scansion

A readline-style library with Vim and Emacs keybindings

1 unstable release

0.0.1 Feb 1, 2024

Apache-2.0

1MB
27K SLoC

scansion

Build Status License: Apache 2.0 Latest Version Docs Status

About

This is a readline-style crate that includes support for Vim and Emacs keybindings.

Usage

This crate is on crates.io and can be used by adding scansion to your dependencies in your project's Cargo.toml.

[dependencies]
scansion = "0.0.1"

License

scansion is released under the Apache License, Version 2.0.


lib.rs:

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);
            },
        }
    }
}

Dependencies

~7–19MB
~272K SLoC