Crate scansion

Source
Expand description

§Readline-style editor

§Overview

This module provides a readline-style editor for getting user input. It is meant to work with any BindingMachine implementor that maps input to an Action.

§Example

use modalkit::{
    env::vim::keybindings::{VimBindings, VimMachine},
    keybindings::InputBindings,
    key::TerminalKey,
};
use scansion::{ReadLine, ReadLineInfo};

fn main() -> Result<(), std::io::Error> {
    let mut vi = VimMachine::<TerminalKey, ReadLineInfo>::empty();
    VimBindings::default().submit_on_enter().setup(&mut vi);

    let mut rl = ReadLine::new(vi)?;

    loop {
        match rl.readline(Some("> ".to_string())) {
            Ok(s) => match s.trim() {
                "q" | "quit" => {
                    return Ok(());
                },
                _ => {
                    println!("User typed: {:?}", s);
                }
            },
            Err(e) => {
                // Print out editor error messages.
                println!("{}", e);
            },
        }
    }
}

Structs§

ReadLine
Simple editor for collecting user input.

Enums§

ReadLineError
Error type for ReadLine editor.
ReadLineId
Identifiers for the buffers used by ReadLine.
ReadLineInfo
Default ApplicationInfo used by ReadLine.

Type Aliases§

ReadLineResult
Result type when using ReadLine::readline.