Frama-C:
Plug-ins:
Libraries:

Frama-C API - Ansi_escape

This modules provides utilities to use semantic tags to output color and style information on capable terminals.

Standard tags can be used in format strings as in the following example.

Format.printf "@{<bold>Bold Text} @{<red>Red Text}"

The name s of the string tags inside "@{<s>}" should match the corresponding style or color constructor. The comparison is case-insensitive. For colors, the color name may be prefixed by an optional "fg" for foreground color and by "bg" for background colors. Multiple tags can be given at once by separating them with a comma.

Format.printf "@{<red,bold>Red & Bold Text}"

Alternatively, style tags may be output using the new Style_tag :

Format.open_stag (Style_tag (Color Red))

For both versions, the semantic tags handlers have to be activated using the enable or enable_on functions below.

See Format.stag for details about semantic tags.

  • since 32.0-Germanium
val is_supported : unit -> bool

is_supported () returns whether the current terminal supports ansi escape sequence, i.e. if it exports a TERM environnement variable that is not assigned "DUMB"

val enable_on : Stdlib.Format.formatter -> unit -> unit

Enable the style output on the given formatter. No support test is performed.

  • returns

    a reset function that can be called to reset styles.

type color =
  1. | Black
    (*

    "black"

    *)
  2. | Red
    (*

    "red"

    *)
  3. | Green
    (*

    "green"

    *)
  4. | Yellow
    (*

    "yellow"

    *)
  5. | Blue
    (*

    "blue"

    *)
  6. | Magenta
    (*

    "magenta"

    *)
  7. | Cyan
    (*

    "cyan"

    *)
  8. | White
    (*

    "white"

    *)
  9. | Orange
    (*

    "orange"

    *)

Output colors. The associated string semantic tag is documented for each constructor. Note that there exists variants prefixed with "fg" and "bg" for each colors, for foreground and background. When no prefix is used, it means the foreground color.

type style =
  1. | Bold
    (*

    "bold"

    *)
  2. | Faint
    (*

    "faint"

    *)
  3. | Italic
    (*

    "italic"

    *)
  4. | Underline
    (*

    "underline"

    *)
  5. | Strike
    (*

    "strike"

    *)
  6. | Foreground of color
    (*

    "fgxxxx" where "xxxx" is the color tag

    *)
  7. | Background of color
    (*

    "bgxxxx" where "xxxx" is the color tag

    *)

Output Styles. The associated string semantic tag is documented for each constructor.

type Stdlib.Format.stag +=
  1. | Style_tag of style

Extension of semantic tags for style information