Package: term
OverviewThetermpackage is an enhanced version of the standard library’sttymodule. It provides context managers for opening a terminal stream, and
for temporarily switching the terminal to raw or cbreak mode.Package ContentsTerminal Controlsetraw(fd, when=TCSAFLUSH, min=1, time=0)Put the terminal in raw mode.setcbreak(fd, when=TCSAFLUSH, min=1, time=0)Put the terminal in cbreak mode.rawmode(fd, when=TCSAFLUSH, min=1, time=0)Context manager to put the terminal in raw mode.cbreakmode(fd, when=TCSAFLUSH, min=1, time=0)Context manager to put the terminal in cbreak mode.Terminal I/Oopentty(bufsize=-1, mode=’r+b’)Context manager returning a new rw stream connected to /dev/tty.
The stream is None if the device cannot be opened.readto(stream, endswith):Read bytes or characters from stream until buffer.endswith(endswith)
is true.High-level Functionsgetyx()Return the cursor position as 1-based (line, col) tuple.
Line and col are 0 if the device cannot be opened or the terminal
does not support DSR 6.getfgcolor()Return the terminal foregound color as (r, g, b) tuple.
All values are -1 if the device cannot be opened or does not supports
OSC 10.getbgcolor()Return the terminal background color as (r, g, b) tuple.
All values are -1 if the device cannot be opened or does not supports
OSC 11.islightmode()Return true if the background color is lighter than the foreground color.
May return None if the terminal does not support OSC color queries.isdarkmode()Return true if the background color is darker than the foreground color.
May return None if the terminal does not support OSC color queries.DocumentationPlease see theAPI Documentationfor more.Changelog2.5 - 2023-09-14Update tox.ini for latest tox.
[stefan]Add .readthedocs.yaml file.
[stefan]Pin sphinx and sphinx-rtd-theme versions in docs extra.
[stefan]Add pylint extra which installs pylint.
[stefan]Update .pylintrc for latest pylint.
[stefan]2.4 - 2022-03-07Add Python 3.8-3.10 to tox.ini. Remove old Python versions.
[stefan]Replace deprecatedpython setup.py testin tox.ini.
[stefan]Remove deprecatedtest_suitefrom setup.py.
[stefan]Move metadata to setup.cfg and add a pyproject.toml file.
[stefan]Include tests in sdist but not in wheel.
[stefan]Fix escape sequence warning in byte string literal.
[stefan]Open /dev/tty in binary mode under both Python 2 and 3.
[stefan]Officially change opentty’s bufsize argument default from 1 to -1.
Under Python 3, 1 has effectively meant -1 all along but Python 3.8
now issues a warning.
[stefan]Add readto, getfgcolor, getbgcolor, islightmode, and isdarkmode.
[stefan]2.3 - 2019-02-08Add MANIFEST.in.
[stefan]Release as wheel.
[stefan]Drop explicit GPL because the PSF license is GPL-compatible anyway.
[stefan]2.2 - 2017-02-05Support Python 2.6-3.6 without 2to3.
[stefan]2.1 - 2014-04-19Remove setuptools from install_requires because it isn’t.
[stefan]2.0 - 2012-04-27Open /dev/tty in binary mode under Python 3.
[stefan]Disable buffering if the device is not seekable.
[stefan]Remove getmaxyx since it cannot be implemented reliably.
[stefan]Support Python 2.5.
[stefan]Change license to GPL or PSF to avoid relicensing of PSF code.
[stefan]1.0 - 2012-04-11Initial release.
[stefan]