Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/12386.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added the ability to scroll horizontally in TUI. (#12386, @Alizter)
8 changes: 1 addition & 7 deletions src/dune_tui/dune_tui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,7 @@ module Message_viewer = struct
`Handled
| _ -> `Unhandled
in
let mouse_handler ~x:_ ~y:_ = function
| `Scroll dir ->
vscroll ~dir;
`Handled
| _ -> `Unhandled
in
ui |> Ui.keyboard_area keyboard_handler |> Ui.mouse_area mouse_handler
ui |> Ui.keyboard_area keyboard_handler
;;
end

Expand Down
20 changes: 11 additions & 9 deletions src/dune_tui/widgets/scrollbox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let scrollbar_wheel_step = 8 (* Wheel event scrolls 1/8th of the screen *)
let scroll visible offset ~set ~dir =
let dir =
match dir with
| `Down -> 1
| `Up -> -1
| `Down | `Right -> 1
| `Up | `Left -> -1
in
set (offset + (dir * max 1 (visible / scrollbar_wheel_step)))
;;
Expand Down Expand Up @@ -153,12 +153,14 @@ let make (state_var : State.t Lwd.var) t =
and+ size = Lwd.get state_var in
(* Render final box *)
let box, vscroll, hscroll = compose_bars ui size in
let hscroll ~dir =
hscroll
~dir:
(match dir with
| `Right -> `Down
| `Left -> `Up)
let mouse_handler ~x:_ ~y:_ = function
| `Scroll ((`Up | `Down) as dir) ->
vscroll ~dir;
`Handled
| `Scroll ((`Left | `Right) as dir) ->
hscroll ~dir;
`Handled
| _ -> `Unhandled
in
{ ui = measure_size box; vscroll; hscroll }
{ ui = measure_size box |> Ui.mouse_area mouse_handler; vscroll; hscroll }
;;
6 changes: 3 additions & 3 deletions vendor/notty/src/notty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ module Unescape = struct
| `Function of int
]

type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down ] ]
type button = [ `Left | `Middle | `Right | `Scroll of [ `Up | `Down | `Left | `Right ] ]

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

Expand Down Expand Up @@ -725,9 +725,9 @@ module Unescape = struct
| 0 -> `Left
| 1 when bit 6 p -> `Scroll `Down
| 1 -> `Middle
| 2 when bit 6 p -> `ALL (* `Scroll `Left *)
| 2 when bit 6 p -> `Scroll `Left
| 2 -> `Right
| 3 when bit 6 p -> `ALL (* `Scroll `Right *)
| 3 when bit 6 p -> `Scroll `Right
| _ -> `ALL
and drag = bit 5 p
and mods =
Expand Down
5 changes: 3 additions & 2 deletions vendor/notty/src/notty.mli
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ module Unescape : sig
]
(** A selection of extra keys on the keyboard. *)

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

type mods = [ `Meta | `Ctrl | `Shift ] list
Expand Down Expand Up @@ -510,7 +510,8 @@ module Unescape : sig

{b Note} Every [`Press (`Left|`Middle|`Right)] generates a corresponding
[`Release], but there is no portable way to detect which button was
released. [`Scroll (`Up|`Down)] presses are not followed by releases.
released. [`Scroll (`Up|`Down|`Left|`Right)] presses are not followed
by releases.

}
{- [`Paste (`Start|`End)] are {e bracketed paste} events, signalling the
Expand Down
2 changes: 1 addition & 1 deletion vendor/update-notty.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

version=83aad282853bc35564114db72b65a087acf82ccf
version=54b14f0dc25316a5b64206c55598442ec9d43325

set -e -o pipefail

Expand Down
Loading