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.13"
# For micro:bit support
[]
= { = "0.0.13", = ["microbit"], = false }
Basic REPL Example
use StdioTerminal;
use LineEditor;
Custom Terminal Implementation
Implement the Terminal trait for your platform:
use ;
use io;
Running the Examples
Standard Terminal (Linux/Windows/macOS)
Embedded micro:bit Example
For embedded targets, you need to:
- Build with
--no-default-featuresto disable thestdfeature - Provide the appropriate target and build configuration
For convenience when developing embedded applications, create a .cargo/config.toml in your project:
[]
= "probe-rs run --chip nRF52833_xxAA"
= ["-C", "link-arg=-Tlink.x"]
[]
= "thumbv7em-none-eabihf"
[]
= ["core", "alloc"]
Then use editline in your Cargo.toml:
[]
= { = "0.0.13", = false }
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
- Ctrl-D to exit (EOF)
- Ctrl-C to interrupt current line (continues REPL)
Platform Support
Supported Platforms
- Linux/Unix: Uses termios for raw mode and ANSI escape sequences for cursor control
- Windows: Uses Windows Console API for native terminal control
- micro:bit v2: UART-based terminal with proper line endings (CRLF) for serial terminals
Platform-Specific Behavior
Line Endings:
- Unix/Linux/macOS:
\n(LF) - micro:bit (serial terminals):
\r\n(CRLF)
The library automatically handles platform-specific line endings through conditional compilation.
Building for Different Platforms
Desktop (Linux/Windows/macOS):
micro:bit v2:
# Requires nightly toolchain for build-std
# With probe-rs runner configured:
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.