A TUIs package written in MoonBit
Dependencies
moon add FrozenLemonTee/LunarTUIimport {
"FrozenLemonTee/LunarTUI@0.1.0",
}let title = @widgets.Label::new(
"Welcome to LunarTUI",
left=2,
top=1,
)
let progress = @widgets.ProgressBar::new(
20,
value=0.75,
left=2,
top=3,
prefix="Loading:",
suffix="complete",
)
let container = @widgets.Container::new(
0,
0,
80,
24,
layout=@layouts.VLayout::new(),
children=[title, progress],
)
let terminal = @terminal.Terminal::new(@base.Area::new(80, 24))
@terminal.Terminal::clear()
terminal.draw(container)
@terminal.Terminal::newline()| Type | Purpose |
|---|---|
| EventKind | Identifies the event category: key, mouse, resize, focus, or text input. |
| Event | Wrapper carrying exactly one event payload. |
| KeyEvent | Key state, key code, optional text, modifiers, and repeat count. |
| MouseEvent | Mouse state, optional button, optional scroll direction, position, and modifiers. |
| ResizeEvent | Terminal width and height. |
| FocusEvent | Focus gained or lost. |
| TextInputEvent | Committed text input. |
| EventResult | Widget response: Ignored, Handled, or Redraw. |
let key = @base.KeyEvent::new(
@base.KeyState::Down,
@base.KeyCode::Enter,
)
let event = @base.Event::key(key)pub(open) trait Widget {
fn width(self : Self) -> Int
fn height(self : Self) -> Int
fn render(self : Self, frame : Frame) -> Unit
fn handle_event(self : Self, event : Event) -> EventResult
}let source = @lunartui.EventSource::new()
match source.poll_event(32) {
Some(event) => {
match widget.handle_event(event) {
@base.EventResult::Redraw => terminal.draw(widget)
@base.EventResult::Handled => ()
@base.EventResult::Ignored => ()
}
}
None => ()
}TerminalEvent -> LunarEvent -> LunarEvent/lunartui -> LunarTUI -> application redraw loopmoon check --target native
moon test --target nativeA TUIs package written in MoonBit
Dependencies