Promkit: A Rust toolkit for building interactive command-line tools

promkit

A toolkit for building your own interactive command-line tools in Rust, utilizing crossterm.

Getting Started

Put the package in your Cargo.toml.

[dependencies]
version = "0.1.2"

Features

  • Applications
    • Readline: provide the lines to receive and display user inputs
      • Masking
      • Switch insert/overwrite modes
      • Suggestions
    • Select: provide the selectbox to choose the items from
      • Move cyclically in the selectbox
  • Customizations
    • Edit key-bindings
    • Edit crossterm Event handler
    • Define your own command-line applications

Examples

Readline:

readline

use promkit::{build::Builder, readline, Result};

fn main() -> Result<()> {
    let mut p = readline::Builder::default().build()?;
    loop {
        let line = p.run()?;
        println!("result: {:?}", line);
    }
}

Select:

select

use promkit::{
    build::Builder, crossterm::style, register::Register, select, selectbox::SelectBox, Result,
};

fn main() -> Result<()> {
    let mut selectbox = Box::new(SelectBox::default());
    selectbox.register_all((0..100).map(|v| v.to_string()).collect::<Vec<String>>());
    let mut p = select::Builder::default()
        .title("Q: What number do you like?")
        .title_color(style::Color::DarkGreen)
        .selectbox(selectbox)
        .build()?;
    let line = p.run()?;
    println!("result: {:?}", line);
    Ok(())
}

.gitignore

/target
Cargo.lock

Cargo.toml

[package]
name = "promkit"
version = "0.1.2"
authors = ["ynqa <un.pensiero.vano@gmail.com>"]
edition = "2018"
description = "A toolkit for building your own interactive command-line tools"
repository = "https://github.com/ynqa/promkit"
license = "MIT"
readme = "README.md"

[[bin]]
name = "debug_cursor"
path = "debugs/cursor.rs"

[lib]
name = "promkit"
path = "src/lib.rs"

[dependencies]
crossterm = "0.23.0"
downcast-rs = "1.2.0"
radix_trie = "0.2.1"
scopeguard = "1.1.0"
unicode-width = "0.1.8"

[dev-dependencies]
strip-ansi-escapes = "0.1.1"

[[example]]
name = "custom_event_handler"
path = "examples/advanced/custom_event_handler.rs"

[[example]]
name = "custom_input_handler"
path = "examples/advanced/custom_input_handler.rs"

[[example]]
name = "custom_keybind"
path = "examples/advanced/custom_keybind.rs"

[[example]]
name = "label"
path = "examples/readline/label.rs"

[[example]]
name = "limit_history_size"
path = "examples/readline/limit_history_size.rs"

[[example]]
name = "masking"
path = "examples/readline/masking.rs"

[[example]]
name = "num_lines"
path = "examples/readline/num_lines.rs"

[[example]]
name = "overwrite"
path = "examples/readline/overwrite.rs"

[[example]]
name = "readline"
path = "examples/readline/readline.rs"

[[example]]
name = "suggest"
path = "examples/readline/suggest.rs"

[[example]]
name = "title"
path = "examples/readline/title.rs"

[[example]]
name = "init_down"
path = "examples/select/init_down.rs"

[[example]]
name = "select"
path = "examples/select/select.rs"

[[example]]
name = "window"
path = "examples/select/window.rs"

Download details:

Author: ynqa
Source: https://github.com/ynqa/promkit

License: MIT license

#rust 

Promkit: A Rust toolkit for building interactive command-line tools
1.10 GEEK