App-Greple-frame

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension App-Greple-frame

1.03 2023-12-18T08:05:39Z

    - introduce --frame-cols option

1.02 2023-12-14T02:52:35Z

    - add --frame-pages image in the document

1.01 2023-12-13T06:11:21Z

    - improve --frame-pages definition

1.00 2023-10-08T01:44:27Z

    - document --frame-pages option

0.07 2022-09-29T02:41:48Z

    - add experimental --frame-pages option

0.06 2022-07-15T10:00:26Z

    - update frame format

0.05 2022-07-14T07:28:44Z

    - accept RPN as a width

0.04 2022-07-13T08:54:34Z

    - make default action to fold long lines

0.03 2022-07-07T07:55:46Z

    - update frame format

0.02 2022-03-27T02:23:00Z

    - implement --frame-fold option

0.01 2022-02-28T04:36:05Z

    - original version

MANIFEST  view on Meta::CPAN

Build.PL
Changes
LICENSE
META.json
README.md
cpanfile
lib/App/Greple/frame.pm
minil.toml
t/00_compile.t
META.yml
MANIFEST

META.json  view on Meta::CPAN

{
   "abstract" : "Greple frame output module",
   "author" : [
      "Kazumasa Utashiro"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Minilla/v3.1.23",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
      "version" : "2"
   },
   "name" : "App-Greple-frame",
   "no_index" : {
      "directory" : [
         "t",
         "xt",
         "inc",
         "share",
         "eg",
         "examples",
         "author",
         "builder"

META.json  view on Meta::CPAN

            "perl" : "5.016"
         }
      },
      "test" : {
         "requires" : {
            "Test::More" : "0.98"
         }
      }
   },
   "provides" : {
      "App::Greple::frame" : {
         "file" : "lib/App/Greple/frame.pm",
         "version" : "1.03"
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://github.com/kaz-utashiro/greple-frame/issues"
      },
      "homepage" : "https://github.com/kaz-utashiro/greple-frame",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/kaz-utashiro/greple-frame.git",
         "web" : "https://github.com/kaz-utashiro/greple-frame"
      }
   },
   "version" : "1.03",
   "x_contributors" : [
      "Kazumasa Utashiro <kaz@utashiro.com>"
   ],
   "x_serialization_backend" : "JSON::PP version 4.12",
   "x_static_install" : 1
}

META.yml  view on Meta::CPAN

---
abstract: 'Greple frame output module'
author:
  - 'Kazumasa Utashiro'
build_requires:
  Test::More: '0.98'
configure_requires:
  Module::Build::Tiny: '0.035'
dynamic_config: 0
generated_by: 'Minilla/v3.1.23, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: App-Greple-frame
no_index:
  directory:
    - t
    - xt
    - inc
    - share
    - eg
    - examples
    - author
    - builder
provides:
  App::Greple::frame:
    file: lib/App/Greple/frame.pm
    version: '1.03'
requires:
  App::Greple: '9.0902'
  App::ansicolumn: '1.39'
  App::ansifold: '1.24'
  Getopt::EX::RPN: '0.01'
  List::Util: '1.29'
  Term::ReadKey: '0'
  perl: '5.016'
resources:
  bugtracker: https://github.com/kaz-utashiro/greple-frame/issues
  homepage: https://github.com/kaz-utashiro/greple-frame
  repository: https://github.com/kaz-utashiro/greple-frame.git
version: '1.03'
x_contributors:
  - 'Kazumasa Utashiro <kaz@utashiro.com>'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
x_static_install: 1

README.md  view on Meta::CPAN

[![Actions Status](https://github.com/kaz-utashiro/greple-frame/workflows/test/badge.svg)](https://github.com/kaz-utashiro/greple-frame/actions) [![MetaCPAN Release](https://badge.fury.io/pl/App-Greple-frame.svg)](https://metacpan.org/release/App-Gre...
# NAME

App::Greple::frame - Greple frame output module

# SYNOPSIS

greple -Mframe --frame ...

# DESCRIPTION

Greple -Mframe module provide a capability to put surrounding frames
for each blocks.

`top`, `middle` and `bottom` frames are printed for blocks.

By default **--join-blocks** option is enabled to collect consecutive
lines into a single block.  If you don't like this, override it by
**--no-join-blocks** option.

# OPTIONS

- **--frame**

    <div>
            <p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-3.png">
    </div>

    Set frame and fold long lines with frame-friendly prefix string.
    Folding width is taken from the terminal.  Or you can specify the
    width by calling **set** function with module option.

- **--frame-cols**

    Output results in multi-column format to fit the width of the
    terminal.  The number of columns is automatically calculated from the
    terminal width.

- **--frame-pages**

    Output results in multi-column and paginated format.

    <div>
            <p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-frame-pages.png">
    </div>

- **--set-frame-width**=_#_

    Set frame width.  You have to put this option before **--frame**
    option.  See **set** function in ["FUNCTION"](#function) section.

# FUNCTION

- **set**(**width**=_n_)

    Set terminal width to _n_.  Use like this:

        greple -Mframe::set(width=80) ...

        greple -Mframe::set=width=80 ...

    If non-digit character is found in the value part, it is considered as
    a Reverse Polish Notation, starting terminal width pushed on the
    stack.  RPN `2/3-` means `terminal-width / 2 - 3`.

    You can use like this:

        greple -Mframe::set=width=2/3- --frame --uc '(\w+::)+\w+' --git | ansicolumn -PC2

    <div>
            <p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-column.png">
    </div>

# SEE ALSO

[App::ansifold](https://metacpan.org/pod/App%3A%3Aansifold)

[App::ansicolumn](https://metacpan.org/pod/App%3A%3Aansicolumn)

[Math::RPN](https://metacpan.org/pod/Math%3A%3ARPN)

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

package App::Greple::frame;

our $VERSION = "1.03";

=encoding utf-8

=head1 NAME

App::Greple::frame - Greple frame output module

=head1 SYNOPSIS

greple -Mframe --frame ...

=head1 DESCRIPTION

Greple -Mframe module provide a capability to put surrounding frames
for each blocks.

C<top>, C<middle> and C<bottom> frames are printed for blocks.

By default B<--join-blocks> option is enabled to collect consecutive
lines into a single block.  If you don't like this, override it by
B<--no-join-blocks> option.

=head1 OPTIONS

=over 7

=item B<--frame>

=for comment
=item B<--frame-fold>

=begin html

<p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-3.png">

=end html

Set frame and fold long lines with frame-friendly prefix string.
Folding width is taken from the terminal.  Or you can specify the
width by calling B<set> function with module option.

=begin comment

=item B<--frame-simple>

Set frame without folding.

=end comment

=item B<--frame-cols>

Output results in multi-column format to fit the width of the
terminal.  The number of columns is automatically calculated from the
terminal width.

=item B<--frame-pages>

Output results in multi-column and paginated format.

=begin html

<p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-frame-pages.png">

=end html

=item B<--set-frame-width>=I<#>

Set frame width.  You have to put this option before B<--frame>
option.  See B<set> function in L</FUNCTION> section.

=back

=begin comment

Put next line in your F<~/.greplerc> to autoload B<App::Greple::frame> module.

    autoload -Mframe --frame

Then you can use B<--frame> option whenever you want.

=end comment

=head1 FUNCTION

=over 7

=item B<set>(B<width>=I<n>)

Set terminal width to I<n>.  Use like this:

    greple -Mframe::set(width=80) ...

    greple -Mframe::set=width=80 ...

If non-digit character is found in the value part, it is considered as
a Reverse Polish Notation, starting terminal width pushed on the
stack.  RPN C<2/3-> means C<terminal-width / 2 - 3>.

You can use like this:

    greple -Mframe::set=width=2/3- --frame --uc '(\w+::)+\w+' --git | ansicolumn -PC2

=begin html

<p><img width="75%" src="https://raw.githubusercontent.com/kaz-utashiro/greple-frame/main/images/terminal-column.png">

=end html

=back

=head1 SEE ALSO

L<App::ansifold>

L<App::ansicolumn>

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

	# This code should work on both versions.
	@size = GetTerminalSize $tty, $tty;
    }
    $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 } },
    );

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

    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:-

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

       --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

minil.toml  view on Meta::CPAN

name = "App-Greple-frame"
badges = [ 'github-actions/test', 'metacpan' ]
Authority = "cpan:UTASHIRO"

module_maker = "ModuleBuildTiny"
static_install = "auto"

[release]
branch = "main"

t/00_compile.t  view on Meta::CPAN

use strict;
use Test::More 0.98;

use_ok $_ for qw(
    App::Greple::frame
);

done_testing;



( run in 1.383 second using v1.01-cache-2.11-cpan-e1769b4cff6 )