To modify the text or move the cursor, call input.handle(request). This method returns an InputResponse (which is Option<StateChanged>).
If the response is Some(StateChanged), the value field indicates if the text content changed, and the cursor field indicates if the cursor position changed. This allows you to efficiently decide whether to re-render your TUI.
Available InputRequests
SetCursor(usize): Move cursor to a specific codepoint.InsertChar(char): Insert a character at the cursor.GoToPrevChar / GoToNextChar: Move cursor by one grapheme.GoToPrevWord / GoToNextWord: Move cursor by one word boundary.GoToStart / GoToEnd: Jump to the beginning or end of the string.DeletePrevChar / DeleteNextChar: Delete one grapheme.DeletePrevWord / DeleteNextWord: Delete one word.DeleteLine: Deletes the entire line and adds it to the yank buffer.DeleteTillEnd: Deletes from the cursor to the end of the line.DeleteFromStart: Deletes from the start of the line to the cursor.Yank: Pastes the contents of the internal yank buffer at the cursor.
use tui_input::{Input, InputRequest, StateChanged};
let mut input: Input = "Hello Worl".into();
let req = InputRequest::InsertChar('d');
let resp = input.handle(req);
// resp is Some(StateChanged { value: true, cursor: true })
assert_eq!(resp, Some(StateChanged { value: true, cursor: true }));
assert_eq!(input.cursor(), 11);
assert_eq!(input.value(), "Hello World");