#terminal-input #terminal #cli-input #input #cli

cool-rust-input

Cross platform customizable multiline input

12 stable releases (4 major)

7.0.0 Mar 14, 2025
6.2.0 Jan 6, 2025
5.0.2 Jan 2, 2025
5.0.0 Dec 31, 2024
3.3.1 Dec 29, 2024

#991 in Command line utilities

Download history 481/week @ 2024-12-25 484/week @ 2025-01-01 29/week @ 2025-01-08 2/week @ 2025-01-15 10/week @ 2025-02-05 7/week @ 2025-02-12 7/week @ 2025-02-19 4/week @ 2025-02-26 137/week @ 2025-03-12 7/week @ 2025-03-19

151 downloads per month

MIT license

25KB
526 lines

cool-rust-input

image

an input crate for fine control over each key press and rendering of text. by default allows multiline input, but custom behaviour can be added to make enter submit.

cross platform, tested on windows 11, arch and termux.

basic code sample

use cool_rust_input::{CoolInput, DefaultInputHandler};

fn main() -> Result<(), std::io::Error> {
    let mut my_input = CoolInput::new(DefaultInputHandler, 0);
    my_input.listen()?;
    Ok(())
}

custom handler sample

use cool_rust_input::{
    set_terminal_line, CoolInput, CustomInputHandler, HandlerContext, InputTransform,
};
use crossterm::{
    queue,
    style::{Color, SetForegroundColor},
};
use std::io::stdout;

struct MyHandler;
impl CustomInputHandler for MyHandler {
    fn get_input_transform(&mut self, ctx: HandlerContext) -> InputTransform {
        let size = (ctx.terminal_size.0 - 10, ctx.terminal_size.1 - 2);
        let offset = (5, 2);
        InputTransform { size, offset }
    }
    fn after_draw_text(&mut self, _: HandlerContext) {
        // we'll use this function to display a title text

        let _ = queue!(stdout(), SetForegroundColor(Color::Green));
        let _ = set_terminal_line("[MY COOL TEXT EDITOR PROGRAM]", 5, 0, true);
    }
}

fn main() -> Result<(), std::io::Error> {
    let mut my_input = CoolInput::new(MyHandler, 0);
    my_input.listen()?;
    Ok(())
}

todo:

  • markdown support (to some degree) (maybe)
  • pgdown/pgup
  • ctrl + left/right arrow

Dependencies

~3–11MB
~148K SLoC