Legend:
Library
Module
Module type
Parameter
Class
Class type
This library provides a small set of standard utility functions for interacting with terminals.
Note that this module does not depend on the unix library. There is therefore a way to use Terminal_ansi and progress.engine in a context other than a POSIX system (such as a unikernel). To do this, you need to compose Terminal_ansi with a library that looks like terminal.unix (which should allow you to obtain the size of a TTY). It would then be sufficient to compose the latter (just as the terminal library does) to then be able to use Progess_engine.Make with the result of this composition.
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.
val truncate_to_width : int ->string -> string
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).