Sign in

    tui

    Terminal UI library for MoonBit with reactive signals

    tui
    terminal
    ui
    cli
    Download zip
    Author
    Version
    0.2.0
    License
    MIT
    Last updated
    9 months ago
    Downloads
    70K

    #mizchi/tui

    Terminal UI library for MoonBit with reactive signals integration.

    #Features

    • ANSI rendering with diff-based updates
    • Reactive signals integration (mizchi/signals)
    • Component-based architecture (box, text, input, textarea, button)
    • Keyboard and mouse input handling
    • Layout powered by mizchi/crater

    alt text

    #Installation

    { "deps": { "mizchi/tui": "0.1.1" } }

    #Package Structure

    mizchi/tui/ ├── core/ # Component, Color, BorderChars, builders ├── events/ # InputEvent, parse_input, FocusManager ├── io/ # Platform I/O (print_raw, read_key, keypress) ├── render/ # App, ScreenBuffer, ANSI, layout └── components/ # UI components (button, input, modal, etc.)

    #Quick Start

    import {
    "mizchi/tui/render" as @render,
    "mizchi/tui/core" as @core,
    "mizchi/tui/io" as @io,
    "mizchi/tui/events" as @events,
    "mizchi/tui/components" as @c,
    "mizchi/signals",
    }

    fn main {
    let (cols, rows) = @io.get_terminal_size()
    let count = @signals.signal(0)

    let app = @render.App::new(cols, rows)

    fn render_ui() -> @core.Component {
    @c.column([
    @c.text("Count: " + count.get().to_string()),
    @c.button("Increment"),
    ])
    }

    // Initialize terminal
    @io.print_raw(@render.App::init_terminal())

    // Render
    @io.print_raw(app.render_frame(render_ui()))

    // Cleanup
    @io.print_raw(@render.App::restore_terminal())
    }

    #Examples

    • examples/counter - Simple counter with keyboard input
    • examples/chat - Chat-like interface
    • examples/form - Form with input fields
    • examples/button - Button states and interactions
    • examples/layout - Layout examples

    Run examples:
    moon run examples/counter

    #License

    MIT

    ActionMenu

    Action menu state and configuration

    App

    App manages the render loop and diff-based updates

    BorderChars

    Re-exports for convenient access to commonly used types

    ButtonState

    Button state for visual feedback

    CharBuffer

    Character-based framebuffer

    CharCell

    A single character cell in the terminal

    Color

    Re-exports for convenient access to commonly used types

    Component

    Re-exports for convenient access to commonly used types

    EditConfig

    Configuration for editable input behavior

    EventHandlers

    Event handlers map (component ID -> handler)

    FocusManager

    Focus manager for handling focus state and navigation

    FocusState

    Focus state for the application

    HitTestResult

    Hit test result

    InputEvent

    Input event

    InputMode

    Input mode for the application

    InputResult

    Result of an input session

    InputState

    Input state for visual feedback

    ItemScroller

    Simple item scroller state

    KeyEvent

    Keyboard event

    KeyModifier

    Key modifiers

    ModalState

    Modal state for controlling visibility

    MouseButton

    Mouse button

    MouseEvent

    Mouse event

    MouseEventType

    Mouse event type

    ProgressStyle

    Progress bar style

    RenderStyleMap

    Re-exports for convenient access to commonly used types

    ScrollState

    Scroll state for managing scrollable content

    SpecialKey

    Special keys

    StreamingState

    Streaming state for managing streaming text display

    TextContentMap

    Re-exports for convenient access to commonly used types

    TextStyle

    Text style for writing text

    TextareaState

    Textarea state for visual feedback

    Source Files