#repl #building #block #history #build #read-eval-print-loop #read-eval-print-loops

repl-block

A crossterm-based library for building Read-Eval-Print-Loops (REPLs)

11 releases (7 breaking)

0.10.0 Aug 11, 2024
0.9.0 Jun 5, 2024
0.8.0 Jun 5, 2024

#572 in Filesystem

Download history 185/week @ 2024-05-09 180/week @ 2024-05-16 380/week @ 2024-05-23 274/week @ 2024-05-30 94/week @ 2024-06-06 4/week @ 2024-06-13 4/week @ 2024-07-25 103/week @ 2024-08-08 16/week @ 2024-08-15

119 downloads per month

MIT/Apache

65KB
1.5K SLoC

repl-block

crates.io Documentation Rust

Synopsis

This crate provides a simple and easy way to build a Read-Eval-Print-Loop, a.k.a. REPL.

Usage

Add a dependency on this crate to your project's Cargo.toml:

[dependencies]
repl-block= "0.9.0"

Then one can use the ReplBuilder type to build an start a REPL like this:

use repl_block::prelude::{ReplBuilder, ReplBlockResult, Utf8PathBuf};

fn main() -> ReplBlockResult<()> {
    let mut evaluator = /* initialize your evaluator */;
    let path = Utf8PathBuf::try_from(env::current_dir()?)?.join(".repl.history");
    ReplBuilder::default()
        // Explicitly register .repl.history as the history file:
        .history_filepath(path)
        // Register the evaluator; the default evaluator fn is NOP
        .evaluator(|query: &str| {
            match evaluator.evaluate(query) {
                Ok(value) => println!("{value}"),
                Err(err)  => println!("{err}"),
            }
            Ok(())
        })
        .build()? // Use `self` to build a REPL
        .start()?;
    Ok(())
}

Dependencies

~6–17MB
~236K SLoC