mirror of
https://github.com/reynir/banawa-chat.git
synced 2024-12-22 10:37:53 +00:00
Implement broken quit:wq
This commit is contained in:
parent
8598f7011f
commit
fdbc198939
12
prompt.ml
12
prompt.ml
|
@ -2,13 +2,14 @@ open Nottui
|
|||
open Notty
|
||||
|
||||
type t = {
|
||||
quit : unit -> unit;
|
||||
message : string -> unit;
|
||||
cursor : Rp.Cursor.cursor;
|
||||
}
|
||||
|
||||
let make message =
|
||||
let make quit message =
|
||||
let cursor = Rp.Cursor.create Rp.empty 0 in
|
||||
{ message; cursor }
|
||||
{ quit; message; cursor }
|
||||
|
||||
let map_cursor f state =
|
||||
{ state with cursor = f state.cursor }
|
||||
|
@ -104,13 +105,16 @@ let handler ~hook state = function
|
|||
state.message msg;
|
||||
hook { state with cursor = Rp.Cursor.create Rp.empty 0 };
|
||||
`Handled
|
||||
| `ASCII ('C'..'D'), [`Ctrl] ->
|
||||
state.quit ();
|
||||
`Handled
|
||||
| _ -> `Unhandled
|
||||
|
||||
let make ~message cursor =
|
||||
let make ~quit ~message cursor =
|
||||
let ( let* ) x f = Lwd.bind x ~f in
|
||||
let ( let+ ) x f = Lwd.map ~f x in
|
||||
let ( and+ ) = Lwd.map2 ~f:(fun x y -> (x, y)) in
|
||||
let state = Lwd.var (make message) in
|
||||
let state = Lwd.var (make quit message) in
|
||||
let position = Lwd.var (0, 0) in
|
||||
let hook = Lwd.set state in
|
||||
let update_prompt state (y, w) =
|
||||
|
|
|
@ -43,10 +43,15 @@ module Main (_ : Mirage_random.S) (T : Mirage_time.S) (M : Mirage_clock.MCLOCK)
|
|||
let msg = Message.make ~nickname:username m in
|
||||
Lwd.set buffer_var (Rb.push buffer msg; buffer);
|
||||
in
|
||||
Rb.push buffer (Message.msgf "Welcome, %s!" username);
|
||||
let quit () =
|
||||
let msg = Message.msgf "%s tried to quit, but it is not implemented" username in
|
||||
Lwd.set buffer_var (Rb.push buffer msg; buffer);
|
||||
in
|
||||
Lwd.set buffer_var
|
||||
(Rb.push buffer (Message.msgf "Welcome, %s!" username); buffer);
|
||||
let ui =
|
||||
let ( let* ) x f = Lwd.bind x ~f in
|
||||
let* prompt = Prompt.make ~message cursor in
|
||||
let* prompt = Prompt.make ~quit ~message cursor in
|
||||
let* window = Window.make buffer_var in
|
||||
Lwd.return (Nottui.Ui.vcat [window; prompt])
|
||||
in
|
||||
|
|
Loading…
Reference in a new issue