A modern terminal emulator written in Rust with both CPU and GPU rendering options and efficient event-driven architecture.
What will make Rustty different? Planned smooth pixel-level scrolling, similar to NeoVide. Unlike traditional terminal emulators that scroll by whole character lines, Rustty will enable buttery-smooth scrolling animations.
- β Smooth Pixel-Level Scrolling (Planned) - Unlike traditional terminals (1-line scroll resolution), Rustty will scroll smoothly at the pixel level, inspired by NeoVide
- β Full PTY Support - Runs your shell with proper pseudo-terminal integration
- β ANSI Escape Sequences - Full 256-color palette + RGB true color support
- β Alternate Screen Buffer - Full-screen apps (vim, less, htop) work correctly
- β Event-Driven Architecture - Dedicated reader thread for near-zero CPU usage when idle
- β Dynamic Grid Sizing - Terminal grid resizes with window, preserving content
- β Scrollback Buffer - 10,000 line scrollback history
- β Dual Rendering Options - Choose between CPU (Raqote) or GPU (wgpu) rendering
- β Keyboard Input - Full keyboard support including arrow keys, function keys, and Ctrl combinations
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β Main Thread β
β ββββββββββββββ ββββββββββββ βββββββββββββββ β
β β Window β β Grid β β Parser β β
β β (winit) β β (80x24+) β β (VTE) β β
β ββββββββββββββ ββββββββββββ βββββββββββββββ β
β β β β β
β ββββββββββββββββ΄ββββββββββββββββ β
β β β
β ββββββΌββββββ β
β β Renderer β β
β β (Raqote) β β
β ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Channel (MPSC)
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β PTY Reader Thread β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β Blocking read on PTY master FD β β
β β Wakes on data β Sends to main thread β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β Shell Process (Child) β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β $SHELL (bash, zsh, fish, etc.) β β
β β Connected to PTY slave β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
Rustty is organized as a library + binary:
Library (src/lib.rs + src/terminal/):
- Pure terminal emulation with zero UI dependencies (~1500 lines)
- Exports:
Terminal,Shell,TerminalGrid,Cell,Color, etc. - Can be used to build custom terminal UIs
Binaries:
- CPU Binary (
src/bin/rustty.rs) - Default, uses Raqote + Softbuffer - GPU Binary (
src/bin/rustty_gpu.rs) - Hardware-accelerated, uses wgpu - Both import terminal types from library and handle window management
Terminal modules:
mod.rs- Terminal struct with VTE Perform implementationshell.rs- Shell process management + PTY + reader threadgrid.rs- Terminal grid data structure with scrollback buffercommand.rs- ANSI command enums (CsiCommand, SgrParameter, etc.)color.rs- Color representation and ANSI color palettecursor.rs- Cursor positioningstate.rs- Terminal state (pure data structure)
- Rust 1.80+ (Rust 2024 edition)
- Linux/Unix system with PTY support
- System libraries:
fontconfigfreetype
Rustty offers two rendering backends via Cargo feature flags:
CPU Renderer (rustty) - Default
- Uses Raqote for software rendering
- Better compatibility (works on all systems)
- Lower memory usage
- Good for general use
GPU Renderer (rustty-gpu)
- Uses wgpu for hardware-accelerated rendering
- Better performance on large windows
- Foundation for future smooth scrolling
- Requires GPU drivers
CPU Renderer (Default):
# Build CPU binary
cargo build --bin rustty
# Run CPU binary
cargo run --bin rustty
# Release build
cargo build --bin rustty --releaseGPU Renderer:
# Build GPU binary
cargo build --bin rustty-gpu --features ui-gpu
# Run GPU binary
cargo run --bin rustty-gpu --features ui-gpu
# Release build
cargo build --bin rustty-gpu --features ui-gpu --releaseBoth Binaries:
# Build both
cargo build --all-features
# Run tests
cargo testSimply run the terminal:
cargo runThe terminal will:
- Launch your default
$SHELL(or/bin/shas fallback) - Create an 800x600 window
- Automatically resize the grid when you resize the window
- Support full keyboard input and terminal output
The rustty library can be used to build custom terminal UIs:
use rustty::{Terminal, Shell};
fn main() -> anyhow::Result<()> {
// Create terminal and shell
let mut terminal = Terminal::new(80, 24);
let shell = Shell::new(80, 24)?;
// Process shell output
loop {
match shell.receiver.try_recv() {
Ok(data) => {
terminal.process_bytes(&data);
// Get terminal state for rendering
let viewport = terminal.state().grid.get_viewport();
// ... custom rendering logic
}
Err(_) => break,
}
}
Ok(())
}The library has zero UI dependencies - only PTY and ANSI parsing.
- Arrow Keys - Navigate (sends
\x1b[A/B/C/D) - Enter - Carriage return (
\r) - Backspace - Delete (
\x7f) - Tab - Tab completion (
\t) - Ctrl+C, Ctrl+D, etc. - Standard control codes
- Function Keys - Home, End, Page Up/Down, Insert, Delete
Rustty uses a dedicated reader thread for PTY I/O:
- Blocking reads in separate thread - sleeps when no data available
- Channel-based communication to main thread
- Near-zero CPU usage when terminal is idle
- Instant response when data arrives (no polling delay)
This is the same architecture used by production terminals like Alacritty and WezTerm.
- Idle CPU usage: < 0.1%
- Input latency: < 5ms
- Scrollback: 10,000 lines
- Grid resize: Preserves all content
Rustty includes comprehensive unit tests:
$ cargo testTest Coverage:
- β 53 passing tests
- Color module (11 tests)
- Grid module (18 tests)
- Parser module (11 tests)
- App module (13 tests)
- Dynamic sizing - Calculates optimal grid based on window dimensions
- Content preservation - Resizing doesn't lose terminal content
- Scrollback buffer - Configurable (default: 10,000 lines)
- Viewport management - Efficient rendering of visible region only
Implemented:
- β
Full 256-color palette (colors 0-255)
- Standard 16 colors (0-15)
- 6Γ6Γ6 RGB cube (16-231)
- Grayscale ramp (232-255)
- β
RGB true color (
ESC[38;2;R;G;Bm) - β Cursor movement (H, f, A, B, C, D)
- β Screen/line clearing (J, K)
- β SGR (Select Graphic Rendition)
- β
Alternate screen buffer (
ESC[?1049h/l)
Not Yet Implemented:
- β Text attribute rendering (bold, italic, underline are stored but not visually rendered)
- β Mouse support
PTY Output β VTE Parser β Terminal Grid β Raqote β Softbuffer β Window
- PTY Thread reads shell output (blocking)
- Channel transfers data to main thread
- VTE Parser interprets ANSI sequences
- Terminal Grid stores characters and attributes
- Raqote renders text to pixel buffer (CPU)
- Softbuffer presents buffer to window
For detailed information, see the following documentation:
- Terminal Fundamentals - Complete guide to how terminal emulators work (PTY, shells, file descriptors, Rustty architecture)
- ANSI Implementation - Complete reference of supported ANSI escape sequences
- Debugging Guide - How to debug and trace ANSI sequences
Test the 256-color palette support:
# Run inside Rustty terminal
./test-256-colors.sh- Full 256-color palette support β¨
- Alternate screen buffer β¨ NEW!
- Text attributes (bold, italic, underline, etc.)
- Cursor blinking animation
- Selection and clipboard support
- GPU rendering with wgpu β¨ NEW!
- Smooth pixel-level scrolling (inspired by NeoVide) - Will leverage GPU renderer
- Configuration file support
- Mouse support (SGR mouse mode)
- Ligature support
- Image rendering (sixel, iTerm2 protocol)
nix- Unix PTY and process managementvte- ANSI escape sequence parseranyhow- Error handling
winit- Cross-platform window creationfont-kit- Font loading and metrics
raqote- 2D graphics rendering (CPU-based)softbuffer- Software rendering backend
wgpu- WebGPU API for hardware-accelerated renderingpollster- Async executor for wgpu initializationbytemuck- Safe type casting for GPU bufferspathfinder_geometry- Geometric primitives for glyph rasterization
This project is open source and available under the MIT License.
- Inspired by Alacritty and WezTerm
- Uses the excellent VTE parser from the Alacritty project
- Built with the Rust 2024 edition
Status: Early development - functional but missing some features
