Ansi
Functions to control the screen, cursor, and text in the terminal using ANSI escape sequences.
import Ansi
import Stream exposing (Stream)
coolGreeting : Stream -> Cmd msg
coolGreeting stdout =
"Hello!"
|> Ansi.wrapItalic
|> Ansi.wrapColor Ansi.Green
|> Stream.sendLine stdout
Colors
Display text in the given color.
This will return the string with a "set color" sequence at the beginning and a "no color" sequence at the end.
Display text with the given background color.
This will return the string with a "set background color" sequence at the beginning and a "default background color" sequence at the end.
Change all subsequent terminal output to the given color.
This will persist even after program exit!
So be sure to call unsetColor
before exiting.
Change all subsequent terminal output to the default term color.
Change background of all subsequent terminal output to the given color.
This will persist even after program exit!
So be sure to call unsetBgColor
before exiting.
Change background of all subsequent terminal output to the default term color.
Styling
Display string with the given font weight.
Change all subsequent terminal output to the given font weight.
This will persist even after program exit!
So be sure to call unsetFontWeight
before exiting.
Change all subsequent terminal output to the term default font weight.
Display the given string as italic.
Display the given string as underline.
Display the given string with a strikethrough.
Change all terminal output from this point to italic (even after program exit).
Stop displaying terminal output as italic.
Change all terminal output from this point to underline (even after program exit).
Stop displaying terminal output as underline.
Change all terminal output from this point with a strikethrough (even after program exit).
Stop displaying terminal output with a strikethrough.
Reset all colors and styles to default.
Clearing the Screen
Clear screen in the given Direction.
Direction for clear functions.
- Down: Clear things after the cursor.
- Up: Clear things before the cursor.
- Full: Clear both directions.
Controlling the Cursor
Move the cursor up the given number of lines.
Move the cursor down the given number of lines.
Move cursor to the given row and column number of the visible terminal.
Show the cursor.
Hide the cursor.
You should call showCursor
before exiting your program, or the
cursor will still be gone after exiting.
Get the cursor position.
After sending this sequence to stdout, a new sequence containing the cursor's
column and row will be output. It will look like this: ESC[n;mR
where
n
is the row and m
is the column.
To capture this, you probably want to be in raw mode,
and be listening
on stdin. escape
will be helpful here when checking the captured string.
If you're using this in gren-tui
you can include it in your view
(or send it directly to an output stream).
This will trigger an update
with your onInput
message
holding a CursorReport row column
.
Arrow Keys
Use these functions if you are reading stdin and want to see if an arrow key was pressed.
ANSI escape sequence for the up arrow key.
ANSI escape sequence for the down arrow key.
ANSI escape sequence for the left arrow key.
ANSI escape sequence for the right arrow key.
Helpers
Measures the width of a String
in terminal columns.
Copied from https://github.com/wolfadex/elm-ansi/blob/3.0.0/src/Ansi/String.elm
The beginning of most ANSI escape sequences (The \e[
part).
Use this to define your own ansi functions.
For example, setItalic
is defined like this:
setItalic : String
setItalic =
prefix ++ "3m"
You can look up escape sequences here or here.
If you create functions you think should be included in the package I'd love it if you sent a pull request.
Unicode character for Escape (Esc).
You would use this if you needed to compare or parse a string holding an escape sequence.