ansiterminal
Handles common operations when interacting with an ANSI-compliant terminal.
Classes
- class pymisclib.ansiterminal.BgColor(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Background colors and the ANSI format strings used to create them.
- Black = '\x1b[40m'
- Blue = '\x1b[44m'
- BrightBlack = '\x1b[100m'
- BrightBlue = '\x1b[104m'
- BrightCyan = '\x1b[106m'
- BrightGreen = '\x1b[102m'
- BrightMagenta = '\x1b[105m'
- BrightRed = '\x1b[101m'
- BrightWhite = '\x1b[107m'
- BrightYellow = '\x1b[103m'
- Cyan = '\x1b[46m'
- Green = '\x1b[42m'
- Magenta = '\x1b[45m'
- Red = '\x1b[41m'
- White = '\x1b[47m'
- Yellow = '\x1b[43m'
- class pymisclib.ansiterminal.FgColor(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Foreground colors and the ANSI format strings used to create them.
- Black = '\x1b[30m'
- Blue = '\x1b[34m'
- BrightBlack = '\x1b[90m'
- BrightBlue = '\x1b[94m'
- BrightCyan = '\x1b[96m'
- BrightGreen = '\x1b[92m'
- BrightMagenta = '\x1b[95m'
- BrightRed = '\x1b[91m'
- BrightWhite = '\x1b[97m'
- BrightYellow = '\x1b[93m'
- Cyan = '\x1b[36m'
- Green = '\x1b[32m'
- Magenta = '\x1b[35m'
- Red = '\x1b[31m'
- White = '\x1b[37m'
- Yellow = '\x1b[33m'
- class pymisclib.ansiterminal.ColsRows(column: int, row: int)
A column and row position or size.
- column: int
- row: int
- class pymisclib.ansiterminal.AnsiTerminal(full: bool = False, autoflush: bool = False, _cursor_column: int = -1, _cursor_row: int = -1, _have_posix: bool = True, _logger: logging.Logger = <Logger pymisclib.ansiterminal (WARNING)>, _terminal_columns: int = -1, _terminal_rows: int = -1)
- __init__(full: bool = False, autoflush: bool = False, _cursor_column: int = -1, _cursor_row: int = -1, _have_posix: bool = True, _logger: ~logging.Logger = <Logger pymisclib.ansiterminal (WARNING)>, _terminal_columns: int = -1, _terminal_rows: int = -1) None
- erase_line()
Erase the current line.
- erase_screen()
Erase the entire screen content.
Depending on the terminal, this may scroll up the entire screen, so the screen content will be saved to the scrollback buffer.
- erase_scrollback_buffer()
Erase the scrollback buffer without erasing the screen content.
- erase_to_end_of_line()
Erase from the cursor position to the end of the current line.
- erase_to_start_of_line()
Erase from the cursor position to the start of the current line.
- move_cursor_back(nr_columns: int = 1)
Move the cursor back by nr_columns columns.
If the cursor is at the edge of the screen, this has no effect.
- Parameters:
nr_columns¶ (int) – Number of columns to move the cursor by.
- move_cursor_down(nr_rows: int = 1)
Move the cursor down by nr_rows rows.
If the cursor is at the edge of the screen, this has no effect.
- Parameters:
nr_rows¶ (int) – Number of rows to move the cursor by.
- move_cursor_forward(nr_columns: int = 1)
Move the cursor forward by nr_columns columns.
If the cursor is at the edge of the screen, this has no effect.
- Parameters:
nr_columns¶ (int) – Number of columns to move the cursor by.
- move_cursor_to(column: int = 1, row: int = 1)
Move the cursor to the given position.
- move_cursor_up(nr_rows: int = 1)
Move the cursor up by nr_rows rows.
If the cursor is at the edge of the screen, this has no effect.
- Parameters:
nr_rows¶ (int) – Number of rows to move the cursor by.
- scroll_page_down(nr_pages: int = 1)
Scroll down by nr_pages pages/screens.
- Parameters:
nr_pages¶ (int) – Number of pages to scroll down by.
- Raises:
ValueError – nr_pages is < 1
- scroll_page_up(nr_pages: int = 1)
Scroll up by nr_pages pages/screens.
- Parameters:
nr_pages¶ (int) – Number of pages to scroll up by.
- Raises:
ValueError – nr_pages is < 1
- autoflush: bool = False
- full: bool = False
Terminal Support
Feature |
Alacritty |
Gnome Terminal |
Kitty |
Windows Terminal |
Windows Cmd |
|---|---|---|---|---|---|
Color |
24 bit |
24 bit |
24 bit |
24 bit |
24 bit |
Bold |
Yes |
Yes |
Yes |
Yes |
Yes |
Faint |
No |
No |
Yes |
No |
No |
Italic |
Yes |
Yes |
Yes |
Yes |
No |
Underline |
Yes |
Yes |
Yes |
Yes |
Yes |
SlowBlink |
No |
Yes |
No |
No |
No |
RapidBlink |
No |
SlowBlink |
No |
No |
No |
Reverse |
Yes |
Yes |
Yes |
Yes |
Yes |
Hide |
Yes |
Yes |
No |
Yes |
No |
StrikeOut |
Yes |
Yes |
Yes |
Yes |
No |
DoubleUnderline |
Yes |
Yes |
Single |
Yes |
No |
Encircle |
No |
Underline |
No |
Underline |
No |
Erase scrollback |
Yes |
Yes |
Yes |
Yes |
|
Read cursor pos |
Yes |
Yes |
Yes |
Yes |
Yes |
Versions Tested:
Alacritty 0.11.0-4 on Debian 12
Alacritty 0.12.2 on Windows 10
Gnome Terminal 3.46.8 on Debian 12
kitty 0.21.2 on Ubuntu 22.04
Windows Terminal 1.18.2822.0
Last tested in November 2023 with Debian 12 and Windows 10.
How to Test
To test support for your terminal, install pymisclib. Then run pymisclib.ansiterminal.main().
python3 -m pip install pymisclib
python -c "from pymisclib.ansiterminal import main;main()"
Footnotes