egui_simple_term 0.1.0

A small embeddable terminal widget for egui: a colored prompt, line editing, command history, and a scrollable output backlog.
Documentation
  • Coverage
  • 83.87%
    26 out of 31 items documented3 out of 18 items with examples
  • Size
  • Source code size: 138.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 420.9 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 57s Average build duration of successful builds.
  • all releases: 57s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • JOMANJOLAN/egui_simple_term
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JOMANJOLAN

egui_simple_term

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.

crates.io docs.rs License: MIT

Features

  • Colored prompt, input, and cursor — each part of the line is styled independently via a [Palette].
  • Full line editing — cursor movement, Home/End, Backspace/Delete, and paste.
  • Command history — arrow-up / arrow-down to recall previous commands.
  • Scrollable backlog — print output with [Terminal::writeln_grid]; it scrolls and sticks to the bottom.
  • No dependencies beyond eframe — drop it into any egui app.

Installation

Add it to your Cargo.toml:

[dependencies]
egui_simple_term = "0.1"

Requires Rust 1.88 or later.

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) {
        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 slightly longer, runnable example lives in examples/demo.rs:

cargo run --example demo

API

The public surface is deliberately tiny:

Type What it is
[Terminal] The widget. Call [Terminal::show] every frame; it returns the submitted command.
[Palette] The three colors — prompt_color, record_color, cursor_color.
[Line] / [CellGroup] The low-level data model behind the backlog, exposed for advanced use.

Key bindings

While the terminal has focus:

Keys Action
Printable characters, paste Insert text at the cursor
← / → Move the cursor
Home / End Jump to the start / end of the line
Backspace / Delete Delete before / at the cursor
↑ / ↓ Previous / next history entry
Enter Submit (returned by [Terminal::show])

Customizing colors

use egui_simple_term::Palette;

let palette = Palette {
    prompt_color: egui::Color32::YELLOW,
    ..Palette::default()
};

License

Licensed under the MIT license.