mrcrowbar.ansi module

mrcrowbar.ansi.ANSI_CURSOR_MOVE_BACKWARD = '\x1b[{}D'

ANSI escape sequence to move the cursor backward.

mrcrowbar.ansi.ANSI_CURSOR_MOVE_DOWN = '\x1b[{}B'

ANSI escape sequence to move the cursor down.

mrcrowbar.ansi.ANSI_CURSOR_MOVE_FORWARD = '\x1b[{}C'

ANSI escape sequence to move the cursor forward.

mrcrowbar.ansi.ANSI_CURSOR_MOVE_UP = '\x1b[{}A'

ANSI escape sequence to move the cursor up.

mrcrowbar.ansi.ANSI_CURSOR_SET_POSITION = '\x1b[{};{}H'

ANSI escape sequence to set the cursor position. (1, 1) is the top left.

mrcrowbar.ansi.ANSI_ERASE_BASE = '\x1b[{}J'

Container for ANSI escape sequence screen erasing

mrcrowbar.ansi.ANSI_ERASE_SCREEN = '\x1b[2J'

ANSI escape sequence for clearing the visible terminal

mrcrowbar.ansi.ANSI_ERASE_SCROLLBACK = '\x1b[3J'

ANSI escape sequence for clearing the scrollback of the terminal

mrcrowbar.ansi.ANSI_FORMAT_BACKGROUND_CMD = '48;2;{};{};{}'

ANSI escape sequence for setting the background colour (24-bit).

mrcrowbar.ansi.ANSI_FORMAT_BACKGROUND_XTERM_CMD = '48;5;{}'

ANSI escape sequence for setting the background colour (xterm).

mrcrowbar.ansi.ANSI_FORMAT_BASE = '\x1b[{}m'

Container for ANSI escape sequences for text formatting

ANSI escape sequence for bold text

mrcrowbar.ansi.ANSI_FORMAT_BOLD_CMD = '1'

ANSI escape sequence for bold text

mrcrowbar.ansi.ANSI_FORMAT_FAINT_CMD = '2'

ANSI escape sequence for faint text

mrcrowbar.ansi.ANSI_FORMAT_FOREGROUND_CMD = '38;2;{};{};{}'

ANSI escape sequence for setting the foreground colour (24-bit).

mrcrowbar.ansi.ANSI_FORMAT_FOREGROUND_XTERM_CMD = '38;5;{}'

ANSI escape sequence for setting the foreground colour (xterm).

mrcrowbar.ansi.ANSI_FORMAT_INVERTED_CMD = '7'

ANSI escape sequence for inverted text

mrcrowbar.ansi.ANSI_FORMAT_ITALIC_CMD = '3'

ANSI escape sequence for bold text

mrcrowbar.ansi.ANSI_FORMAT_RESET_CMD = '0'

ANSI escape sequence for resetting the colour settings to the default.

mrcrowbar.ansi.ANSI_FORMAT_UNDERLINE_CMD = '4'

ANSI escape sequence for bold text

mrcrowbar.ansi.BAR_HORIZ = ' ▏▎▍▌▋▊▉█'

Unicode representation of a horizontal bar graph.

mrcrowbar.ansi.BAR_VERT = ' ▁▂▃▄▅▆▇█'

Unicode representation of a vertical bar graph.

class mrcrowbar.ansi.HexdumpHighlightBuffer(source, start=None, end=None, length=None, major_len=8, minor_len=4, colour=True, address_base=None, before=2, after=2, title=None)[source]

Bases: object

add_span(span)[source]
flush(final=False)[source]
update(marker)[source]
mrcrowbar.ansi.format_bar_graph_iter(data, width=64, height=12, y_min=None, y_max=None)[source]
mrcrowbar.ansi.format_escape(foreground=None, background=None, bold=False, faint=False, italic=False, underline=False, blink=False, inverted=False)[source]

Returns the ANSI escape sequence to set character formatting.

foreground
Foreground colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
background
Background colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
bold
Enable bold text (default: False)
faint
Enable faint text (default: False)
italic
Enable italic text (default: False)
underline
Enable underlined text (default: False)
blink
Enable blinky text (default: False)
inverted
Enable inverted text (default: False)
mrcrowbar.ansi.format_hexdump_line(source, offset, end=None, major_len=8, minor_len=4, colour=True, prefix='', highlight_addr=None, highlight_map=None, address_base_offset=0, show_offsets=True, show_glyphs=True)[source]
mrcrowbar.ansi.format_histdump_line(source, offset, length=None, end=None, width=64, address_base_offset=0, palette=None)[source]
mrcrowbar.ansi.format_histogram_line(buckets, palette=None)[source]
mrcrowbar.ansi.format_image_iter(data_fetch, x_start=0, y_start=0, width=32, height=32, frame=0, columns=1, downsample=1)[source]

Return the ANSI escape sequence to render a bitmap image.

data_fetch
Function that takes three arguments (x position, y position, and frame) and returns a Colour corresponding to the pixel stored there, or Transparent if the requested pixel is out of bounds.
x_start
Offset from the left of the image data to render from. Defaults to 0.
y_start
Offset from the top of the image data to render from. Defaults to 0.
width
Width of the image data to render. Defaults to 32.
height
Height of the image data to render. Defaults to 32.
frame
Single frame number/object, or a list to render in sequence. Defaults to frame 0.
columns
Number of frames to render per line (useful for printing tilemaps!). Defaults to 1.
downsample
Shrink larger images by printing every nth pixel only. Defaults to 1.
mrcrowbar.ansi.format_pixels(top, bottom, reset=True, repeat=1)[source]

Return the ANSI escape sequence to render two vertically-stacked pixels as a single monospace character.

top
Top colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
bottom
Bottom colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
reset
Reset the formatting at the end (default: True)
repeat
Number of horizontal pixels to render (default: 1)
mrcrowbar.ansi.format_string(string, foreground=None, background=None, reset=True, bold=False, faint=False, italic=False, underline=False, blink=False, inverted=False)[source]

Returns a Unicode string formatted with an ANSI escape sequence.

string
String to format
foreground
Foreground colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
background
Background colour to use. Accepted types: None, int (xterm palette ID), tuple (RGB, RGBA), Colour
reset
Reset the formatting at the end (default: True)
bold
Enable bold text (default: False)
faint
Enable faint text (default: False)
italic
Enable italic text (default: False)
underline
Enable underlined text (default: False)
blink
Enable blinky text (default: False)
inverted
Enable inverted text (default: False)