Package: cs.tty
Functions related to terminals.Latest release 20210316:ttysize: discard the Popen object earlier.ttysize: close Popen.stdout after use. seems to leak.Functionmodify_termios(fd=0, set_modes=None, clear_modes=None, strict=False)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.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 fromiflag,oflag,cflag,lflag,ispeed,ospeed,cc,
corresponding to the list entries defined by thetermios.tcgetattrcall.Forset_modes, the attributesispeed,ospeedandccare applied directly;
the other attributes are binary ORed into the existing modes.Forclear_modes, the attributesispeed,ospeedandcccannot 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)Functionsetupterm(*args)Run curses.setupterm, needed to be able to use the status line.
Uses a global flag to avoid doing this twice.Functionstack_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 fromtermios.tcgetattrorNoneif the changes could not be applied.
Ifstrict, raise an exception instead of yieldingNone.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 fromiflag,oflag,cflag,lflag,ispeed,ospeed,cc,
corresponding to the list entries defined by thetermios.tcgetattrcall.Forset_modes, the attributesispeed,ospeedandccare applied directly;
the other attributes are binary ORed into the existing modes.Forclear_modes, the attributesispeed,ospeedandcccannot 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 ...Functionstatus(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 :-(Functionstatusline(text, fd=None, reverse=False, xpos=None, ypos=None)Update the status line.Functionstatusline_bs(text, reverse=False, xpos=None, ypos=None)Return a byte string to update the status line.Functionttysize(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 UNIXsttycommand.ClassWinSize(builtins.tuple)WinSize(rows, columns)PropertyWinSize.columnsAlias for field number 1PropertyWinSize.rowsAlias for field number 0Release LogRelease 20210316:ttysize: discard the Popen object earlier.ttysize: close Popen.stdout after use. seems to leak.Release 20201102:
New modify_termios and stack_termios to apply (and restore) termios modes.Release 20200521:New status() function dragged in from cs.logutils, which uses cs.upd for status() -- needs some refactoring to match with the other functions in cs.tty -- text vs bytes, stdout vs stderr, etc.Get warning() from cs.gimmicks.Release 20190101:
Small bugfix for setupterm.Release 20170903:
add statusline and statusline_s functions; ttysize: support BSD stty output formatRelease 20160828:
Use "install_requires" instead of "requires" in DISTINFO, add PyPI category.Release 20150116:
Initial PyPI release.