5 releases (2 stable)

2.0.0 Nov 5, 2022
2.0.0-beta.1 Oct 22, 2022
1.0.0 Jul 31, 2022

#320 in Text editors

33 downloads per month
Used in tty-form

MIT license

24KB
487 lines

TTY Text

Crate Rust CI Rust CD

Provides agnostic text editing state management. Uses TTY Interface for rendering and TTY Form for forms.


lib.rs:

tty-text

Provides agnostic text editing state management.

Examples

For more examples, see [Text].

use tty_text::{Text, Key};

let mut text = Text::from("Hello,\nworld!", (1, 0), true);

// Move cursor from "e" to "w"
text.handle_input(Key::Down);
text.handle_input(Key::Down);
text.handle_input(Key::Left);

// Combine into single line, add " "
text.handle_input(Key::Backspace);
text.handle_input(Key::Char(' '));

// Add another "!"
text.set_cursor((13, 0));
text.handle_input(Key::Char('!'));

assert_eq!("Hello, world!!", text.value());
assert_eq!((14, 0), text.cursor());

Dependencies

~550KB