Support MouseScrollLeft and MouseScrollRight control sequences. #5995
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.
Background
Horizontal scrolling is useful in certain scenarios, such as browsing a
DataTable
with many rows and columns or moving around in a map in all four directions. Since most input devices do not have a dedicated horizontal scroll wheel, most terminal emulators only send control sequences for vertical (but not horizontal) scroll. Textual performs horizontal scrolling when a vertical scroll sequence is received with the CTRL or SHIFT key pressed; see source code.Some terminal emulators do send a specific control sequence on horizontal mouse scrolling. For example, iTerm2 sends
^[[66;x;yM
for scroll-left and^[[67;x;yM
for scroll-right, withx
andy
replaced by the cursor coordinates. These control codes are left unspecified under xterm when the mouse wheel is in action. Most terminal emulators, such as Windows Terminal or MacOS Terminal, do not send these codes.At the moment, Textual ignores the second lowest bit of the control code when the mouse wheel is in action. Consequently, for a terminal emulator that sends
66
or67
, scroll-left (66
) is treated as scroll-up (64
) and scroll-right (67
) is treated as scroll-down (65
); see source code.Change
This PR adds support for control codes
66
and67
. When these control codes are received and the mouse wheel is in action, theMouseScrollLeft
orMouseScrollRight
event is sent accordingly. These events are then handled by scrollable containers to perform horizontal scrolling.Checklist
Updated CHANGELOG.md(skipped -- probably better to update at release time)Demo
The following script creates a
DataTable
with many rows and columns. Run the script under iTerm2 (MacOS only) and "scroll" the Magic Mouse in all four directions to have the DataTable scroll accordingly.