fix(grid): fix a problem that the default bottom line of the scrolling region (DECSTBM) is placed outside the terminal screen #3381
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.
Summary
When Zellij receives the control sequence
\e[1;r
(DECSTBM
with the parameter string1;
) from a terminal application, it uses "the terminal height" (self.height
) for the second parameter (which is supposed to be the bottom-line 1-based index of the scrolling region).zellij/zellij-server/src/panes/grid.rs
Line 1570 in c72f3a7
However, the internal index of the bottom line should be "(the terminal height) - 1" (
self.height - 1
) because the internal index is 0-based.Problem
What I expect: Suppose the current terminal height is N. I expect that the last N-lines in the output of the
seq
command remain in the terminal screen.Behavior in
main
: However, in the currentmain
branch of Zellij, the first N-lines in theseq
output remain in the terminal screen.This doesn't happen when the terminal height is directly specified to the parameter string of
DECSTBM
asbecause the index base is properly converted on the following line:
zellij/zellij-server/src/panes/grid.rs
Line 2733 in c72f3a7
cf In another location that sets the default scrolling region, the subtraction is properly performed:
zellij/zellij-server/src/panes/grid.rs
Lines 1579 to 1581 in c72f3a7
Note: The problem was found while investigating akinomyoga/ble.sh#450, (though this PR doesn't still fix the original problem).
Remarks
There should still be problems when the terminal window height is changed or when the terminal application explicitly specifies the bottom line to be outside the terminal window. However, solving them would require changing the internal representation of the scroll region, so I avoid performing the large change within this PR. I think they should be separately fixed if needed.