rustne-kretser / noline

IO-agnostic line editor for embedded systems
Mozilla Public License 2.0
96 stars 9 forks source link

feat: add `reinit` to editors to handle resizing #35

Open sethp opened 1 week ago

sethp commented 1 week ago

When the terminal connected to the noline Editor is resized, we need a mechanism to update the internal Terminal state so that it matches the new size & cursor position.

At this snapshot, both the sync & async Editors have grown a reinit function that re-probes the terminal environment to ensure these data line up.

One possible pattern for managing resync is to do so after every line is read, so that an operator who has resized their terminal can hit "enter" to get the terminals' states to line back up (similar to how many shells commonly appear to function):

while let Ok(line) = {
            editor.reinit(&mut io).unwrap(); // On every newline, re-initialize the cursor/terminal state

            editor.readline(prompt, &mut io)
        } {
    // Do something with line...
}
eivindbergem commented 1 week ago

Thanks! This looks good. Can you add a test?