A low-level package for text formatting and layout for your terminal.
This package is meant as a building block for more expressive packages. You can think of it like elm/virtual-dom for elm/html and mdgriffith/elm-ui.
port module Main exposing (..)
import Ansi
import Ansi.Cursor
import Ansi.Font
import Platform
init _ =
( ()
, [ Ansi.Font.resetAll
, Ansi.clearScreen
, Ansi.Cursor.moveTo { row = 1, column = 1 }
, "🌈 Hello, " ++ Ansi.Font.bold "world" ++ "!"
]
|> String.concat
|> stdout
)
stdout : String -> Cmd msg
main =
Platform.worker
{ init = init
, subscriptions = \_ -> Sub.none
, update = \_ model -> ( model, Cmd.none )
}
if printed to a terminal would give you
🌈 Hello, World!
Walking through this step-by-step:
- With
Ansi.Font.resetAll
we reset all of the font settings, removing and styles that might be left over. - Then we use
Ansi.clearScreen
to, clear the screen. - At this point our cursor is still wherever we left it so we move it to the top left most corner with
Ansi.Cursor.moveTo { row = 1, column = 1 }
. - Now we can finally start drawing our content! We want to write out
"🌈 Hello, World!"
, but we also want to makeWorld
bold. - Finally we join all of this together and send it out through a port!
For more complete example including handling input, checkout the examples directory in the repo.
For a more production like example, check out micro-dungeon.
or