vito/elm-ansi/6.0.1

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.

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

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

type Action
= Print String
| Remainder String
| SetForeground (Maybe Color)
| SetBackground (Maybe Color)
| SetBold Bool
| SetFaint Bool
| SetItalic Bool
| SetUnderline Bool
| SetInverted 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.

  • Print is a chunk of text which should be interpreted with the style implied by the preceding actions (i.e. [SetBold 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.
  • The rest are derived from their respective ANSI escape sequences.
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.

= EraseToBeginning
| EraseToEnd
| EraseAll

Method to erase the display or line.