Package: tcod-ansi-terminal
tcod-ansi-terminalMinimal true colour ANSI terminal support for Python TCOD (tcod).This doesn't try to support everything or be very compatible, just to cover
basic functionality on common terminals with true colour support. Note that
TCOD itselfmay eventually get terminal
support, so check it before
committing to using this.This is currently all in Python code and may not be very performant.There is an example included inexample/. It also serves for
basic testing of features.CompatibilityOperating systems:Linux, MacOS X, probably other Unixes: somewhat tested, worksWindows: totally untested, almost certainly doesn't work yetTerminal emulators (without exploring their options much):xterm: working (all supported features)urxvt: mostly working (poor colour handling)gnome-terminal: working (doesn't honour pixel size or position requests;
reserves some function keys)konsole: mostly working (may read initial size wrong if size was requested;
doesn't honour any size or position requests; doesn't honour title; reserves
some function keys)kitty: working (doesn't honour any size or position requests)alacritty: working (doesn't honour any size of position requests)MacOS X default terminal: not working (no true colour support; some other
features don't work)iterm2: working (does not respect any position or size requests, insert key
seemingly not supported; reserves some function keys)Only uses true colour mode, and won't support consoles that don't handle it.FeaturesSupported TCOD features (at least for some terminals):Basic letter, digit, punctuation, and enter keys (anything received as an
unescaped character; this set is safest for compatibility with untested
terminals).Shift modifier for letter keys (but not digits etc.).Arrow, function, home, end, insert, delete, page up, page down keys.Keysyms for the above keys.Key down and key up events in immediate succession for the above keys, based
on terminal input.Text input events for letter etc. keys.Terminal size checks forrecommended_console_size()andnew_console().Window position, pixel size, and character size as requests. The choice to
honour them or not is up to the terminal and/or window manager.Window resize events for terminal resizes.Mouse motion, button, and wheel events.Window focus gained and lost events.Window title.Quit event on hangup and other exit signals. If in a windowing system, this
might get produced when the window is closed but isn't guaranteed.Other features:The terminal will be reset cleanly on exit.The cursor position can be set.Cursor visibility can be set.Unsupported TCOD features:Shift modifier for non-letter key.Modifiers other than shift.Key scancodes (are allK_UNKNOWN).Correct timing for key down/up events.tcod.event.get().Basically any other input/output feature that isn't mentioned above,
especially things intcod.contextandtcod.event.Features that are not supported but could be later:Some support for other colour modes.Screenshots (with separate interface) to text files.UsageUsetcod_ansi_terminal.context.new()to get a context object which manages an
ANSI terminal and canpresent()Python TCOD consoles to it. Usetcod_ansi_terminal.event.wait()to get events.Targeting terminalsNot all features will be supported in all terminals, so if you want broad
compatibly you should not assume that any particular feature will be available.The context will request the terminal size asked for (if any), but the calling
code must treat this as a request, and not assume that the request will be
honoured or that the size will remain the same during the run. Use the
context'srecommended_console_size()to get the actual size, ornew_console()to get a correctly sized console, and use theWindowResizedevent (or re-checking the size) to catch resizes.The terminal contexttcod_ansi_terminal.context.TerminalContextmay support
operations that are not part of the regular TCOD interface, currently just
cursor controls.Targeting either terminals or regular tcodIf you want to support both regular TCOD and terminals in your program,
parameterize your core code using these interfaces:For rendering, thetcod_ansi_terminal.context.TerminalCompatibleContextprotocol.For input, thetcod_ansi_terminal.event.TerminalCompatibleEventWaitprotocol.The included example covers handling both a terminal or regular TCOD.Presenterstcod_ansi_terminal.contextprovides two presenters which manage how a TCOD
console is written to a terminal on a contextpresent()call.NaivePresenteralways writes the entire console.SparsePresenterwrites only
the character cells which changed since the lastpresent()call. If the
calling code tends to update only small parts of the console between frames,SparsePresenterwill likely be much faster.