Expand description
Egaku-Term — terminal renderer + runtime for egaku widget state machines.
egaku is a pure-logic widget toolkit: state only, no rendering, no event
loop. Every consumer that wants a terminal UI today re-implements the
same boilerplate:
- Enable raw mode + alternate screen + hide cursor on entry.
- Restore those on exit (and on panic, ideally).
- Pump
crossterm::event::read()in a loop. - Translate
KeyEventinto something the app’s state machine understands. - Hand-style each widget render — selected line reverse video, padding, column wrapping, etc.
egaku-term lifts those five steps into one library:
Terminal— Drop-safe lifecycle wrapper. Constructing one enables raw mode + alt screen; dropping (or panicking with one alive) restores the terminal.Buffer— the typed back buffer ofCells. Drawers write cells into it; the runtimediffs it against the previous frame and flushes only the changed cells viarender::render_diff— no full-repaint, noformat!()(★★ TYPED EMISSION).event::from_crossterm— convert anycrossterm::event::Eventinto anegaku::KeyCombo. Pairs withegaku::KeyMapfor action dispatch.draw— drawers for every widget egaku ships (ListView,TableView,TextInput,TabBar,Modal,SplitPane,ScrollView). Each one takes aBuffer, aRect, the widget, the theme, and a focus flag.Draw— the uniform surface over those drawers:widget.draw(buf, rect, palette), object-safe, sourcing focus from the widget’s ownis_focused(). It lives here rather than in egaku because a drawer needs aBufferand aPaletteand egaku depends on no renderer.Modalis a documented non-implementor — see the trait docs.TestBackend— headlessBuffercapture for golden-frame tests.App/run— a generic event-loop runtime. ImplementApp::handleApp::drawandrun(&mut app)does the rest.
keymap!/key!— declarative macros that make hand-authoring keybindings ergonomic.
§Minimal example
use egaku::ListView;
use egaku_term::{App, Buffer, Result, draw};
#[derive(Clone, Copy, PartialEq, Eq)]
enum Action { Next, Prev, Quit }
struct Wizard {
list: ListView,
keys: egaku::KeyMap<Action>,
done: bool,
}
impl App for Wizard {
type Action = Action;
fn keymap(&self) -> &egaku::KeyMap<Action> { &self.keys }
fn handle(&mut self, action: &Action) {
match action {
Action::Next => self.list.select_next(),
Action::Prev => self.list.select_prev(),
Action::Quit => self.done = true,
}
}
fn draw(&self, frame: &mut Buffer) -> Result<()> {
draw::list(frame, egaku::Rect::new(0.0, 0.0, 40.0, 10.0), &self.list, true);
Ok(())
}
fn should_quit(&self) -> bool { self.done }
}Re-exports§
pub use app::App;pub use app::EventPump;pub use app::run;pub use draw::Draw;pub use error::Error;pub use error::Result;pub use event::from_crossterm;pub use render::render_diff;pub use terminal::Terminal;pub use crossterm;
Modules§
- anim
- Terminal motion: time-parameterised helpers over the fleet’s motion algebra.
- app
Apptrait +run()runtime.- draw
- Drawers for
egakuwidgets onto aBuffer. - error
- Error type for terminal operations.
- event
- Adapter from
crossterm::event::Eventtoegaku::KeyCombo. - keymap
keymap!declarative macro — ergonomic keybinding tables.- render
- The diff renderer — projects changed
Cells to crosstermCommands. - terminal
- Drop-safe terminal lifecycle wrapper + panic-safe restore (Quadro P7).
- theme
- Adapter from
egaku::Theme(RGBA float) tocrossterm::style::Color.
Macros§
- key
- Construct a
KeyCombofrom a literal description. - keymap
- Build an
egaku::KeyMapfrom a list ofcombo => actionrows.
Structs§
- Buffer
- A
width × heightgrid of attributedCells, row-major. - Cell
- One attributed cell of the framed board.
- Modifiers
- A typed set of terminal text attributes.
- Style
- A typed style: foreground, background, and
Modifiers. - Test
Backend - A headless renderer that draws into an in-memory
Buffer.