Stream: show and tell

Topic: Terminal Colors


view this post on Zulip Luke Boswell (Nov 03 2023 at 04:27):

lukewilliamboswell/roc-ansi-escapes provides some helpers to print pretty colors to the terminal using ANSI escape codes.

app "example"
    packages {
        cli: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br",
        pkg: "https://github.com/lukewilliamboswell/roc-ansi-escapes/releases/download/0.1.1/cPHdNPNh8bjOrlOgfSaGBJDz6VleQwsPdW0LJK6dbGQ.tar.br",
    }
    imports [cli.Stdout, pkg.Color.{ fg }]
    provides [main] to cli

main =
    [
        "The ",
        "GREEN" |> Color.fg Green,
        " frog, the ",
        "BLUE" |> Color.fg Blue,
        " bird, and the ",
        "RED" |> Color.fg Red,
        " ant shared a leaf.",
    ]
    |> Str.joinWith ""
    |> Stdout.line

I was going through some older stuff I had done and thought I might make this into a package for people to use as it could be fun for the Advent of Code.

Screenshot-2023-11-03-at-15.25.06.png

view this post on Zulip Luke Boswell (Nov 03 2023 at 04:28):

Screenshot-2023-11-03-at-15.28.20.png

view this post on Zulip Sven van Caem (Nov 03 2023 at 13:29):

Very clean API!

It occurs to me that this might be a case where being able to write string literals inside a string interpolation could come in handy!

E.g:

"The \("GREEN" |> Color.fg Green) frog"

view this post on Zulip Richard Feldman (Nov 03 2023 at 13:50):

that already works, if desired :big_smile:


Last updated: Jul 06 2025 at 12:14 UTC