#editor #text-editing #text #user-input #cli-applications #xvrqt

scrawl

Opens a user's preferred text editor so they can edit data inline and returns a Read-able struct for interactive CLI applications

10 releases (3 stable)

2.0.0 Feb 2, 2023
1.1.0 Dec 5, 2019
1.0.0 Jul 30, 2019
0.9.0 Jul 27, 2019
0.1.5 Jul 27, 2019

#134 in Text editors

Download history 168/week @ 2024-03-11 80/week @ 2024-03-18 74/week @ 2024-03-25 136/week @ 2024-04-01 67/week @ 2024-04-08 104/week @ 2024-04-15 82/week @ 2024-04-22 119/week @ 2024-04-29 60/week @ 2024-05-06 83/week @ 2024-05-13 75/week @ 2024-05-20 223/week @ 2024-05-27 121/week @ 2024-06-03 58/week @ 2024-06-10 55/week @ 2024-06-17 45/week @ 2024-06-24

308 downloads per month
Used in 5 crates

BSD-3-Clause

16KB
223 lines

Scrawl

Rust library that opens a user's text editor and returns the results as a string. Can be used to open and edit exisiting files, or just as a scratch space for input. Useful for having a user edit text inline with a CLI program a la git commit -m

Quick Start

use scrawl;

fn main() {
    // Open an empty buffer with the user's preferred text editor
    let output = scrawl::new()?;
    println!("User Input: {}", output.to_string());

    // Open a buffer with contents in the text editor
    let output = scrawl::with(&"Favorite color: ")?;
    println!("{}", output.to_string());

    // Open a buffer with text from a file in the text editor
    let output = scrawl::from_file(&"survey.txt")?;
    println!("{}", output.to_string());

    // Open a file for direct editing in the text editor
    scrawl::edit_file(&"README.md")?;
}

Editor Struct

The Editor struct allows you to set certain options before opening the editor. Such as: which editor to open, which arguments to pass to that editor, which file extension to use when editing (provides editors with syntax highlight hints).

use scrawl::{editor, Contents};

fn main() -> Result<(), error::ScrawlError> {
    let output = editor::new()
                        .editor("vim")
                        .args("--clean")
                        .ext(".rs)
                        .open(Contents::FromFile(&"foo.txt"))?;
}

No runtime deps