-
Notifications
You must be signed in to change notification settings - Fork 116
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
term.rs: prevent clear_last_lines from deleting input below the cursor #121
base: main
Are you sure you want to change the base?
Conversation
(I've seen the CI failures on windows. Will fix them if it's clear that this direction is worth taking; the code is a prototype anyway.) |
Please rebase. |
1315ceb
to
edc64e6
Compare
… too large argument.
The implementation is a proof-of-concept, and not fully polished yet.
Instead, check the number of rows above the cursor position, and error if passed a too large number.
Rebased and squashed commits down to three. Will fix the build on windows if I know the approach is useful. |
- Also parse multi-digit cursor positions correctly. - Clear the terminal after sending the code. - accept an u16, as terminal can be up to 65536 chars wide or long - just read a limited buffer, not an entire line; I can use a fixed-size buffer because of the above. - note two current FIXMEs in the code. - restrict this code to UNIX systems for now.
41e8d39
to
e96b5d7
Compare
I pushed another commit which cleans up the implementation (see commit message for details), along with the formatting. (The MSRV check fails as I'm currently using slice patters, which were only stabilised in Rust 1.48.0.) I've come to realise that my approach has two significant issues.
Hence, I see the options of
|
Right now, when
clear_last_lines
is called with a valuen
that is larger than the number of lines before the current cursor position, the topn
lines of the terminal are cleared. I would expect that all input below the cursor is left alone.I see several ways to solve this issue. When there are
m
lines above the current cursor and clear_last_lines is called with argumentn>m
, we could:n-m
lines (doing nothing if possible), then clearing the topn
lines. In effect, that's the current behaviour.m
lines. (Does this crate have a way of emitting a warning to the user? This could be an occasion to emit one; I suspect such code is not doing what the user intended.)This PR implements first option (1), documenting this limitation, and adds a proof-of-concept for option (3).
Options (2) and (3) require a way to query the cursor position (to find out how many lines are above the current one). Since this crate doesn't have a way to do so yet, this PR adds one (based on the corresponding ANSI sequence). That code is not complete or polished yet; I'm interested in feedback on the overall approach first.
Currently based in #119 (only last three commits are new); will rebase when that has landed.