linkcheck.ansicolor

ANSI Color definitions and functions. For Windows systems, the colorama module uses ctypes and Windows DLLs to generate colored output.

From Term::ANSIColor, applies also to this module:

The codes output by this module are standard terminal control codes, complying with ECMA-48 and ISO 6429 (generally referred to as “ANSI color” for the color codes). The non-color control codes (bold, dark, italic, underline, and reverse) are part of the earlier ANSI X3.64 standard for control sequences for video terminals and peripherals.

Note that not all displays are ISO 6429-compliant, or even X3.64-compliant (or are even attempting to be so).

Jean Delvare provided the following table of different common terminal emulators and their support for the various attributes and others have helped me flesh it out:

             clear    bold     dark    under    blink   reverse  conceal
------------------------------------------------------------------------
xterm         yes      yes      no      yes     bold      yes      yes
linux         yes      yes      yes    bold      yes      yes      no
rxvt          yes      yes      no      yes  bold/black   yes      no
dtterm        yes      yes      yes     yes    reverse    yes      yes
teraterm      yes    reverse    no      yes    rev/red    yes      no
aixterm      kinda   normal     no      yes      no       yes      yes
PuTTY         yes     color     no      yes      no       yes      no
Windows       yes      no       no      no       no       yes      no
Cygwin SSH    yes      yes      no     color    color    color     yes

SEE ALSO

ECMA-048 is available on-line (at least at the time of this writing) at http://www.ecma-international.org/publications/standards/ECMA-048.HTM.

ISO 6429 is available from ISO for a charge; the author of this module does not own a copy of it. Since the source material for ISO 6429 was ECMA-048 and the latter is available for free, there seems little reason to obtain the ISO standard.

Functions

esc_ansicolor(color)

convert a named color definition to an escaped ANSI color

get_columns(fp)

Return number of columns for given file.

get_win_color(color)

Convert a named color definition to Windows console color foreground, background and style numbers.

has_colors(fp)

Test if given file is an ANSI color enabled tty.

write_color(fp, text, color)

Colorize text with given color.

Classes

ColoredStreamHandler([strm])

Send colored log messages to streams (file-like objects).

Colorizer(fp)

Prints colored messages to streams.

class linkcheck.ansicolor.ColoredStreamHandler(strm=None)[source]

Bases: logging.StreamHandler

Send colored log messages to streams (file-like objects).

Log to given stream (a file-like object) or to stderr if strm is None.

emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline [N.B. this may be removed depending on feedback].

get_color(record)[source]

Get appropriate color according to log level.

class linkcheck.ansicolor.Colorizer(fp)[source]

Bases: object

Prints colored messages to streams.

Initialize with given stream (file-like object).

linkcheck.ansicolor.esc_ansicolor(color)[source]

convert a named color definition to an escaped ANSI color

linkcheck.ansicolor.get_columns(fp)[source]

Return number of columns for given file.

linkcheck.ansicolor.get_win_color(color)[source]

Convert a named color definition to Windows console color foreground, background and style numbers.

linkcheck.ansicolor.has_colors(fp)[source]

Test if given file is an ANSI color enabled tty.

linkcheck.ansicolor.write_color(fp, text, color)

Colorize text with given color.