term.rs: prevent clear_last_lines from deleting input below the cursor#121
Open
grunweg wants to merge 5 commits intoconsole-rs:mainfrom
Open
term.rs: prevent clear_last_lines from deleting input below the cursor#121grunweg wants to merge 5 commits intoconsole-rs:mainfrom
grunweg wants to merge 5 commits intoconsole-rs:mainfrom
Conversation
Contributor
Author
|
(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.) |
Collaborator
|
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.
Contributor
Author
|
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
Contributor
Author
|
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now, when
clear_last_linesis called with a valuenthat is larger than the number of lines before the current cursor position, the topnlines 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
mlines above the current cursor and clear_last_lines is called with argumentn>m, we could:n-mlines (doing nothing if possible), then clearing the topnlines. In effect, that's the current behaviour.mlines. (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.