Skip to main content

Command-line tool for colorizing output of log files and console programs

Project description

TxtStyle

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.

TxtStyle

Requirements

  • Latest version 1.1.2 requires Python 3.7+

Install

Using package installer

pip install TxtStyle

From sources

git clone https://github.com/armandino/TxtStyle.git
cd TxtStyle
sudo python setup.py install

Try it out

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

Define your own styles

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

Other usage examples

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

✨ Special thanks to contributors

  • (Josef Moudrik)[https://github.com/jmoudrik]
  • (Arjix)[https://github.com/ArjixWasTaken]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TxtStyle-1.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

TxtStyle-1.1.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file TxtStyle-1.1.2.tar.gz.

File metadata

  • Download URL: TxtStyle-1.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for TxtStyle-1.1.2.tar.gz
Algorithm Hash digest
SHA256 188d681eefe02577b058c9a6ed786c9425bd5655730d974d11d15480fdd7f013
MD5 9bdf4579ff7888da4c5c9c50178006e8
BLAKE2b-256 b3eb09fc9bada868323ece29b0bd547cae530bf50c64d5f36588e8811f2d9f03

See more details on using hashes here.

File details

Details for the file TxtStyle-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: TxtStyle-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for TxtStyle-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a99b78b0ce49d98267d2b1fd428385643b114acac85fc2685ca58fcf43de4b39
MD5 783c31f2a2f169d4b33d713f4c3559bc
BLAKE2b-256 996fa32c25d6a22b355d4218bce7be4d3bd00e5318ca1953e3a2071eeb92cdf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page