drawille

    MoonBit port of drawille for terminal graphics with Unicode Braille characters

    terminal
    braille
    graphics
    ansi
    color
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    7 months ago
    Downloads
    358

    No dependencies

    #Moon Drawille

    Terminal graphics library using Unicode Braille characters for MoonBit.

    Snapshot

    #Overview

    cg-zhou/drawille is a high-performance terminal graphics library for MoonBit, inspired by the concept of Unicode Braille-based rendering. It provides a logical canvas that allows you to draw high-density graphics in traditional text-based terminals by leveraging the 2x4 dot grid available in Braille characters.

    This is a clean-room implementation in MoonBit, designed to be lightweight, efficient, and easy to integrate into other MoonBit projects.

    #Features

    • High-density graphics: 8 pixels per terminal character.
    • ANSI Color Support: 16-color ANSI and TrueColor (RGB) support.
    • Text Overlay: Mix text and graphics on the same canvas seamlessly.
    • Pure MoonBit: No external dependencies other than the standard library.

    #API Documentation

    The library provides a high-level Canvas interface:

    • Canvas::new() - Create a new canvas.
    • Canvas::set(x: Int, y: Int) - Draw a pixel.
    • Canvas::unset(x: Int, y: Int) - Erase a pixel.
    • Canvas::stroke_line(x1: Int, y1: Int, x2: Int, y2: Int) - Draw a line.
    • Canvas::set_text(x: Int, y: Int, text: String, style? : Style) - Draw text with optional styling.
    • Canvas::render(options? : RenderOptions) - Render canvas to a string for terminal display.

    #License

    MIT

    BasicColor

    pub enum BasicColor {
    Black
    Red
    Green
    Yellow
    Blue
    Magenta
    Cyan
    White
    } derive(Eq, Show)

    Basic ANSI color names used by the public color model.

    Canvas

    pub struct Canvas {
    cells : Map[(Int, Int), Cell]
    }

    Logical pixel and text surface.

    Use a Map to store cell content. Each key is (cell_x, cell_y). Each cell contains a bitmask for braille, optional text, and optional style.

    Canvas::clear

    fn Canvas::clear(self : Canvas) -> Unit

    Clear all canvas content.

    Canvas::new

    fn Canvas::new() -> Canvas

    Create an empty logical canvas.

    Canvas::render

    fn Canvas::render(self : Canvas, options? : RenderOptions) -> String

    Render the current canvas into a terminal string.

    Canvas::set

    fn Canvas::set(self : Canvas, x : Int, y : Int) -> Unit

    Activate one logical pixel.

    Canvas::set_style

    fn Canvas::set_style(self : Canvas, x : Int, y : Int, style : Style) -> Unit

    Apply a style to content located at a logical position.

    Canvas::set_text

    fn Canvas::set_text(self : Canvas, x : Int, y : Int, text : String, style? : Style) -> Unit

    Write text at a logical position with optional style.

    Canvas::stroke_line

    fn Canvas::stroke_line(self : Canvas, x1 : Int, y1 : Int, x2 : Int, y2 : Int, style? : Style) -> Unit

    Draw a styled line segment on the canvas. Use Bresenham's algorithm for drawing lines.

    Canvas::unset

    fn Canvas::unset(self : Canvas, x : Int, y : Int) -> Unit

    Deactivate one logical pixel.

    Cell

    type Cell

    Color

    pub enum Color {
    Default
    Ansi(BasicColor, Bool)
    Rgb(Int, Int, Int)
    } derive(Eq, Show)

    Public color abstraction for terminal styling.

    RenderOptions

    pub struct RenderOptions {
    line_ending : String
    enable_ansi : Bool
    reset_each_line : Bool
    } derive(Eq, Show)

    Rendering controls for terminal output.

    Style

    pub struct Style {
    fg : Color
    bg : Color
    } derive(Eq, Show)

    Style metadata attached to text or braille content.

    clamp_rgb

    fn clamp_rgb(channel : Int) -> Int

    Clamp an RGB channel to the inclusive range [0, 255].

    default_render_options

    fn default_render_options() -> RenderOptions

    Default rendering options for ANSI-capable terminal output.

    default_style

    fn default_style() -> Style

    Default style with terminal default foreground/background and all flags off.

    rgb

    fn rgb(r : Int, g : Int, b : Int) -> Color

    Construct a truecolor value after clamping each channel.

    with_fg

    fn with_fg(style : Style, fg : Color) -> Style

    Return a copy of a style with a different foreground color.

    without_ansi

    fn without_ansi(options : RenderOptions) -> RenderOptions

    Return rendering options with ANSI output disabled.

    Source Files

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io