Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
TerminalSourceThis library provides a small set of standard utility functions for interacting with terminals.
guess_printed_width s returns an estimate of the number of terminal columns that the UTF-8 encoded string s would occupy if displayed in a terminal, after stripping any ANSI escape codes in the string.
Note: this function uses a heuristic (Uucp.tty_width_hint) to guess the rendered length of supplied strings. This function is not guaranteed to be correct on all UTF-8 codepoints. See the Uucp documentation for details.
truncate_to_width n s is the longest prefix of UTF-8 encoded string s that will fit within n columns when displayed in a terminal (without including unbalanced ANSI control sequences after the n-th column).
As with guess_printed_width, the implementation relies on heuristics and so may not be accurate for all inputs (or for all terminal implementations).