Reputation: 23
I'm currently writing a simple Notepad app in Rust. During the main loop, the user is asked to insert, delete, or change lines. When the user changes a line, I'd like to pre-fill the content of the line so that the user can edit a line easier.
Something like this (The underscore represents the terminal cursor. The user has not made any input after selecting the line):
Content:
1. Test
2. 123
Action(Change, Insert, Delete) --> C
Which line --> 2
--> 123_
I've found some crates that could help: Crossterm and Termion. Ncurses could help too, but I'd prefer not to use it.
Upvotes: 2
Views: 220
Reputation: 23244
If you don't want to use a full TUI crate like ratatui
or a lower-level "curses"-like terminal handling crate like termion
, you can still use rustyline
for basic input with line editing. Specifically for editing a pre-filled line, you would use readline_with_initial
:
let mut rl = rustyline::DefaultEditor::new()?;
let line = rl.readline_with_initial ("-->", ("123", ""))?;
Upvotes: 2