diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-14 10:46:28 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-14 10:46:28 -0500 |
commit | be2bf751536850e7bdfbd876ef908c5d6cf00087 (patch) | |
tree | 91d426b4b9f2e763aa5f23931f5ef166b47c2393 /lib/input_screen.ml | |
parent | fde592dbbb97a89a498feb95f97bee674bd571e8 (diff) | |
download | stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.tar.gz stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.tar.bz2 stitch-be2bf751536850e7bdfbd876ef908c5d6cf00087.zip |
Add search and tag search
Diffstat (limited to '')
-rw-r--r-- | lib/input_screen.ml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/input_screen.ml b/lib/input_screen.ml new file mode 100644 index 0000000..3fae53c --- /dev/null +++ b/lib/input_screen.ml @@ -0,0 +1,35 @@ +module Grep = Grep +module Common = Common +open Notty + +type state = + { user_input : string + ; on_enter : string -> unit + ; on_cancel : unit -> unit + ; prompt : string + ; screen : I.t + } + +let rec render t ({ user_input; on_enter; on_cancel; screen; prompt } as state) = + let _, size_y = Common.Term.size t in + Common.Term.cursor t (Some (String.length user_input + String.length prompt, size_y)); + let img = + let open I in + I.strf "%s%s" prompt user_input |> I.pad ~l:0 ~t:(size_y - 1) </> screen + in + Common.Term.image t img; + match Common.Term.event t with + | `End | `Key (`ASCII 'G', [ `Ctrl ]) | `Key (`ASCII 'C', [ `Ctrl ]) -> on_cancel () + | `Key (`Enter, []) -> on_enter user_input + | `Key (`Backspace, []) -> + let state = + { state with + user_input = String.sub user_input 0 (max (String.length user_input - 1) 0) + } + in + render t state + | `Resize _ -> render t state + | `Key (`ASCII c, []) -> + let state = { state with user_input = user_input ^ String.make 1 c } in + render t state + | _ -> render t state |