package console
Module Console.EnvSource
How a formatter prints, from the environment: colour, depth and UTF-8.
Formatter setup from the environment.
Env sets a formatter's colour, colour depth and UTF-8 flag from the environment. The caller says whether the output is a terminal. Env needs no Unix. A program that cannot link Unix can detect a terminal another way, such as with Out_channel.isatty. The console.tty library uses Unix.isatty for Fmt.stdout and Fmt.stderr (Console_tty.setup).
val setup :
?style_renderer:Fmt.style_renderer ->
?utf_8:bool ->
?theme:Theme.t ->
is_tty:bool ->
Format.formatter ->
unitsetup ~is_tty ppf sets the style renderer, the Fmt.utf_8 flag, the Color.depth and the Theme of ppf. is_tty says whether ppf writes to a terminal.
- The style renderer is
style_rendererif given, for example asFmt_cli.style_rendererreads it from a--coloroption. Otherwise it is`NoneifNO_COLORis set and not empty, or ifTERMis unset, empty ordumb. Otherwise it is`Ansi_ttyiffis_ttyholds orCONSOLE_CASTrecords the output.CLICOLOR_FORCEandFORCE_COLORare not read; use--color=alwaysto force colour. Fmt.utf_8isutf_8if given. Otherwise it istrueiff the locale's character set is UTF-8. The locale is the first ofLC_ALL,LC_CTYPEandLANGthat is set and not empty, in POSIX order. An unset locale is not UTF-8, and the widgets then print only ASCII.- The colour depth is
`True_colorifCOLORTERMistruecoloror24bit, or ifTERMends in-direct. It is`Ansi_256ifTERMcontains256color, and`Ansi_16otherwise. - The theme is
themeif given. Otherwiseppfkeeps its theme.
ensure ~is_tty ppf is setup ~is_tty ppf (setup) if the program has not configured ppf, and does nothing otherwise. ppf is configured if it has a style renderer or a Fmt.utf_8 flag set (with Fmt, Fmt_tty or setup), or a Color.depth. Setting a Theme does not count.