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

fix(grid): fix a problem that the default bottom line of the scrolling region (DECSTBM) is placed outside the terminal screen #3381

Merged
merged 1 commit into from
May 27, 2024

Conversation

akinomyoga
Copy link
Contributor

Summary

When Zellij receives the control sequence \e[1;r (DECSTBM with the parameter string 1;) 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).

let bottom_line_index = bottom_line_index.unwrap_or(self.height);

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

  • Steps to reproduce: See the following reduced case. You can run the command inside Zellij.
$ printf '\e[1;r'; seq 999; printf '\e[r'
  • 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 current main branch of Zellij, the first N-lines in the seq output remain in the terminal screen.

This doesn't happen when the terminal height is directly specified to the parameter string of DECSTBM as

$ printf '\e[1;%dr' "$LINES"; seq 999; printf '\e[r'

because the index base is properly converted on the following line:

.map(|bottom| bottom.saturating_sub(1));

cf In another location that sets the default scrolling region, the subtraction is properly performed:

pub fn set_scroll_region_to_viewport_size(&mut self) {
self.scroll_region = Some((0, self.height.saturating_sub(1)));
}

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.

@imsnif
Copy link
Member

imsnif commented May 27, 2024

Thanks for this - good catch!

I agree the internal representation of the scrolling region needs to change (specifically it shouldn't be an Option), and I also agree it's out of scope here.

@imsnif imsnif merged commit 5f5d6df into zellij-org:main May 27, 2024
6 checks passed
@akinomyoga akinomyoga deleted the stbm-out-of-bound branch May 27, 2024 15:37
@akinomyoga
Copy link
Contributor Author

Thanks!

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