Functions related to terminals.
Short summary:
-
modify_termios: Apply mode changes to a tty. Return the previous tty modes as fromtermios.tcgetattrorNoneif the changes could not be applied. Ifstrict, raise an exception instead of returningNone. -
rmoveto: Move the cursordxpositions horizontally anddypositions vertically.dyis negative for up and positive for down. -
rmoveto_bs: Return the control bytes needed to move the cursordxpositions horizontally anddypositions vertically.dyis negative for up and positive for down. -
setupterm: Run curses.setupterm, needed to be able to use the status line. Uses a global flag to avoid doing this twice. -
stack_termios: Context manager to apply and restore changes to a tty. Yield the previous tty modes as fromtermios.tcgetattrorNoneif the changes could not be applied. Ifstrict, raise an exception instead of yieldingNone. -
status: Write a message to the terminal's status line. -
statusline: Update the status line. -
statusline_bs: Return a byte string to update the status line. -
ttysize: Return a (rows, columns) tuple for the specified file descriptor. -
ttysizepx: Return a(rows,columns,widthpx,heightpx)tuple for the specified file descriptor being the terminal character rows and columns and pixel width and height respectively. -
WinSize: WinSize(rows, columns). -
WinSizePX: Size information about a terminal including its pixel size.
Functions
modify_termios(fd=0, set_modes=None, clear_modes=None, strict=False)
Apply mode changes to a tty.
Return the previous tty modes as from termios.tcgetattr
or None if the changes could not be applied.
If strict, raise an exception instead of returning None.
Parameters:
fd: optional tty file descriptor, default0.set_modes: an optional mapping of attribute name to new value for values to setclear_modes: an optional mapping of attribute name to new value for values to clearstrict: optional flag, defaultFalse; if true, raise exceptions from failedtcgetattrandtcsetattrcalls otherwise issue a warning if the errno is notENOTTYand proceed. This aims to provide ease of use in batch mode by default while providing a mode to fail overtly if required.
The attribute names are from
iflag, oflag, cflag, lflag, ispeed, ospeed, cc,
corresponding to the list entries defined by the termios.tcgetattr
call.
For set_modes, the attributes ispeed, ospeed and cc
are applied directly;
the other attributes are binary ORed into the existing modes.
For clear_modes, the attributes ispeed, ospeed and cc
cannot be cleared;
the other attributes are binary removed from the existing modes.
For example, to turn off the terminal echo during some operation:
old_modes = apply_termios(clear_modes={'lflag': termios.ECHO}):
... do something with tty echo disabled ...
if old_modes:
termios.tcsetattr(fd, termios.TCSANOW, old_modes)
rmoveto(dx, dy, *, file=None, flush=False)
Move the cursor dx positions horizontally and dy positions vertically.
dy is negative for up and positive for down.
Parameters:
dx: the number of horizontal positions to move, negative is left, positive is rightdy: the number of vertical positions to move, negative is up, positive is downfile: the file object to write to, defaultsys.stdoutflush: whether to flushfileafter the write, defaultFalse
rmoveto_bs(dx, dy, *, flush=False) -> bytes
Return the control bytes needed to move the cursor dx
positions horizontally and dy positions vertically.
dy is negative for up and positive for down.
setupterm(*args)
Run curses.setupterm, needed to be able to use the status line. Uses a global flag to avoid doing this twice.
stack_termios(fd=0, set_modes=None, clear_modes=None, strict=False)
Context manager to apply and restore changes to a tty.
Yield the previous tty modes as from termios.tcgetattr
or None if the changes could not be applied.
If strict, raise an exception instead of yielding None.
Parameters:
fd: optional tty file descriptor, default0.set_modes: an optional mapping of attribute name to new value for values to setclear_modes: an optional mapping of attribute name to new value for values to clearstrict: optional flag, defaultFalse; if true, raise exceptions from failedtcgetattrandtcsetattrcalls otherwise issue a warning if the errno is notENOTTYand proceed. This aims to provide ease of use in batch mode by default while providing a mode to fail overtly if required.
The attribute names are from
iflag, oflag, cflag, lflag, ispeed, ospeed, cc,
corresponding to the list entries defined by the termios.tcgetattr
call.
For set_modes, the attributes ispeed, ospeed and cc
are applied directly;
the other attributes are binary ORed into the existing modes.
For clear_modes, the attributes ispeed, ospeed and cc
cannot be cleared;
the other attributes are binary removed from the existing modes.
For example, to turn off the terminal echo during some operation:
with stack_termios(clear_modes={'lflag': termios.ECHO}):
... do something with tty echo disabled ...
status(msg, *args, **kwargs)
Write a message to the terminal's status line.
Parameters:
msg: message stringargs: if not empty, the message is %-formatted withargsfile: optional keyword argument specifying the output file. Default:sys.stderr.
Hack: if there is no status line use the xterm title bar sequence :-(
statusline(text, fd=None, reverse=False, xpos=None, ypos=None)
Update the status line.
statusline_bs(text, reverse=False, xpos=None, ypos=None)
Return a byte string to update the status line.
ttysize(fd)
Return a (rows, columns) tuple for the specified file descriptor.
If the window size cannot be determined, None will be returned for either or both of rows and columns.
This function relies on the UNIX stty command.
ttysizepx(fd)
Return a (rows,columns,widthpx,heightpx) tuple for the
specified file descriptor being the terminal character rows
and columns and pixel width and height respectively.
This function relies on the fcntl.ioctl using termios.TIOCGWINSZ.
Classes
class WinSize(builtins.tuple)
WinSize(rows, columns)
WinSize.__replace__(self, /, **kwds)
Return a new WinSize object replacing specified fields with new values
WinSize.columns
_tuplegetter(1, 'Alias for field number 1')
WinSize.rows
_tuplegetter(0, 'Alias for field number 0')
class WinSizePX(WinSizePX)
Size information about a terminal including its pixel size.
WinSizePX.char_height
<property object at 0x105fffe70>
WinSizePX.char_width
<property object at 0x105fffd80>
Metadata
Release files for cs-tty 20261016
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs_tty-20261016.tar.gz | 5.5 kB | Without provenance | Details for cs_tty-20261016.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs_tty-20261016-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for cs_tty-20261016-py2.py3-none-any.whl |
Total release size: 12.3 kB
Release files / cs_tty-20261016.tar.gz
| Download URL | cs_tty-20261016.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eac8dc62b0038d547d338de39e5aa07c842ad34347f41bcfa8f102d984910eba
|
|
BLAKE2b-256 checksum How to use checksums |
985d74bc9dd8b5576a83523e55e5fc63c6f66e9ad4450b32d7740734db2c48a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_tty-20261016-py2.py3-none-any.whl
| Download URL | cs_tty-20261016-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0fe12dc7e7c1a12309111cd598c192c695c4a888dd05faea5c037677f2468fdd
|
|
BLAKE2b-256 checksum How to use checksums |
2129338e22e3b1d8ae90f682f2f5998f3afe9be1575c43a89eb5c20f5ede3534
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for cs-tty 20261016
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.