terminal

Useful functions for terminal-based programs.

Changed in version 2.0.0: domdf_python_tools.terminal.get_terminal_size() was removed. Use shutil.get_terminal_size() instead.

Classes:

Echo([indent])

Context manager for echoing variable assignments (in CPython).

Functions:

br()

Prints a blank line.

clear()

Clears the display.

interrupt()

Print the key combination needed to abort the script; dynamic depending on OS.

overtype(*objects[, sep, end, file, flush])

Print *objects to the text stream file, starting with '\\r', separated by sep and followed by end.

class Echo(indent='  ')[source]

Bases: object

Context manager for echoing variable assignments (in CPython).

Parameters

indent (str) – The indentation of the dictionary of variable assignments. Default '␣␣'.

Methods:

__enter__()

Called when entering the context manager.

__exit__(*args, **kwargs)

Called when exiting the context manager.

__enter__()[source]

Called when entering the context manager.

__exit__(*args, **kwargs)[source]

Called when exiting the context manager.

br()[source]

Prints a blank line.

clear()[source]

Clears the display.

Works for Windows and POSIX, but does not clear the Python Interpreter or PyCharm’s Console.

interrupt()[source]

Print the key combination needed to abort the script; dynamic depending on OS.

Useful when you have a long-running script that you might want to interrupt part way through.

Example:

>>> interrupt()
(Press Ctrl-C to quit at any time)
overtype(*objects, sep=' ', end='', file=None, flush=False)[source]

Print *objects to the text stream file, starting with '\\r', separated by sep and followed by end.

All non-keyword arguments are converted to strings like str does and written to the stream, separated by sep and followed by end.

If no objects are given, overtype() will just write "\\r".

Parameters
  • *objects – A list of strings or string-like objects to write to the terminal.

  • sep (str) – The separator between values. Default '␣'.

  • end (str) – The final value to print. Default ''.

  • file (Optional[IO]) – An object with a write(string) method. If not present or None, sys.stdout will be used.

  • flush (bool) – If True the stream is forcibly flushed after printing. Default False.