@@ -782,9 +782,13 @@ fn parse_cb(cb: u8) -> io::Result<(MouseEventKind, KeyModifiers)> {
782782 ( 0 , false ) => MouseEventKind :: Down ( MouseButton :: Left ) ,
783783 ( 1 , false ) => MouseEventKind :: Down ( MouseButton :: Middle ) ,
784784 ( 2 , false ) => MouseEventKind :: Down ( MouseButton :: Right ) ,
785+ ( 8 , false ) => MouseEventKind :: Down ( MouseButton :: X1 ) ,
786+ ( 9 , false ) => MouseEventKind :: Down ( MouseButton :: X2 ) ,
785787 ( 0 , true ) => MouseEventKind :: Drag ( MouseButton :: Left ) ,
786788 ( 1 , true ) => MouseEventKind :: Drag ( MouseButton :: Middle ) ,
787789 ( 2 , true ) => MouseEventKind :: Drag ( MouseButton :: Right ) ,
790+ ( 8 , true ) => MouseEventKind :: Drag ( MouseButton :: X1 ) ,
791+ ( 9 , true ) => MouseEventKind :: Drag ( MouseButton :: X2 ) ,
788792 ( 3 , false ) => MouseEventKind :: Up ( MouseButton :: Left ) ,
789793 ( 3 , true ) | ( 4 , true ) | ( 5 , true ) => MouseEventKind :: Moved ,
790794 ( 4 , false ) => MouseEventKind :: ScrollUp ,
@@ -1228,6 +1232,57 @@ mod tests {
12281232 ) ;
12291233 }
12301234
1235+ // X1/X2 (back/forward) buttons are encoded with bit 7 of Cb set,
1236+ // giving button numbers 8 and 9 instead of a parse error.
1237+ #[ test]
1238+ fn test_parse_csi_sgr_mouse_x1_x2_buttons ( ) {
1239+ assert_eq ! (
1240+ parse_csi_sgr_mouse( b"\x1B [<128;20;10M" ) . unwrap( ) ,
1241+ Some ( InternalEvent :: Event ( Event :: Mouse ( MouseEvent {
1242+ kind: MouseEventKind :: Down ( MouseButton :: X1 ) ,
1243+ column: 19 ,
1244+ row: 9 ,
1245+ modifiers: KeyModifiers :: empty( ) ,
1246+ } ) ) )
1247+ ) ;
1248+ assert_eq ! (
1249+ parse_csi_sgr_mouse( b"\x1B [<128;20;10m" ) . unwrap( ) ,
1250+ Some ( InternalEvent :: Event ( Event :: Mouse ( MouseEvent {
1251+ kind: MouseEventKind :: Up ( MouseButton :: X1 ) ,
1252+ column: 19 ,
1253+ row: 9 ,
1254+ modifiers: KeyModifiers :: empty( ) ,
1255+ } ) ) )
1256+ ) ;
1257+ assert_eq ! (
1258+ parse_csi_sgr_mouse( b"\x1B [<129;20;10M" ) . unwrap( ) ,
1259+ Some ( InternalEvent :: Event ( Event :: Mouse ( MouseEvent {
1260+ kind: MouseEventKind :: Down ( MouseButton :: X2 ) ,
1261+ column: 19 ,
1262+ row: 9 ,
1263+ modifiers: KeyModifiers :: empty( ) ,
1264+ } ) ) )
1265+ ) ;
1266+ assert_eq ! (
1267+ parse_csi_sgr_mouse( b"\x1B [<129;20;10m" ) . unwrap( ) ,
1268+ Some ( InternalEvent :: Event ( Event :: Mouse ( MouseEvent {
1269+ kind: MouseEventKind :: Up ( MouseButton :: X2 ) ,
1270+ column: 19 ,
1271+ row: 9 ,
1272+ modifiers: KeyModifiers :: empty( ) ,
1273+ } ) ) )
1274+ ) ;
1275+ assert_eq ! (
1276+ parse_csi_sgr_mouse( b"\x1B [<160;20;10M" ) . unwrap( ) ,
1277+ Some ( InternalEvent :: Event ( Event :: Mouse ( MouseEvent {
1278+ kind: MouseEventKind :: Drag ( MouseButton :: X1 ) ,
1279+ column: 19 ,
1280+ row: 9 ,
1281+ modifiers: KeyModifiers :: empty( ) ,
1282+ } ) ) )
1283+ ) ;
1284+ }
1285+
12311286 #[ test]
12321287 fn test_utf8 ( ) {
12331288 // https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805
0 commit comments