vito/elm-ansi/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Ansi

This library primarily exposes the parse function and the types that it will yield.

parse : String -> List Action

Convert an arbitrary String of text into a sequence of actions.

If the input string ends with a partial ANSI escape sequence, it will be yielded as a Remainder action, which should then be prepended to the next call to parse.

type Action
= SetForeground (Maybe Color)
| SetBackground (Maybe Color)
| SetBold Bool
| SetFaint Bool
| SetItalic Bool
| SetUnderline Bool
| SetInverted Bool
| Linebreak
| CarriageReturn
| Print String
| Remainder String

The events relevant to interpreting the stream.

  • SetForeground corresponds to \e[3Xm and \e[4Xm where X is the color
  • SetBackground corresponds to \e[9Xm and \e[10Xm where X is the color
  • SetBold corresponds to \e[1m
  • SetFaint corresponds to \e[2m
  • SetItalic corresponds to \e[3m
  • SetUnderline corresponds to \e[4m
  • SetInverted corresponds to \e[7m
  • Linebreak corresponds to a '\n' character
  • CarriageReturn corresponds to a '\r' character
  • Print is a chunk of text which should be interpreted with the style implied by the preceding actions (i.e. [Bold True, Print "foo"]) should yield a bold "foo"
  • Remainder is a partial ANSI escape sequence, returned at the end of the actions if it was cut off. The next string passed to parse should have this prepended to it.
type Color
= Black
| Red
| Green
| Yellow
| Blue
| Magenta
| Cyan
| White
| BrightBlack
| BrightRed
| BrightGreen
| BrightYellow
| BrightBlue
| BrightMagenta
| BrightCyan
| BrightWhite

The colors applied to the foreground/background.