Logo

index : termcolors-jai

---

  • summary
  • about
  • tree
  • log
  • branches
https://git.ptrace.dev/public/termcolors-jai.git
ssh://git@git.ptrace.dev/public/termcolors-jai.git
JAI: 67%
MD: 33%

Terminal Colors for Jai

This is a small declarative library which allows you to create colorful terminal messages.

Note, that Jai already provides a module for printing colors: modules/Print_Color.

The differences are, that the builtin module prints the characters directly, where this library returns strings.

APIs of this library also returning the amount of characters, which were used for representing the colors. Which makes it useful for CLI programs, that are aware of the terminal window width.

The last thing: The builtin library uses a default color palette. Where this library extends it a bit more and allows you to use RGB values.

Windows

I don't develop for Windows, so I'm not sure if this library will work on it.
But I don't mind supporting Windows, you can provide me more information or a patch.

Usage

Put the directory termcolors in your projects modules directory, or link it while building.

Example


#import "termcolors";

main :: () {
    termcolors_init_allocator_and_context();

    // If you want, you can reset the library pool with this proc
    defer termcolors_reset_pool();


                        font style     background color
                        v              v
    log(paint("FooBar", .BOLD, .BLACK, .WHITE));
              ^                ^
              text             foreground color


                                                              background color
                                                              v
    log(paint_ex("FooBar", .[.BOLD, .UNDERLINE, .ITALIC], 84, 124));
                 ^           ^                            ^
                 text        multiple font styles         foreground 256bit color
}

More Information

There are several APIs and overloads, which are ranging from static/more declarative, to flexible/fully customizable.

Please consult termcolors/lib.jai for a more detailed documentation.

You can also view test/test.jai for more examples. If you want to run those examples, execute them with jai build.jai - run silent.

Credits

  • https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences
EXPAND COLLAPSE
Name
Size
Modified (UTC)
.gitignore
25 b
2025-11-08
raw
LICENSE
2 kB
2025-11-08
raw
README.md
3 kB
2026-01-16
raw
build.jai
3 kB
2025-11-08
raw
---
---
termcodes.md
3 kB
2025-11-08
raw
---
---
lib.jai
16 kB
2026-01-16
raw
module.jai
62 b
2025-11-08
raw
---
---
test.jai
3 kB
2026-01-16
raw
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit