Skip to main content

Convenience functions for ANSI terminal colour sequences

Project description

Mapping and function for adding ANSI terminal colour escape sequences to strings for colour highlighting of output.

Function colourise(s, colour=None, uncolour='normal')

Return a string enclosed in colour-on and colour-off ANSI sequences.
colour names the desired ANSI colour.
uncolour may be used to specify the colour-off colour;
the default is 'normal'.

Function colourise_patterns(s, patterns, default_colour=None)

Colourise a string according to regular expressions.
s: the string
patterns: a sequence of patterns
default_colour: if a string pattern has no colon, or starts
with a colon, use this colour; default DEFAULT_HIGHLIGHT
Each pattern may be:
a string of the form "[colour]:regexp"
a string containing no colon, taken to be a regexp
a tuple of the form (colour, regexp)
a regexp object
Returns the string with ANSI colour escapes embedded.

Function make_pattern(pattern, default_colour=None)

Convert a pattern specification into a (colour, regexp) tuple.
Each pattern may be:
a string of the form "[colour]:regexp"
a string containing no colon, taken to be a regexp
a tuple of the form (colour, regexp)
a regexp object

Function make_patterns(patterns, default_colour=None)

Convert an iterable of pattern specifications into a list of (colour, regexp) tuples.
Each pattern may be:
a string of the form "[colour]:regexp"
a string containing no colon, taken to be a regexp
a tuple of the form (colour, regexp)
a regexp object

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

cs.ansi_colour-20180725.1.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file cs.ansi_colour-20180725.1.tar.gz.

File metadata

File hashes

Hashes for cs.ansi_colour-20180725.1.tar.gz
Algorithm Hash digest
SHA256 32696db3a4f0aea14249f54ae83a155a54fc28b713caafd104493923f95f3f91
MD5 ad359766e474c815c57527c8fe930b1b
BLAKE2b-256 d752458f5cb0e59460cce3f4871e96b18abd59570b701a5ac72417388bd456f2

See more details on using hashes here.

Supported by

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