vito/elm-ansi/2.1.2

NOTE: this package is not compatible with Elm 0.19.1

Ansi.Log

Log interprets a stream of text and ANSI escape codes.

init : Window

Construct an empty model.

update : String -> Window -> Window

Parse and interpret a chunk of ANSI output.

Trailing partial ANSI escape codes will be prepended to the chunk in the next call to update.

type alias Window =
{ lines : Array Line
, position : CursorPosition
, savedPosition : Maybe CursorPosition
, style : Style
, remainder : String
}

Window is populated by parsing ANSI character sequences and escape codes via update.

  • lines contains all of the output that's been parsed
  • position is the current position of the cursor
  • style is the style to be applied to any text that's printed
  • remainder is a partial ANSI escape sequence left around from an incomplete segment from the stream
type alias Line =
List Chunk

A list of arbitrarily-sized chunks of output.

type alias Chunk =
{ text : String
, style : Style
}

A blob of text paired with the style that was configured at the time.

type alias CursorPosition =
{ row : Int
, column : Int
}

The coordinate in the window where text will be printed.

type alias Style =
{ foreground : Maybe Color
, background : Maybe Color
, bold : Bool
, faint : Bool
, italic : Bool
, underline : Bool
, inverted : Bool
}

The current presentation state for any text that's printed.