API Reference

adafruit_color_terminal

Extension of supports ANSI color escapes for subsets of text and optionally the ASCII bell escape code.

  • Author(s): Tim Cocks

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_color_terminal.ColorTerminal(font, width, height, custom_palette=None, audio_interface=None, bell_audio_file='/beep.wav')

Extension of terminalio.Terminal that supports ANSI color escapes for subsets of text

Parameters:
  • font – The font to use for the terminal.

  • width – The width of the terminal in characters.

  • height – The height of the terminal in characters.

  • custom_palette – A custom palette of colors to use instead of the default ones. Must contain at least 9 colors.

  • audio_interface – The audio interface to use for playing ASCII bell escape codes.

  • bell_audio_file – The wave audio file to use for the ASCII bell escape codes. Defaults to beep.wav

apply_color(string)

Set the current color into the TilePaletteMapper from the current cursor position to the end of the given string.

Parameters:

string – The string that will have its color set

property cursor_x

The x position of the cursor :return:

property cursor_y

The y position of the cursor :return:

get_color_mapping(color_code)

given an ANSI escape code like ‘32;45m’ return the mapping used by TilePaletteMapper to represent the specified color code.

Parameters:

color_code (string) – ANSI color escape code

static parse_ansi_colors(text)

Parse ANSI color escape codes from a string.

Returns:

(clean_string, color_map) - clean_string: string with all ANSI escape codes removed - color_map: dict mapping string indices to color codes (e.g., “32m”, “0m”)

Return type:

tuple

update_visual_cursor()

Move the visible cursor to the current cursor location. Visible cursor is denoted by inverted color mapping. :return:

write(s)

Write a string to the terminal. If it contains ANSI color escape codes then the TilePaletteMapper will be adjusted to map to the given colors for the specified subsets of text.

Parameters:

s – The string to write.