App-Greple-frame

 view release on metacpan or  search on metacpan

lib/App/Greple/frame.pm  view on Meta::CPAN

    $size[0] or $default;
}

sub finalize {
    ($mod, $argv) = @_;
}

my %frame_base = (
    top    => '      ┌─' ,
    middle => '    ⋮ ├╶' ,
    bottom => '──────┴─' ,
);

sub opt_frame {
    my $pos = shift;
    my $width = $param{width} //= terminal_width;
    local $_ = $frame_base{$pos} or die;
    if ((my $rest = $width - length) > 0) {
	$_ .= (substr($_, -1, 1) x $rest);
    }
    $_;
}

my %rpn = (
    width  => { init => sub { terminal_width } },
    column => { init => sub { terminal_width } },
    );
sub rpn {
    my($k, $v) = @_;
    require Getopt::EX::RPN
	and Getopt::EX::RPN->import('rpn_calc');
    my $init = $rpn{$k}->{init} // die;
    my @init = ref $init ? $init->() : $init ? $init : ();
    int(rpn_calc(@init, $v)) or die "$v: format error\n";
}

sub set {
    while (my($k, $v) = splice(@_, 0, 2)) {
	exists $param{$k} or next;
	$v = rpn($k, $v) if $rpn{$k} and $v =~ /\D/;
	$param{$k} = $v;
    }
    ();
}

sub get {
    use List::Util qw(pairmap);
    pairmap { $param{$a} } @_;
}

1;

__DATA__

mode function

option --set-frame-width  &set(width=$<shift>)
option --set-frame-column &set(column=$<shift>)

option --ansifold-with-width \
       --pf "ansifold --expand --discard=EL --padding --prefix '      │ ' $<shift> --width=$<shift>"

option --ansifold \
       --ansifold-with-width &get(fold,width)

option --frame-color-filename \
       --colormap FILE=555/CE --format FILE=' %s'

option --frame-simple \
       --line-number --join-blocks \
       --filestyle=once \
       --colormap LINE= --format LINE='%5d │ ' \
       --blockend= \
       --show-frame-middle

option --show-frame-top    --frame_top    &opt_frame(top)
option --show-frame-middle --frame_middle &opt_frame(middle)
option --show-frame-bottom --frame_bottom &opt_frame(bottom)

option --frame-plain --frame-color-filename --frame-simple
option --frame-fold  --frame-plain --ansifold
option --frame       --frame-fold

option --frame-classic-plain --frame-simple --show-frame-top --show-frame-bottom
option --frame-classic-fold  --frame-classic-plain --ansifold
option --frame-classic       --frame-classic-fold

##
## EXPERIMENTAL: --frame-pages, --frame-cols
##

# RPN
define @TEXT_WIDTH  $ENV{GREPLE_FRAME_PAGES_WIDTH}
define @MARGIN      $ENV{GREPLE_FRAME_PAGES_MARGIN}
define @LINE_FIELD  8
define @FRAME_GAP   3
define @COL_WIDTH   @TEXT_WIDTH:@LINE_FIELD:+:@FRAME_GAP:+
define @COLUMN      @COL_WIDTH:/:INT:DUP:1:GE:EXCH:1:IF
define @WIDTH       DUP:@COLUMN:/:@FRAME_GAP:-:@MARGIN:-

define $FOLD \
       ansifold --expand --discard=EL --padding \
       --width =@WIDTH \
       --prefix '      │ ' \
       --boundary=$ENV{GREPLE_FRAME_PAGES_BOUNDARY} \
       --linebreak=all --runin=@MARGIN --runout=@MARGIN

define $COLS \
       ansicolumn --border=box -U @COLUMN

define $PAGES \
       ansicolumn --border=box -P -C @COLUMN

option --frame-set-params \
       &set(width=@WIDTH)

option --frame-col \
       --frame-set-params \
       --pf "$FOLD" \
       --frame-plain

option --frame-pages \
       --frame-set-params \
       --pf "$FOLD | $PAGES" \
       --frame-plain

option --frame-cols \
       --frame-set-params \
       --pf "$FOLD | $COLS" \
       --frame-plain

option --frame-columns --frame-cols

option --frame-pages-classic \
       --frame-set-params \
       --pf "$FOLD | $PAGES" \
       --frame-classic-plain



( run in 0.788 second using v1.01-cache-2.11-cpan-5623c5533a1 )