Skip to main content

tcod-ansi-terminal

Minimal 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 itself may 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 in example/. It also serves for basic testing of features.

Compatibility

Operating systems:

  • Linux, MacOS X, probably other Unixes: somewhat tested, works
  • Windows: totally untested, almost certainly doesn't work yet

Terminal 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.

Features

Supported 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 for recommended_console_size() and new_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 all K_UNKNOWN).
  • Correct timing for key down/up events.
  • tcod.event.get().
  • Basically any other input/output feature that isn't mentioned above, especially things in tcod.context and tcod.event.

Features that are not supported but could be later:

  • Some support for other colour modes.
  • Screenshots (with separate interface) to text files.

Usage

Use tcod_ansi_terminal.context.new() to get a context object which manages an ANSI terminal and can present() Python TCOD consoles to it. Use tcod_ansi_terminal.event.wait() to get events.

Targeting terminals

Not 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's recommended_console_size() to get the actual size, or new_console() to get a correctly sized console, and use the WindowResized event (or re-checking the size) to catch resizes.

The terminal context tcod_ansi_terminal.context.TerminalContext may support operations that are not part of the regular TCOD interface, currently just cursor controls.

Targeting either terminals or regular tcod

If you want to support both regular TCOD and terminals in your program, parameterize your core code using these interfaces:

  • For rendering, the tcod_ansi_terminal.context.TerminalCompatibleContext protocol.
  • For input, the tcod_ansi_terminal.event.TerminalCompatibleEventWait protocol.

The included example covers handling both a terminal or regular TCOD.

Presenters

tcod_ansi_terminal.context provides two presenters which manage how a TCOD console is written to a terminal on a context present() call. NaivePresenter always writes the entire console. SparsePresenter writes only the character cells which changed since the last present() call. If the calling code tends to update only small parts of the console between frames, SparsePresenter will likely be much faster.

Metadata

Release files for tcod-ansi-terminal 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tcod-ansi-terminal 0.1.0
File Size Uploaded
tcod-ansi-terminal-0.1.0.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tcod-ansi-terminal 0.1.0
File Interpreter ABI Platform
tcod_ansi_terminal-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.5 kB

Release files / tcod-ansi-terminal-0.1.0.tar.gz

Download URL tcod-ansi-terminal-0.1.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
68cb5a9b6c66ec59424a8315621977080fe250e7e980f56cbf9f327ebc28b366
BLAKE2b-256 checksum
How to use checksums
7bf26e375fb0c700504cf2adc6c55ca6e04f210cbd6ef9a553e29d44d600d005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / tcod_ansi_terminal-0.1.0-py3-none-any.whl

Download URL tcod_ansi_terminal-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ccb1ff2ce11e29531db53f9a52f634debbae1dfc1a2a0971911d1c0904dcdc6
BLAKE2b-256 checksum
How to use checksums
b1d43196fc7f6ef0443a9b9482ba15c1cd58ca1711dcd46762e3d054c4e1cccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page