Skip to content

Commit 328f3b9

Browse files
committed
feat(tui): horizontal mouse scrolling
Signed-off-by: Ali Caglayan <[email protected]>
1 parent 6cd8230 commit 328f3b9

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

doc/changes/12386.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added the ability to scroll horizontally in TUI. (#12386, @Alizter)

src/dune_tui/dune_tui.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,7 @@ module Message_viewer = struct
203203
`Handled
204204
| _ -> `Unhandled
205205
in
206-
let mouse_handler ~x:_ ~y:_ = function
207-
| `Scroll dir ->
208-
vscroll ~dir;
209-
`Handled
210-
| _ -> `Unhandled
211-
in
212-
ui |> Ui.keyboard_area keyboard_handler |> Ui.mouse_area mouse_handler
206+
ui |> Ui.keyboard_area keyboard_handler
213207
;;
214208
end
215209

src/dune_tui/widgets/scrollbox.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ let scrollbar_wheel_step = 8 (* Wheel event scrolls 1/8th of the screen *)
2626
let scroll visible offset ~set ~dir =
2727
let dir =
2828
match dir with
29-
| `Down -> 1
30-
| `Up -> -1
29+
| `Down | `Right -> 1
30+
| `Up | `Left -> -1
3131
in
3232
set (offset + (dir * max 1 (visible / scrollbar_wheel_step)))
3333
;;
@@ -153,12 +153,14 @@ let make (state_var : State.t Lwd.var) t =
153153
and+ size = Lwd.get state_var in
154154
(* Render final box *)
155155
let box, vscroll, hscroll = compose_bars ui size in
156-
let hscroll ~dir =
157-
hscroll
158-
~dir:
159-
(match dir with
160-
| `Right -> `Down
161-
| `Left -> `Up)
156+
let mouse_handler ~x:_ ~y:_ = function
157+
| `Scroll ((`Up | `Down) as dir) ->
158+
vscroll ~dir;
159+
`Handled
160+
| `Scroll ((`Left | `Right) as dir) ->
161+
hscroll ~dir;
162+
`Handled
163+
| _ -> `Unhandled
162164
in
163-
{ ui = measure_size box; vscroll; hscroll }
165+
{ ui = measure_size box |> Ui.mouse_area mouse_handler; vscroll; hscroll }
164166
;;

vendor/notty/src/notty.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ module Unescape = struct
641641
| `Function of int
642642
]
643643

644-
type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down ] ]
644+
type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down | `Left | `Right ] ]
645645

646646
type mods = [ `Meta | `Ctrl | `Shift ] list
647647

@@ -725,9 +725,9 @@ module Unescape = struct
725725
| 0 -> `Left
726726
| 1 when bit 6 p -> `Scroll `Down
727727
| 1 -> `Middle
728-
| 2 when bit 6 p -> `ALL (* `Scroll `Left *)
728+
| 2 when bit 6 p -> `Scroll `Left
729729
| 2 -> `Right
730-
| 3 when bit 6 p -> `ALL (* `Scroll `Right *)
730+
| 3 when bit 6 p -> `Scroll `Right
731731
| _ -> `ALL
732732
and drag = bit 5 p
733733
and mods =

vendor/notty/src/notty.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ module Unescape : sig
464464
]
465465
(** A selection of extra keys on the keyboard. *)
466466

467-
type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down ] ]
467+
type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down | `Left | `Right ] ]
468468
(** Mouse buttons. *)
469469

470470
type mods = [ `Meta | `Ctrl | `Shift ] list
@@ -510,7 +510,8 @@ module Unescape : sig
510510
511511
{b Note} Every [`Press (`Left|`Middle|`Right)] generates a corresponding
512512
[`Release], but there is no portable way to detect which button was
513-
released. [`Scroll (`Up|`Down)] presses are not followed by releases.
513+
released. [`Scroll (`Up|`Down|`Left|`Right)] presses are not followed
514+
by releases.
514515
515516
}
516517
{- [`Paste (`Start|`End)] are {e bracketed paste} events, signalling the

vendor/update-notty.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
version=83aad282853bc35564114db72b65a087acf82ccf
3+
version=54b14f0dc25316a5b64206c55598442ec9d43325
44

55
set -e -o pipefail
66

0 commit comments

Comments
 (0)