TxtStyle
is a command line tool for colorizing output of console programs.
Its main goal is to assist humans in reading log files by highlighting text
in various colors using custom rules. Or it can simply be used
to make output of console programs prettier.
- Latest version
1.1.2
requires Python 3.7+
pip install TxtStyle
git clone https://github.com/armandino/TxtStyle.git
cd TxtStyle
sudo python setup.py install
Color calendar
cal 2012 | txts -n calendar
Color ifconfig output
ifconfig | txts -n ifconfig
Apply 'example' style to example.log
wget https://raw.githubusercontent.com/armandino/TxtStyle/master/example.log
txts -n example example.log
TxtStyle
reads styles from a config file under user's home directory:
~/.txts.conf
A default config is generated by the installer. It contains some styles provided as an example. To define your own, add styles to the config and reference them by name.
For example, to add "mystyle":
[Style="mystyle"]
blue: index(0-6)
red: regex("foo")
green bold: regex("bar")
grey on-yellow: regex("baz")
TxtStyle
works by styling lines of text using regular expressions
and/or string indexes. index(0-6)
highlights a substring of a line
and regex("pattern")
highlights text matching the pattern.
Save the conf file with "mystyle" and run txts
with
the -n
(or --name
) option:
echo "Styling foo, bar, and baz." | txts -n mystyle
TxtStyle
configuration supports a small set of named color keys
(such as red
, blue
, yellow
) and an extended set of numeric keys
(from 1
to 255
). To print available keys use the -p
option:
txts -p
Highlight text using the -r
(or --regex
) option. For example
echo "A Foo and a Bar" | txts -r "Foo|Bar"
will color both Foo and Bar in red. If you use the -r
option
multiple times, each of the specified regexps will have a different
color, as in:
echo "A Foo and a Bar" | txts -r Foo -r Bar
TxtStyle
does not apply styles if output is piped to another command.
To force color if the output is piped, use --color-always
option:
ps aux | txts -n ps --color-always | less -R
Print help
txts -h