| Crates.io | input_handler |
| lib.rs | input_handler |
| version | 0.1.0 |
| created_at | 2025-08-28 14:30:57.763158+00 |
| updated_at | 2025-08-28 14:30:57.763158+00 |
| description | Reusable input handler module |
| homepage | |
| repository | https://github.com/Arshdeep54/input_handler |
| max_upload_size | |
| id | 1814183 |
| size | 18,220 |
A tiny, reusable input editor for Rust CLI apps. It provides readline-like terminal editing with in-memory and optional on-disk history, arrow-key navigation, backspace/delete handling, and sane defaults, without external C deps beyond libc/termios.
Editor and ergonomic wrapper InputHandlerAdd to your Cargo.toml:
[dependencies]
input_handler = "0.1"
use input_handler::InputHandler;
fn main() -> std::io::Result<()> {
let mut ih = InputHandler::new()?;
loop {
let line = ih.readline("app> ")?;
if line.trim() == "exit" { break; }
println!("you typed: {}", line);
}
Ok(())
}
use input_handler::InputHandler;
use std::path::PathBuf;
fn main() -> std::io::Result<()> {
let history_path = PathBuf::from("/tmp/.app_history");
let mut ih = InputHandler::with_history_file(history_path)?;
let line = ih.readline("app> ")?;
println!("{}", line);
Ok(())
}
^C"exit"Exports from the crate root:
Editor
new() -> io::Result<Editor>with_history_file(path: PathBuf) -> io::Result<Editor>readline(prompt: &str) -> io::Result<String>History
new(max_size: usize) -> Historywith_file(max_size: usize, path: PathBuf) -> Historyadd(command: String)previous() -> Option<&String> / next_command() -> Option<&String>InputHandler (light wrapper around Editor)
new() -> io::Result<InputHandler>with_history_file(path: PathBuf) -> io::Result<InputHandler>readline(prompt: &str) -> io::Result<String>Notes:
This crate uses termios and libc to enter raw mode and read keys. It targets Unix-like systems (Linux, macOS). Windows is not supported out of the box.
"exit" so you can exit loops easily; otherwise, it is ignored.MIT © Contributors
https://github.com/Arshdeep54/input_handler