package terminal
Install
    
    dune-project
 Dependency
Authors
Maintainers
Sources
sha256=8be449553379bb2dc5e8b79805c80447690a03dca3e9aee959fecf46d8278fb7
    
    
  sha512=841383e8aa7d6bd802ced5eb7feae01bd507b2914eb45e8a559140677f83d5b8ec614f1d0bc54421021b5254a1edd78dd8a2506b2dfb264af72448d76bd03ac5
    
    
  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).