aboutsummaryrefslogtreecommitdiff
path: root/lib/help_screen.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/help_screen.ml')
-rw-r--r--lib/help_screen.ml55
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