Skip to main content

Crate egui_tty

Crate egui_tty 

Source
Expand description

A terminal emulator widget for egui.

libghostty-vt — the VT engine Ghostty is built on — owns everything that makes a terminal a terminal: the parser, the screen and its scrollback, reflow on resize, selections, and input encoding. This crate is the part Ghostty deliberately leaves out: turning the resulting grid into pixels, and turning window events into terminal events.

What you get is a real terminal, not a log view. Full-screen programs, mouse reporting, bracketed paste, OSC 8 links, the Kitty keyboard protocol — they work because the engine underneath is the one shipping in Ghostty.

§Attaching a program

The crate takes no view on where the bytes come from: a local pty, a websocket to another machine, or a test harness. You provide a Tty to write to, and an std::sync::mpsc::Receiver the program’s output arrives on.

use std::sync::{Arc, mpsc};

struct Echo;

impl egui_tty::Tty for Echo {
    fn write(&self, _bytes: &[u8]) -> egui_tty::Result<()> {
        Ok(())
    }

    fn resize(&self, _cols: u16, _rows: u16) -> egui_tty::Result<()> {
        Ok(())
    }
}

let (writer, output) = mpsc::channel();
writer.send(b"hello from a terminal\r\n".to_vec()).ok();

let mut terminal = egui_tty::Terminal::new(egui_tty::TtyStream {
    output,
    tty: Arc::new(Echo),
})?;

Then draw it, once per frame, wherever you want it:

let style = egui_tty::TerminalStyle::from_visuals(ui.visuals());
terminal.ui(ui, &style);

See examples/shell.rs for the whole thing against a real login shell.

§Building

libghostty-vt compiles Ghostty’s VT engine from source, so a Zig 0.15.x toolchain has to be on PATH to build this crate.

Structs§

Error
Anything that can go wrong between a program and the grid it draws on.
Terminal
A terminal: an emulator, the program attached to it, and the grid both end up drawn as.
TerminalStyle
How a Terminal is drawn.
TtyStream
One attached program: the bytes it writes, and the handle to write back to it.

Enums§

ColorScheme
Which way round a terminal’s own colors run.

Constants§

DEFAULT_SCROLLBACK
Lines of scrollback a terminal keeps by default.

Traits§

Tty
The program behind a terminal: somewhere to send keystrokes, and a grid size to keep it informed of.

Functions§

cell_size
The advance and line height of a monospace font, which is what a terminal cell is.

Type Aliases§

Result
The result of anything that talks to the emulator or to the program behind it.