A unique approach to terminal coloring (ofarben)

Hello there! A few months back, I made a Rust crate called Farben. It started small but then became something I truly like.

After that, I tried programming in Odin and I really loved it. Because of that, I wanted to try rewriting my library in Odin.

After a few days, I finally got it working. Odin has made making this very easy and straightforward, love the language.

Introducing ofarben, a terminal coloring package built around a lightweight markup syntax.

ofarben.cprintfln("[bold red]Error:[/] something went wrong.")
ofarben.cprintfln("[green]Success:[/] operation completed.")
ofarben.cprintfln("[rgb(255,100,0)]Custom color[/]")

The features that currently work:

  • Named colors, RGB, ANSI256, and hex (#ff0000, #f00)
  • Bold, italic, underline, strikethrough, and more
  • Partial resets ([/red]) removes just the red and keeps everything else
  • Style bleeding across calls with reset = false
  • TTY/env detection, respects NO_COLOR, CLICOLOR_FORCE, etc.
  • Color degradation, automatically downgrades RGB to ANSI256 to 16 colors to nothing based on terminal support
  • Got a little too much fun making this one: compiler-quality diagnostic errors that I tried to make look like Odin’s compiler errors.
  • core:fmt-mirrored API just with a c prefix: cprintfln, ctprintf, cwprintf, caprintf, and more

Codeberg: https://codeberg.org/razkar/ofarben
GitHub mirror: https://github.com/razkar-studio/ofarben

What are your thoughts about it? Let me know. Especially something about:

  • How does the syntax feel to use?
  • Anything unintuitive?
  • Any features you want to add in the future?
  • Anything I didn’t cover here that you wanted to ask about?
6 Likes

Looks cool! Any images to show how it looks in practice?

I didn’t see anything about platform support - is this cross platform? I’m not sure how console coloring works, and how similar it is between Windows and Linux/Mac.

Also, how does this compare to @xuul 's afmt library? Seems like they achieve similar things, but perhaps with a different philosophy on syntax.

1 Like

Thanks! For screenshots, I’ve added some to the README now.

Regarding platform support, oFarben should work on any platform that supports ANSI escape codes for terminal coloring. I’ve personally tested it on Linux so far. The terminal itself generally shouldn’t matter as long as it supports the relevant ANSI sequences.

I took a glance at afmt, and from what I’ve seen, afmt looks more like a fmt-compatible ANSI formatting library, whereas oFarben is centered around inline markup.

The goal with oFarben was to write styled text directly in the string itself. I haven’t used afmt extensively though, so I wouldn’t want to make a deeper comparison.

1 Like