Rustyline

A readline/line-editing library for building interactive Rust REPLs and CLI shells

Library
Cargo
v18.0.1
1,918stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity88
Maintenance80
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality82
Innovation65
Learning Curve78

Rustyline is a Rust implementation of readline-style line editing, based on Antirez’s Linenoise, that gives command-line applications features like history, cursor movement, kill-ring cut/paste, tab completion, and syntax highlighting for interactive input. It’s the library most Rust REPLs and interactive shells reach for instead of hand-rolling terminal input handling.

The crate works cross-platform (Unix terminals and Windows console/PowerShell) and exposes an Editor type that applications configure with pluggable Completer, Highlighter, Hinter, and Validator traits, plus optional history persistence to a plain file or a SQLite-backed history store via the sqlite_history feature. A companion rustyline-derive crate provides derive macros for composing these traits onto a single custom helper type.

What You Get

  • An Editor type providing line editing with history, kill-ring cut/paste, and both emacs- and vi-style keybindings
  • Pluggable Completer, Highlighter, Hinter, and Validator traits for tab completion, syntax highlighting, inline hints, and multi-line input validation
  • Cross-platform terminal support for Unix (Linux, macOS, FreeBSD) and Windows (cmd.exe, PowerShell)
  • History persistence to a plain text file by default, or to SQLite via the with-sqlite-history feature
  • The rustyline-derive companion crate for deriving the helper traits on a single custom type

Common Use Cases

  • Building an interactive REPL for a programming language, database client, or scripting tool
  • Adding tab-completion and command history to a custom interactive CLI shell
  • Providing syntax-highlighted input for a domain-specific interactive query tool
  • Persisting and recalling command history across sessions in a terminal application

Under The Hood

Architecture - The crate centers on edit.rs (the core line-editing state machine) and keymap.rs/command.rs (translating keypresses into editing commands under emacs or vi modes), backed by a tty module abstracting Unix termios and Windows console APIs behind a common interface. Extension points (completion.rs, highlight.rs, hint.rs, validate.rs) define traits that consuming applications implement to customize behavior, while history.rs/sqlite_history.rs handle persisting and recalling past input.

Tech Stack - Pure Rust (edition 2024) with platform-specific dependencies gated by cfg(unix)/cfg(windows)nix for Unix terminal control, and Windows console APIs on that platform — plus unicode-width/unicode-segmentation for correct cursor movement over multi-byte and combining characters, and an optional rusqlite (bundled) dependency for SQLite-backed history. The workspace also includes rustyline-derive, a small proc-macro crate for deriving the helper traits.

Code Quality - Tests are organized in a dedicated src/test module covering emacs and vi keybinding behavior (emacs.rs, vi_cmd.rs, vi_insert.rs) plus history handling, with 22 files across the crate containing #[test] blocks — a meaningful investment in behavioral coverage for something as fiddly as terminal input handling. The deny.toml config and CI badge (maintenance = actively-developed) signal an active dependency-auditing and maintenance practice.

API Design - The DefaultEditor::new() entry point requires zero configuration for the common case, while power users compose custom completion/highlighting/hinting/validation behavior by implementing a handful of well-scoped traits on a single helper struct (optionally derived via rustyline-derive), keeping the common path simple without boxing out advanced customization.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search