Skip to main content

Crate egaku_term

Crate egaku_term 

Source
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:

  1. Enable raw mode + alternate screen + hide cursor on entry.
  2. Restore those on exit (and on panic, ideally).
  3. Pump crossterm::event::read() in a loop.
  4. Translate KeyEvent into something the app’s state machine understands.
  5. 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 of Cells. Drawers write cells into it; the runtime diffs it against the previous frame and flushes only the changed cells via render::render_diff — no full-repaint, no format!() (★★ TYPED EMISSION).
  • event::from_crossterm — convert any crossterm::event::Event into an egaku::KeyCombo. Pairs with egaku::KeyMap for action dispatch.
  • draw — drawers for every widget egaku ships (ListView, TableView, TextInput, TabBar, Modal, SplitPane, ScrollView). Each one takes a Buffer, a Rect, 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 own is_focused(). It lives here rather than in egaku because a drawer needs a Buffer and a Palette and egaku depends on no renderer. Modal is a documented non-implementor — see the trait docs.
  • TestBackend — headless Buffer capture for golden-frame tests.
  • App / run — a generic event-loop runtime. Implement App::handle
    • App::draw and run(&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
App trait + run() runtime.
draw
Drawers for egaku widgets onto a Buffer.
error
Error type for terminal operations.
event
Adapter from crossterm::event::Event to egaku::KeyCombo.
keymap
keymap! declarative macro — ergonomic keybinding tables.
render
The diff renderer — projects changed Cells to crossterm Commands.
terminal
Drop-safe terminal lifecycle wrapper + panic-safe restore (Quadro P7).
theme
Adapter from egaku::Theme (RGBA float) to crossterm::style::Color.

Macros§

key
Construct a KeyCombo from a literal description.
keymap
Build an egaku::KeyMap from a list of combo => action rows.

Structs§

Buffer
A width × height grid of attributed Cells, 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.
TestBackend
A headless renderer that draws into an in-memory Buffer.

Type Aliases§

Frame
The back buffer a frame is drawn into. Alias of Buffer — a drawer’s canvas for one frame, diffed against the previous frame by the runtime.