moonbit-chalk

Terminal string styling support for MoonBit.

string
chalk
color
moon add kokic/moonbit-chalk@0.6.0
Download zip
Author
Version
0.6.0
License
MIT
Last updated
2 months ago
Downloads
44
README

#MoonBit-Chalk

⚠️ This is a fork and continued maintenance version of Lampese's MoonBit-Chalk.

MoonBit-Chalk provides some APIs for terminal color rendering, including rendering APIs for formatting, background color, and font color.

#Usage

Use chalk() to construct a Chalk object and attach properties to it through chain calls.

Chalk provides three types of enum internally for setting properties: text color(Color enum), background color(BackGroundColors enum), and format(Modifier enum).

Chalk is an immutable variable, which allows you to easily reuse and combine it, and finally use Render to render any value that conforms to the Show Trait.

let str = chalk().background(BgRed).modifier(Bold).color(Red).render("hello")

#
BackgroundColor

pub(all) enum BackgroundColor {
BgBlack
BgRed
BgGreen
BgYellow
BgBlue
BgMagenta
BgCyan
BgWhite
BgBlackBright
BgRedBright
BgGreenBright
BgYellowBright
BgBlueBright
BgMagentaBright
BgCyanBright
BgWhiteBright
}

#
Chalk

pub(all) enum Chalk {
Cons(Chalk, Render)
Nil
}

#
Chalk::background

fn Chalk::background(self : Chalk, color : BackgroundColor) -> Chalk

#
Chalk::color

fn Chalk::color(self : Chalk, color : Color) -> Chalk

#
Chalk::modifier

fn Chalk::modifier(self : Chalk, modifier : Modifier) -> Chalk

#
Chalk::render

fn[T : Show] Chalk::render(self : Chalk, to_render : T) -> String

#
Color

pub(all) enum Color {
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
BlackBright
RedBright
GreenBright
YellowBright
BlueBright
MagentaBright
CyanBright
WhiteBright
}

#
Modifier

pub(all) enum Modifier {
Reset
Bold
Dim
Italic
Underline
Overline
Inverse
Hidden
Strikethrough
}

#
Render

pub(all) enum Render {
RenderBackGround(BackgroundColor)
RenderColor(Color)
RenderModifier(Modifier)
}

#
chalk

fn chalk() -> Chalk