kaz-utashiro@github
GitHub: kaz-utashiro PAUSE ID: UTASHIRO URL: https://github.com/kaz-utashiro
GitHub: kaz-utashiro PAUSE ID: UTASHIRO URL: https://github.com/kaz-utashiro
This module is currently included in Text::VisualPrintf distribution as Text::VisualPrintf::Transform, and I'm planning to release it as an individual module.
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;
I made this command to demonstrate Text::ANSI::Printf module, but it is getting to be more interesting tool.
$ 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
$ cpanm App::optex::textconv
$ optex -Mtextconv ansicolumn -DPC3 foo.docx | less
$ source-highlight -f esc -i lib/App/ansicolumn.pm | ansicolumn -PC2 | less
$ cpanm https://github.com/kaz-utashiro/App-ansicolumn.git
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