#repl #autocomplete #zsh

caprice

A Repl for Rust projects featuring an easy to use, zsh like autocomplete feature

2 releases

0.2.5 May 6, 2021
0.2.4 Mar 8, 2021
0.2.1 Feb 23, 2020
0.1.0 Jan 5, 2020
0.0.1 Aug 8, 2019

#71 in Command-line interface

Download history 4/week @ 2021-02-27 51/week @ 2021-03-06 4/week @ 2021-03-13 17/week @ 2021-03-20 7/week @ 2021-03-27 9/week @ 2021-04-03 10/week @ 2021-04-10 27/week @ 2021-04-17 3/week @ 2021-04-24 21/week @ 2021-05-01 3/week @ 2021-05-08 8/week @ 2021-05-15 1/week @ 2021-05-22 8/week @ 2021-06-05

57 downloads per month

MIT license

380KB
857 lines

caprice is a work in progress REPL for Rust projects featuring an easy to use, zsh like autocomplete feature.

using caprice with the spinning square example from Piston

Usage

  • typing /list will print all available tokens in the caprice console in alphabetical order
  • pressing tab will cycle between all autocompleted suggestions

caprice uses crossterm as its terminal emulator.

Example:

use caprice::{Caprice, CapriceCommand};
use std::thread;
use std::time::Duration;
fn main() {
    let mut caprice = Caprice::new()
        .set_prompt("!:") // set the prompt
        .disable_ctrl_c() // pressing control + c won't close the caprice console
        .set_keywords(&[  // set some tokens
            "some_token".to_owned(),
            "some_other_token".to_owned(),
            "exit".to_owned(), // an exit keyword
        ])
        .init(); // initialises the caprice terminal
    // caprice.run() will run the caprice in a separate thread.
    // you can use the returned tx and rx channels for receiving and sending messages
    // to caprice instance
    let (tx, rx, caprice_handle) = caprice.run().unwrap();
    // our main application runs here
    // for this example we will simply print back
    // the tokens send by caprice
    loop {
        // if we received a token from caprice
        if let Ok(token) = rx.try_recv() {
            match token.as_str() {
                // leave if the user types exit
                "exit" => {
                    tx.send(CapriceCommand::Println("bye".to_owned())).unwrap();
                    tx.send(CapriceCommand::Exit).unwrap();
                    caprice_handle.join().expect("couldn't join thread").expect("Caprice run has encountered an error");
                    break; // at this point caprice has already exited, let the main process do as well
                },
                // else send back the token to be printed
                _ => {
                    let print_token = format!("Got {} from Caprice", token);
                    tx.send(CapriceCommand::Println(print_token)).unwrap();
                }
            }
        }
        // let the thread sleep for some time
        thread::sleep(Duration::from_millis(10));
    }
}

Releases

Release info and changelogs can be found here

Dependencies

~0.7–1MB
~20K SLoC