PrePAN

Sign in to PrePAN

Profile

User's Modules

Text::Transform transform and recover interface for text processing

This module is currently included in Text::VisualPrintf distribution as Text::VisualPrintf::Transform, and I'm planning to release it as an individual module.

Library using Text::VisualPrintf::Transform

Application using Text::VisualPrintf::Transform

Application using Text::ANSI::Printf intensively

DESCRIPTION

This is a general interface to transform text data into desirable form, and recover the result after the process.

For example, Text::Tabs does not take care of Asian wide characters to calculate string width. So the next program does not work as we wish.

use Text::Tabs;
print expand <>;

In this case, make transform object with length function which understand wide-character width, and the pattern of string to be replaced.

use Text::VisualPrintf::Transform;
use Text::VisualWidth::PP;
my $xform = Text::VisualPrintf::Transform->new(
    length => \&Text::VisualWidth::PP::width,
    match => qr/\P{ASCII}+/,
);

Then next program encode data, call expand() function, and recover the result into the original text.

my @lines = <>;
$xform->encode(@lines);
my @expanded = expand @lines;
$xform->decode(@expanded);
print @expanded;

kaz-utashiro@github 7 comments

App::ansicolumn ANSI sequence aware column command

I made this command to demonstrate Text::ANSI::Printf module, but it is getting to be more interesting tool.

IMAGES

https://github.com/kaz-utashiro/App-ansicolumn/tree/master/images

EXAMPLE

column(1) compatible usage

$ ls -1 --color=always /usr/bin | ansicolumn

$ (printf "PERM LINKS OWNER GROUP SIZE MONTH DAY HH:MM/YEAR NAME\n" ; ls --color=always -l | sed 1d) | ansicolumn -t

Show DOCX document in 3up format

$ cpanm App::optex::textconv
$ optex -Mtextconv ansicolumn -DPC3 foo.docx | less

Show highlighted source code in 2up format

$ source-highlight -f esc -i lib/App/ansicolumn.pm | ansicolumn -PC2 | less

INSTALL

$ cpanm https://github.com/kaz-utashiro/App-ansicolumn.git

kaz-utashiro@github 1 comment

Text::ANSI::Printf printf function for string with ANSI sequence

Text::ANSI::Printf is a almost-printf-compatible library with a capability of handling string with ANSI terminal sequences, as well as multi-byte wide characters.

This is just a quick hack using existing modules, Text::VisualPrintf and Text::ANSI::Fold::Util. Not tuned for performance. Most of complicated work is done in Text::ANSI::Fold module.

INSTALL: cpanm https://github.com/kaz-utashiro/Text-ANSI-Printf.git

kaz-utashiro@github 6 comments