module documentation

Utility functions surrounding terminal devices & I/O. Much of this code performs platform-sensitive branching, e.g. Windows support. This is its own module to abstract away what would otherwise be distracting logic-flow interruptions.

Function bytes_to_read Query stream ``input_`` to see how many bytes may be readable.
Function cbreak_already_set Undocumented
Function character_buffered Force local terminal ``stream`` be character, not line, buffered.
Function pty_size Determine current local pseudoterminal dimensions.
Function ready_for_reading Test ``input_`` to determine whether a read action will succeed.
Function stdin_is_foregrounded_tty Detect if given stdin ``stream`` seems to be in the foreground of a TTY.
Constant WINDOWS Whether or not the current platform appears to be Windows in nature.
Function _pty_size Suitable for most POSIX platforms.
Function _win_pty_size Undocumented
def bytes_to_read(input_): (source)

Query stream ``input_`` to see how many bytes may be readable. .. note:: If we are unable to tell (e.g. if ``input_`` isn't a true file descriptor or isn't a valid TTY) we fall back to suggesting reading 1 byte only. :param input: Input stream object (file-like). :returns: `int` number of bytes to read. .. versionadded:: 1.0

def cbreak_already_set(stream): (source)

Undocumented

@contextmanager
def character_buffered(stream): (source)

Force local terminal ``stream`` be character, not line, buffered. Only applies to Unix-based systems; on Windows this is a no-op. .. versionadded:: 1.0

def pty_size(): (source)

Determine current local pseudoterminal dimensions. :returns: A ``(num_cols, num_rows)`` two-tuple describing PTY size. Defaults to ``(80, 24)`` if unable to get a sensible result dynamically. .. versionadded:: 1.0

def ready_for_reading(input_): (source)

Test ``input_`` to determine whether a read action will succeed. :param input_: Input stream object (file-like). :returns: ``True`` if a read should succeed, ``False`` otherwise. .. versionadded:: 1.0

def stdin_is_foregrounded_tty(stream): (source)

Detect if given stdin ``stream`` seems to be in the foreground of a TTY. Specifically, compares the current Python process group ID to that of the stream's file descriptor to see if they match; if they do not match, it is likely that the process has been placed in the background. This is used as a test to determine whether we should manipulate an active stdin so it runs in a character-buffered mode; touching the terminal in this way when the process is backgrounded, causes most shells to pause execution. .. note:: Processes that aren't attached to a terminal to begin with, will always fail this test, as it starts with "do you have a real ``fileno``?". .. versionadded:: 1.0

Whether or not the current platform appears to be Windows in nature. Note that Cygwin's Python is actually close enough to "real" UNIXes that it doesn't need (or want!) to use PyWin32 -- so we only test for literal Win32 setups (vanilla Python, ActiveState etc) here. .. versionadded:: 1.0

Value
(sys.platform == 'win32')
def _pty_size(): (source)

Suitable for most POSIX platforms. .. versionadded:: 1.0

def _win_pty_size(): (source)

Undocumented