#repl #clap #interpreter #syntax-highlighting

reedline-repl-rs

Library to generate a fancy REPL for your application based on reedline and clap

19 releases (11 stable)

1.2.1 Aug 1, 2024
1.1.1 Apr 1, 2024
1.1.0 Mar 2, 2024
1.0.7 Jul 31, 2023
0.3.2 Jun 8, 2022

#237 in Command-line interface

Download history 457/week @ 2024-08-10 411/week @ 2024-08-17 576/week @ 2024-08-24 655/week @ 2024-08-31 479/week @ 2024-09-07 460/week @ 2024-09-14 523/week @ 2024-09-21 488/week @ 2024-09-28 631/week @ 2024-10-05 886/week @ 2024-10-12 576/week @ 2024-10-19 521/week @ 2024-10-26 559/week @ 2024-11-02 655/week @ 2024-11-09 1087/week @ 2024-11-16 689/week @ 2024-11-23

3,063 downloads per month
Used in 6 crates

MIT license

52KB
940 lines

reedline-repl-rs

Library to help you create a fancy REPL for your application based on nushell's reedline.

License: MIT Crates.io Documentation

Features:

  • Popular clap crate Command used as configuration interface
  • Also supports clap-derive based configuration with feature flag, see derive examples
  • General editing functionality, that should feel familiar coming from other shells (e.g. bash, fish, zsh).
  • Interactive tab-completion with graphical selection menu
  • Fish-style history autosuggestion hints
  • History with interactive search options (optionally persists to file, can support multiple sessions accessing the same file)
  • Configurable keybindings (default emacs-style bindings).
  • Configurable prompt with hooks to update after commands run
  • Command Syntax highlighting
  • Feature-flag for async support
  • Feature-flag shlex for optional POSIX compliant line splitting
  • Tip: Search history with CTRL+R, clear input with CTRL+C, exit repl with CTRL+D

Basic example code:

//! Minimal example
use reedline_repl_rs::clap::{Arg, ArgMatches, Command};
use reedline_repl_rs::{Repl, Result};

/// Write "Hello" with given name
fn hello<T>(args: ArgMatches, _context: &mut T) -> Result<Option<String>> {
    Ok(Some(format!(
        "Hello, {}",
        args.get_one::<String>("who").unwrap()
    )))
}

fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .with_banner("Welcome to MyApp")
        .with_command(
            Command::new("hello")
                .arg(Arg::new("who").required(true))
                .about("Greetings!"),
            hello,
        );
    repl.run()
}

Running the example above:

Colored Terminal Output

Welcome to MyApp
MyApp〉help
MyApp v0.1.0: My very cool app

COMMANDS:
    hello    Greetings!
    help     Print this message or the help of the given subcommand(s)

MyApp〉help hello
hello
Greetings!

USAGE:
    hello <who>

ARGS:
    <who>

OPTIONS:
    -h, --help    Print help information
MyApp〉hello Friend
Hello, Friend
MyApp〉

Testing

cargo test --features async

Will run the doc tests (compiling the examples). Notice, the examples/async.rs requires the async feature.

Thanks

Forked from repl-rs by Jacklund, changed to use reedline which is an advanced readline clone and the base of nushell.

Dependencies

~10–20MB
~294K SLoC