Repository: wezterm/wezterm (language: rust)

Issue:
termwiz: support horizontal mouse scroll events
It would be great if termwiz supported horizontal mouse scroll events.

Right now as far as I can tell these events aren't parsed at all, and some zellij users are seeing them output in their terminals: https://github.com/zellij-org/zellij/issues/1716.

I'd be happy to try and come up with a PR for this.


Discussion / hints:
I'd gladly accept a PR for this!

Fix patch:
diff --git a/termwiz/src/escape/csi.rs b/termwiz/src/escape/csi.rs
index 7573a5ee86c..2cab8552526 100644
--- a/termwiz/src/escape/csi.rs
+++ b/termwiz/src/escape/csi.rs
@@ -408,11 +408,15 @@ pub enum MouseButton {
     Button3Press,
     Button4Press,
     Button5Press,
+    Button6Press,
+    Button7Press,
     Button1Release,
     Button2Release,
     Button3Release,
     Button4Release,
     Button5Release,
+    Button6Release,
+    Button7Release,
     Button1Drag,
     Button2Drag,
     Button3Drag,
@@ -427,6 +431,8 @@ impl From<MouseButton> for MouseButtons {
             MouseButton::Button3Press | MouseButton::Button3Drag => MouseButtons::RIGHT,
             MouseButton::Button4Press => MouseButtons::VERT_WHEEL | MouseButtons::WHEEL_POSITIVE,
             MouseButton::Button5Press => MouseButtons::VERT_WHEEL,
+            MouseButton::Button6Press => MouseButtons::HORZ_WHEEL | MouseButtons::WHEEL_POSITIVE,
+            MouseButton::Button7Press => MouseButtons::HORZ_WHEEL,
             _ => MouseButtons::NONE,
         }
     }
@@ -605,6 +611,8 @@ impl Display for MouseReport {
                     MouseButton::Button3Press | MouseButton::Button3Release => 2,
                     MouseButton::Button4Press | MouseButton::Button4Release => 64,
                     MouseButton::Button5Press | MouseButton::Button5Release => 65,
+                    MouseButton::Button6Press | MouseButton::Button6Release => 66,
+                    MouseButton::Button7Press | MouseButton::Button7Release => 67,
                     MouseButton::Button1Drag => 32,
                     MouseButton::Button2Drag => 33,
                     MouseButton::Button3Drag => 34,
@@ -646,6 +654,8 @@ impl Display for MouseReport {
                     MouseButton::Button3Press | MouseButton::Button3Release => 2,
                     MouseButton::Button4Press | MouseButton::Button4Release => 64,
                     MouseButton::Button5Press | MouseButton::Button5Release => 65,
+                    MouseButton::Button6Press | MouseButton::Button6Release => 66,
+                    MouseButton::Button7Press | MouseButton::Button7Release => 67,
                     MouseButton::Button1Drag => 32,
                     MouseButton::Button2Drag => 33,
                     MouseButton::Button3Drag => 34,
@@ -2200,6 +2210,10 @@ impl<'a> CSIParser<'a> {
             ('m', 64) => MouseButton::Button4Release,
             ('M', 65) => MouseButton::Button5Press,
             ('m', 65) => MouseButton::Button5Release,
+            ('M', 66) => MouseButton::Button6Press,
+            ('m', 66) => MouseButton::Button6Release,
+            ('M', 67) => MouseButton::Button7Press,
+            ('m', 67) => MouseButton::Button7Release,
             ('M', 32) => MouseButton::Button1Drag,
             ('M', 33) => MouseButton::Button2Drag,
             ('M', 34) => MouseButton::Button3Drag,
diff --git a/termwiz/src/input.rs b/termwiz/src/input.rs
index 9a00edf026c..79473e8971f 100644
--- a/termwiz/src/input.rs
+++ b/termwiz/src/input.rs
@@ -2031,4 +2031,30 @@ mod test {
 
         assert_eq!(vec![InputEvent::Paste("12345678".to_owned())], inputs)
     }
+
+    #[test]
+    fn mouse_horizontal_scroll() {
+        let mut p = InputParser::new();
+
+        let input = b"\x1b[<66;42;12M\x1b[<67;42;12M";
+        let res = p.parse_as_vec(input);
+
+        assert_eq!(
+            vec![
+                InputEvent::Mouse(MouseEvent {
+                    x: 42,
+                    y: 12,
+                    mouse_buttons: MouseButtons::HORZ_WHEEL | MouseButtons::WHEEL_POSITIVE,
+                    modifiers: Modifiers::NONE,
+                }),
+                InputEvent::Mouse(MouseEvent {
+                    x: 42,
+                    y: 12,
+                    mouse_buttons: MouseButtons::HORZ_WHEEL,
+                    modifiers: Modifiers::NONE,
+                })
+            ],
+            res
+        );
+    }
 }


Test patch: