mirror of
https://github.com/reynir/banawa-chat.git
synced 2024-12-26 04:07:55 +00:00
Cleanup, reduce Lwd.set calls
This commit is contained in:
parent
1724e5c994
commit
3f43398866
|
@ -64,7 +64,9 @@ module User_prompt = struct
|
|||
let text, position =
|
||||
Utils.render_cursor ~width:(max 0 (w - 3)) state.cursor
|
||||
in
|
||||
Lwd.set cursor (position + 1, y);
|
||||
let new_cursor = (position + 1, y) in
|
||||
if new_cursor <> (Lwd.peek cursor) then
|
||||
Lwd.set cursor new_cursor;
|
||||
I.hcat [ I.char A.empty ' ' 1 1 ; text ]
|
||||
end
|
||||
|
||||
|
@ -116,7 +118,10 @@ let make ~quit ~message cursor =
|
|||
let ( and+ ) = Lwd.map2 ~f:(fun x y -> (x, y)) in
|
||||
let state = Lwd.var (make quit message) in
|
||||
let position = Lwd.var (0, 0) in
|
||||
let hook = Lwd.set state in
|
||||
let hook state' =
|
||||
if (Lwd.peek state).cursor != state'.cursor then
|
||||
Lwd.set state state'
|
||||
in
|
||||
let update_prompt state (y, w) =
|
||||
let user = User_prompt.render ~cursor ~y ~w state in
|
||||
Ui.keyboard_area (handler ~hook state) (Ui.atom user)
|
||||
|
|
11
window.ml
11
window.ml
|
@ -51,27 +51,22 @@ let render { w; h } msgs =
|
|||
done;
|
||||
Ui.atom (I.vsnap ~align:`Bottom h !image)
|
||||
|
||||
let handler ~hook:_ _state _buffer _key = `Unhandled
|
||||
|
||||
let make w =
|
||||
let ( let* ) x f = Lwd.bind ~f x 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 { w = 0; h = 0; p = 0 } in
|
||||
let hook = Lwd.set state in
|
||||
let state = Lwd.var { w = 0; h = 0 } in
|
||||
|
||||
let* document =
|
||||
let+ state = Lwd.get state
|
||||
and+ buffer = Lwd.get w in
|
||||
Ui.keyboard_area
|
||||
(handler ~hook state buffer)
|
||||
(render state buffer)
|
||||
render state buffer
|
||||
in
|
||||
|
||||
let update_size ~w ~h =
|
||||
let state' = Lwd.peek state in
|
||||
if state'.w <> w || state'.h <> h then Lwd.set state { state' with w; h }
|
||||
if state'.w <> w || state'.h <> h then Lwd.set state { w; h }
|
||||
in
|
||||
|
||||
let measure_size document =
|
||||
|
|
Loading…
Reference in a new issue