ModularM
Modular2y ago
2 replies
toasty

Mist and Weave: ANSI Styling and text formatting libraries

Mist

mist
lets you safely use advanced styling options on the terminal. It offers you convenient methods to colorize and style your output, without you having to deal with all kinds of weird ANSI escape sequences and color conversions.
https://github.com/thatstoasty/mist

import mist

fn main():
    # ANSI Color Support (0-15)
    var style = mist.new_style().foreground(12)
    print(style.render(a))

    # ANSI256 Color Support (16-255)
    style = mist.new_style().foreground(55)
    print(style.render(a))

    # RGBColor Support (Hex Codes)
    style = mist.new_style().foreground(0xc9a0dc)
    print(style.render(a))


Weave

weave
is a collection of (ANSI-sequence aware) text reflow operations & algorithms. Includes text padding, margins, truncation, wrapping, word wrapping, indenting, and dedenting.
https://github.com/thatstoasty/weave

eg
from weave import indent

fn main() raises:
    print(indent("Hello\nWorld\n  TEST!", 5))

     Hello
     World
       TEST!


Both of these projects are used in
mog
, but if you need something lightweight to apply some texting coloring/styling or simple ANSI aware formatting, you can use one of these libraries instead.
Was this page helpful?