https://github.com/vito/elm-ansi
ANSI stream handling for Elm
https://github.com/vito/elm-ansi
Last synced: over 1 year ago
JSON representation
ANSI stream handling for Elm
- Host: GitHub
- URL: https://github.com/vito/elm-ansi
- Owner: vito
- License: mit
- Created: 2015-11-10T21:15:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-30T17:26:24.000Z (over 1 year ago)
- Last Synced: 2025-04-11T16:32:39.923Z (over 1 year ago)
- Language: Elm
- Homepage:
- Size: 90.8 KB
- Stars: 8
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-ansi
ANSI text stream handling for Elm.
## Usage
### Parsing a string of ANSI console output
The `Ansi.parse` function returns a list of `Ansi.Action` types which can be
used for interpreting escape sequences:
```elm
> Ansi.parse "\u{001b}[1;32mhello\u{001b}[0m"
[SetBold True,SetForeground (Just Green),Print "hello",SetForeground Nothing,SetBackground Nothing,SetBold False,SetFaint False,SetItalic False,SetUnderline False,SetBlink False,SetInverted False,SetFraktur False,SetFramed False]
: List Ansi.Action
```
The `Ansi.parseInto` function calls a helper function while parsing to avoid
the intermediate data structure.
### Rendering ANSI console output as HTML
The `Ansi.Log` module provides a component for incrementally parsing `String`
chunks and maintaining a `Model` that can be rendered as HTML.
It exports the usual `init`, `update`, `view` along with `Model` and other
types to assist with rendering, should you want to bring your own `view`
function. A `viewLine` function is also exported should you want to re-use that
aspect within your own view.