editline
A platform-agnostic line editor library for Rust with full editing capabilities, command history, and cross-platform terminal support.
Overview
editline provides a powerful, flexible line editing library with a clean separation between I/O and editing logic. Unlike traditional readline implementations that are tightly coupled to specific terminal APIs, editline uses a trait-based design that works with any byte-stream I/O.
Perfect for:
- Desktop CLIs and REPLs
- Embedded systems (UART, custom displays)
- Network services (telnet/SSH servers)
- Custom terminal emulators
- Testing with mock I/O
Why editline?
- Platform-agnostic core - editing logic has zero I/O dependencies
- No global state - create multiple independent editors
- Type-safe - Rust enums and Result types throughout
- Memory-safe - no manual memory management
- Full-featured - history, word navigation, editing operations
- Cross-platform - Unix (termios/ANSI) and Windows (Console API) included
Features
- Full line editing: Insert, delete, cursor movement
- Word-aware navigation: Ctrl+Left/Right, Alt+Backspace, Ctrl+Delete
- Command history: 50-entry circular buffer with up/down navigation
- Smart history: Automatically skips duplicates and empty lines
- Cross-platform: Unix (termios/ANSI) and Windows (Console API)
- Zero global state: All state is explicitly managed
- Type-safe: Strong typing with Result-based error handling
Usage
Add to your Cargo.toml:
[]
= "0.0.2"
Basic REPL Example
use StdioTerminal;
use LineEditor;
Custom Terminal Implementation
Implement the Terminal trait for your platform:
use ;
use io;
Running the Example
Try these features:
- Arrow keys for cursor movement
- Home/End keys
- Up/Down for history
- Ctrl+Left/Right for word navigation
- Alt+Backspace to delete word left
- Ctrl+Delete to delete word right
Architecture
┌───────────────────────────────────────┐
│ LineEditor (lib.rs) │
│ ┌───────────┐ ┌──────────────────┐ │
│ │LineBuffer │ │ History │ │
│ │ │ │ (circular buffer)│ │
│ └───────────┘ └──────────────────┘ │
└──────────────────┬────────────────────┘
│ Terminal trait
┌──────────┴──────────┐
│ │
┌───────▼────────┐ ┌────────▼─────────┐
│ Unix Terminal │ │ Windows Terminal │
│ (termios/ANSI) │ │ (Console API) │
└────────────────┘ └──────────────────┘
Contributing
Contributions are welcome! Areas for enhancement:
- Tab completion callback hooks
- Multi-line editing support
- Syntax highlighting callbacks
- Additional platform implementations
- More comprehensive tests
License
Licensed under either of:
at your option.