diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-14 19:11:24 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-14 19:11:24 -0500 |
commit | 8dc118d9bf685d96022a010fb2a20d724c40b5cf (patch) | |
tree | ce99ac0f13c0f8407bbde30630366b9143ef7558 /lib/help_screen.ml | |
parent | a76fb32e7c5815e37b5772f15326f00ec58a322d (diff) | |
download | stitch-8dc118d9bf685d96022a010fb2a20d724c40b5cf.tar.gz stitch-8dc118d9bf685d96022a010fb2a20d724c40b5cf.tar.bz2 stitch-8dc118d9bf685d96022a010fb2a20d724c40b5cf.zip |
Add help menu
Diffstat (limited to '')
-rw-r--r-- | lib/help_screen.ml | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/help_screen.ml b/lib/help_screen.ml new file mode 100644 index 0000000..2f6fbaa --- /dev/null +++ b/lib/help_screen.ml @@ -0,0 +1,55 @@ +module Common = Common +open Notty + +type state = { go_back : unit -> unit } + +let info = [ "STITCH"; "Note composing tool" ] + +let render_info = + let title = I.strf ~attr:A.(st bold) "%s" "STITCH" |> I.pad ~l:2 ~t:1 in + let description = + I.strf ~attr:A.(st bold) "%s" "Small Note Composer" |> I.pad ~l:2 ~t:2 + in + let keybindings = I.strf ~attr:A.(st bold) "%s" "Keybindings" |> I.pad ~l:2 ~t:4 in + let open I in + title </> description </> keybindings + + +let help_menu = + [ "Toggle this menu", "?" + ; "Exit", "Ctrl-c, q, Esc" + ; "Toggle collapsed view", "@" + ; "Go down", "Ctrl-n, j" + ; "Go up", "Ctrl-p, k" + ; "Grep", "s" + ] + + +let pad str n = + let padding = n - String.length str in + String.concat "" [ str; String.make padding ' ' ] + + +let render_help_menu start_y = + let elements = + List.mapi + (fun i (explanation, keybinding) -> + let padding = pad explanation 30 in + I.strf "%s%s" padding keybinding |> I.pad ~l:2 ~t:(i + start_y)) + help_menu + in + let open I in + List.fold_left (fun sum el -> el </> sum) I.empty elements + + +let rec render t ({ go_back } as state) = + let img = + let open I in + render_info </> render_help_menu 5 + in + Common.Term.image t img; + match Common.Term.event t with + | `End | `Key (`Escape, []) | `Key (`ASCII 'q', []) | `Key (`ASCII 'C', [ `Ctrl ]) -> () + | `Resize _ -> render t state + | `Key (`ASCII '?', []) -> go_back () + | _ -> render t state |