NAME
Text::ANSI::Highlight::IO - read source files in colors, in a program as it is
SYNOPSIS
From one-liners:
perl -MText::ANSI::Highlight::IO -ne 'print' file.c file.pl
perl -MText::ANSI::Highlight::IO=gnu -pe 's/^/> /' README.md
From a script:
use Text::ANSI::Highlight::IO with => 'pandoc';
while (<>) {
...
}
In a program which opens its files by IO::Factotum:
use Text::ANSI::Highlight::IO ();
Text::ANSI::Highlight::IO->setup('pandoc');
my $fh = IO::Factotum::open_input($file);
DESCRIPTION
With this module, a program which reads files by <> reads them in colors, the syntax highlight of Text::ANSI::Highlight, and nothing of the program has to be changed. A file whose language is not known is read as it is, and so is the standard input. $ARGV, $. and eof work as usual.
It does not color by itself, and does not read files by itself. It gives a highlighter of Text::ANSI::Highlight to IO::Factotum, which reads files through what it is given, and makes <> read by IO::Factotum. Neither of the two knows the other.
The arguments are those of Text::ANSI::Highlight->new: with => name is the highlighter, and with can be left out for the first argument. Without it, the highlighter is the default, pandoc.
use Text::ANSI::Highlight::IO; # pandoc
use Text::ANSI::Highlight::IO 'gnu'; # sourcehighlight
use Text::ANSI::Highlight::IO with => 'sky'; # skylighting
A file which is opened by open is not read through it: only the files of <>, and those which are opened by IO::Factotum::open_input.
METHODS
- import(arguments)
-
Called by
use. Give the highlighter to IO::Factotum, and make<>read by it (IO::Factotum::tie_argv).A program which takes the highlighter from its options can load the module without it, and call this later:
use Text::ANSI::Highlight::IO (); ... Text::ANSI::Highlight::IO->import($name) if defined $name; - setup(arguments)
-
Give the highlighter to IO::Factotum, and leave
<>as it is. For a program which opens its files byIO::Factotum::open_input.
SEE ALSO
Text::ANSI::Highlight, IO::Factotum
ARGV::URL makes <> read URLs in the same way, by being loaded.
AUTHOR
Kazumasa Utashiro
LICENSE
Copyright © 2026 Kazumasa Utashiro.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.