Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Ansifmt.Ansi
This module defines the escape sequence data type.
Every value of this type is one styling (`Bold, `Reverse, `ForegroundColor.red) or the composition of two of them (`Bold&`Reverse), which can be chained (`Dim&`Italic&`Blink&`BackgroundColor.magenta).
open Ansifmt
let chesnay = `Italic
let rocquencout = Ansi.(`Bold & `Reverse & `Foreground Color.red)
(* compose to infinity! *)
let inria = Ansi.(chesnay & rocquencourt)
chesnay, rocquencourt and inria all have the same type t.
In a composition chain, if two stylings are overlapping (for example, `Foreground Color.blue & `Foreground Color.red), the rightmost takes precedence.
wrap ansi string wraps string with the rendered ansi escape sequence and its cancelling counterpart.
For example, if string is "Hello" and ansi is `Bold, the result will be "\x1b[1mHello\x1b[22m", which makes the string appear bold but not what comes after.
Example
open Ansifmt
let styling = `Foreground (`Rgb (255, 127, 0))
let text = "I love OCaml"
let () = Printf.printf "%s\n" (Ansi.wrap styling text)
I love OCaml will be printed in a beautiful orange color.