package terminal
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=7f87f0597363928c45ba859ae5a1430f6aa3c29e251ff1a53cf786ed0e045961
sha512=45dee4fe2ae0b7fc3ca675f6e854d738873eb608ef9155ea5d7edac4639c183ae1f512847a1b43bdfc1f4c459e7d5b44d03ee809455797e680f890b33d531367
doc/terminal.ansi/Terminal_ansi/index.html
Module Terminal_ansiSource
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.
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).