wolfadex/elm-ansi/3.0.0

NOTE: the latest version is 3.0.1

Ansi.Parser

For parsing ANSI codes into a custom type. Useful for turning ANSI text into another format such as HTML.

Borrowed from vito/elm-ansi and then modified to fit the rest of this package.

parse : String -> List Command

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

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

parseInto : a -> (Command -> a -> a) -> String -> a

Update a structure with commands parsed out of the given string.

type Command
= Text String
| Remainder String
| SetForeground (Maybe Color)
| SetBackground (Maybe Color)
| SetBold Bool
| SetFaint Bool
| SetItalic Bool
| SetUnderline Bool
| SetBlink Bool
| SetFastBlink Bool
| SetInverted Bool
| SetFraktur Bool
| SetFramed Bool
| Linebreak
| CarriageReturn
| CursorUp Int
| CursorDown Int
| CursorForward Int
| CursorBack Int
| CursorPosition Int Int
| CursorColumn Int
| EraseDisplay EraseMode
| EraseLine EraseMode
| SaveCursorPosition
| RestoreCursorPosition

The events relevant to interpreting the stream.

  • Text is a chunk of text which should be interpreted with the style implied by the preceding commands (i.e. [SetBold True, Text "foo"]) should yield a bold foo
  • Remainder is a partial ANSI escape sequence, returned at the end of the commands if it was cut off. The next string passed to parse should have this prepended to it.
  • The rest are derived from their respective ANSI escape sequences.
= EraseToBeginning
| EraseToEnd
| EraseAll

Method to erase the display or line.