Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reinit to editors to handle resizing #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sethp
Copy link

@sethp sethp commented Oct 12, 2024

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...
}

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):

```rust
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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants