Stream: show and tell

Topic: Basic Terminal UI package


view this post on Zulip Matthew Griffith (Mar 04 2023 at 16:12):

Ok, something small but fun to share!

I put together a very basic TUI package to help with printing nice stuff to the terminal.

The API

image.png

main =
    Term.print
        [ Term.empty
        , Term.empty
        , Term.row [ Term.yellow ]
            [ Term.text "──"
            , Term.text " Welcome to Roc Terminal UI! "
            , Term.fill "─"
            , Term.text "Term.roc"
                |> Term.with [ Term.cyan ]
            ]
        , Term.lines [ Term.indent 3 ]
            [ Term.empty
            , Term.text "An indented thing!"
            , Term.text "and another"
            , Term.text "Maybe we want a list of other stuff!"
            , Term.empty
            , Term.lines [ Term.yellow ]
                [ Term.row []
                    [ Term.text "Intro to Terminal UI"
                    , Term.fill "."
                    , Term.text "Page 5"
                        |> Term.with [ Term.red ]
                    ]
                , Term.row []
                    [ Term.text "Intro to Roc"
                    , Term.fill "."
                    , Term.text "Page 6"
                        |> Term.with [ Term.red ]
                    ]
                ]
            ]
        , Term.empty
        , Term.fill "─"
        , Term.text "Hello!!!!!!"
            |> Term.with [ Term.indent 5, Term.red ]
        , Term.empty
        , Term.empty
        ]

The Result

image.png

It was really fun and satisfying to write :muscle:

I have an idea for a super simple animation API and a few convenience things for gathering input from the user too.

view this post on Zulip Brendan Hansknecht (Mar 04 2023 at 16:19):

Looks great! Also, Term.fill is simple and wonderful.

view this post on Zulip Richard Feldman (Mar 04 2023 at 17:04):

ooo, looks lovely! :smiley:

view this post on Zulip Matthew Griffith (Mar 05 2023 at 16:58):

Terminal ascii command codes are haunted, no one go in there.

view this post on Zulip Wolfgang Schuster (Mar 06 2023 at 16:24):

https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 is a great resource. I used it a lot for https://package.elm-lang.org/packages/wolfadex/elm-ansi/latest

view this post on Zulip Wolfgang Schuster (Mar 06 2023 at 16:27):

I think I have some other links in comments for other useful ANSI things like measuring character (not Char) widths and such

view this post on Zulip Matthew Griffith (Mar 06 2023 at 16:37):

Nice! I have that github gist in my notes, it's great :raised_hands:

I was running into some weird things where doing the "move up" command was erasing lines, which basically just meant that my understanding of what the cursor is was...well, I'm still slightly confused.


Last updated: Jul 06 2025 at 12:14 UTC