/motoko-color

A library for rendering color schemes and graphics to the terminal, based on the ANSI ASCII standard in Motoko

Primary LanguageMotokoApache License 2.0Apache-2.0

motoko-color

A library for styling your terminal in Motoko!

Example image


Getting started


Easy to use, expressive API:

import Writer from "mo:color/Writer";
import TextStyle from "mo:color/TextStyle";

let { backgroundColor; textColor } = TextStyle;

let writer = Writer.Writer();

writer
  .text("hello world")
  .textColor(textColor.black)
  .backgroundColor(backgroundColor.white)
  .bold(true)
  .print();

Chain multiple colors on the same line:

...
import Debug "mo:base/Debug";

Debug.log(
  writer
    .text("It's easy being green")
    .textColor(textColor.green)
    .read()
  # ", however... " #
  writer
    .text("I really love purple backgrounds!")
    .backgroundColor(backgroundColor.purple)
    .read()
);

Use RGB colors for the text or background:

writer
  .text("woah dude, RGB!")
  .textColorRGB(20,40,60)
  .backgroundColorRGB(180,200,220)
  .print();

Immutable text styling settings, so use it all over the place, and don't worry about overwriting a bound setting.

let greenCheckMark = writer
  .text("✓")
  .textColor(textColor.green)
  .backgroundColor(backgroundColor.white);
let redCheckMark = greenCheckMark
  .textColor(textColor.red);

greenCheckMark.print();
redCheckMark.print();

Documentation

Further documentation for the latest release can be found at https://byronbecker.github.io/motoko-color.

If you'd like to generate documentation locally run $(vessel bin)/mo-doc && firefox docs/index.html

Example

See the example folder for usage, making sure that both vessel and wasmtime are installed before running make run-example from the root directory.





Credits

Credits to Christopher Hegemann for motoko-library-template that helped jumpstart this library

License

motoko-color is distributed under the terms of the Apache License (Version 2.0).

See LICENSE for details.