diff options
Diffstat (limited to 'lib/input_prompt.ml')
-rw-r--r-- | lib/input_prompt.ml | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/input_prompt.ml b/lib/input_prompt.ml index 45979aa..aec6021 100644 --- a/lib/input_prompt.ml +++ b/lib/input_prompt.ml @@ -10,16 +10,22 @@ type state = ; 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 rec render t ({ user_input; on_enter; on_cancel; prompt; screen } as state) = + let size_x, size_y = Common.Term.size t in + Common.Term.cursor + t + (Some (String.length user_input + String.length prompt + 3, size_y)); let img = let open I in - I.strf "%s%s" prompt user_input |> I.pad ~l:0 ~t:(size_y - 1) </> screen + I.strf " %s " ~attr:(A.st A.reverse) prompt + <|> I.strf " %s%s" user_input (String.make size_x ' ') + |> 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 () + | `End | `Key (`Escape, []) | `Key (`ASCII 'G', [ `Ctrl ]) | `Key (`ASCII 'C', [ `Ctrl ]) + -> on_cancel () | `Key (`Enter, []) -> on_enter user_input | `Key (`Backspace, []) -> if String.equal "" user_input |