| Crates.io | rusty_repl |
| lib.rs | rusty_repl |
| version | 0.3.0 |
| created_at | 2025-10-12 00:19:59.79583+00 |
| updated_at | 2025-10-13 22:19:13.102531+00 |
| description | REPL library with customisable prompts and clean terminal management. |
| homepage | https://gitlab.com/amad3v/rusty-repl |
| repository | https://gitlab.com/amad3v/rusty-repl |
| max_upload_size | |
| id | 1878681 |
| size | 72,863 |
A lightweight, modular framework for building interactive REPLs in Rust โ with clean prompts, terminal isolation, and customisable input handling.
Prompt style via CleanPromptreedlineKeywordStyle)ReplConfig::new().with_title(...).with_prompt(...).with_kw_style(...)Add to your Cargo.toml:
[dependencies]
rusty_repl = "0.3.0"
Then in your project:
use rusty_repl::Repl;
fn input_handler(cmd: String) -> bool {
match cmd.as_str() {
"e" | "q" | "quit" | "exit" => {
return true;
}
val => println!("{val}"),
};
false
}
fn main() {
// Use default configuration
let repl_manager = Repl::new();
// Run REPL loop
let _ = repl_manager.run(run);
}
Or
use rusty_repl::{CleanPrompt, Color, DefaultPromptSegment, KeywordStyle, Repl, ReplConfig};
fn input_handler(cmd: String) -> bool {
match cmd.as_str() {
"e" | "q" | "quit" | "exit" => {
return true;
}
val => println!("{val}"),
};
false
}
fn main() {
// Configure keywords
let ks = KeywordStyle::new(
vec!["ls", "pwd", "cd", "e", "q", "quit", "exit"],
Color::Red,
);
// Configure prompt
let default_prompt = CleanPrompt::from(
DefaultPromptSegment::Basic("โฏโฏโฏ ".to_string()),
DefaultPromptSegment::Empty,
);
// Build REPL configuration
let cfg = ReplConfig::new("REPL")
.with_kw_style(ks)
.with_prompt(default_prompt);
let repl_manager = Repl::from(cfg);
// Run REPL loop
let _ = repl_manager.run(run);
}
This opens an alternate terminal screen with a minimal prompt.
Type exit to leave the session.
| Module | Responsibility |
|---|---|
repl::input |
Handles user input with reedline |
repl::terminal |
Manages terminal (alternate screen, cursor, cleanup) |
repl::prompt |
Defines a cleaner, customisable prompt |
repl::highlighter |
Highlights configured keywords during input |
repl::style |
Configures keyword styles (colors, word list) |
repl::repl |
Connects all components into a cohesive REPL session |
Licensed under the MIT License
ReplConfig builder with .with_title(), .with_prompt(), .with_kw_style()Arc<dyn Prompt> to avoid ownership/move issuesArc<ReplConfig> instead of cloning individual fieldsArc usageKeywordHighlighter for basic keyword-based styling.KeywordStyle as part of the public API.Repl::new to accept an optional KeywordStyle argument.