1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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:0 in
let description =
I.strf ~attr:A.(st bold) "%s" "Small Note Composer" |> I.pad ~l:2 ~t:1
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", "@"
; "Down", "Ctrl-n, j"
; "Up", "Ctrl-p, k"
; "Grep", "s"
; "Edit", "Enter, e"
]
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 27 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
|