Expand description
A small, embeddable terminal widget for egui.
It renders an interactive command line — a colored prompt, the text you are
typing, a block cursor, and a scrollable backlog of output — and hands each
submitted command back to your app as a String.
What those commands do is entirely up to you.
The public surface is deliberately tiny:
Terminal— the widget. CallTerminal::showevery frame.Palette— the three colors (prompt_color,record_color,cursor_color).Line/CellGroup— the low-level data model behind the backlog, exposed for advanced use.
§Quick start
use eframe::{
App, Frame, NativeOptions, Result as EframeResult,
egui::{CentralPanel, Ui, ViewportBuilder},
};
use egui_simple_term::{Palette, Terminal};
struct Repl {
term: Terminal,
}
impl App for Repl {
fn ui(&mut self, ui: &mut Ui, _frame: &mut Frame) {
// Drive the terminal from a panel; `show` handles input + painting.
CentralPanel::no_frame().show(ui, |ui| {
if let Some(command) = self.term.show(ui) {
// `command` is the text the user typed, without the prompt.
self.term.writeln_grid(&format!("unknown command: {command}"));
}
});
}
}
fn main() -> EframeResult {
let options = NativeOptions {
viewport: ViewportBuilder::default().with_inner_size([800.0, 600.0]),
..Default::default()
};
eframe::run_native(
"repl",
options,
Box::new(|_cc| Ok(Box::new(Repl {
term: Terminal::new("> ", Palette::default()),
}))),
)
}A complete, runnable version lives in examples/demo.rs — run it with
cargo run --example demo.