5 releases (2 stable)

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

#309 in Text editors

Download history 3/week @ 2024-02-22 2/week @ 2024-02-29 6/week @ 2024-03-28 4/week @ 2024-04-04 63/week @ 2024-04-11 6/week @ 2024-04-18

79 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

~555KB