telist is lwd.var

This commit is contained in:
cqc
2024-07-06 00:14:56 -05:00
parent 023495b3b0
commit b117b6916b
2 changed files with 45 additions and 62 deletions

53
ogui.ml
View File

@ -80,21 +80,6 @@ let string_of_utf_8_uchar uc =
let pp_uchar : Uchar.t F.t = let pp_uchar : Uchar.t F.t =
fun ppf u -> F.pf ppf "%S" (string_of_utf_8_uchar u) fun ppf u -> F.pf ppf "%S" (string_of_utf_8_uchar u)
module Sense = struct
type t = {
click : bool;
drag : bool;
focusable : bool;
edit : bool;
}
let click =
{ click = true; drag = false; focusable = true; edit = false }
let hover =
{ click = false; drag = false; focusable = true; edit = false }
end
module TextBuffer = struct module TextBuffer = struct
type t = { type t = {
path : string list Lwd.var; path : string list Lwd.var;
@ -717,17 +702,7 @@ module Ui = struct
| Some (`Char _) -> Lwt_stream.junk events | Some (`Char _) -> Lwt_stream.junk events
| _ -> Lwt.return_unit) | _ -> Lwt.return_unit)
| Accepted _ | Continue _ | Rejected -> Lwt.return_unit) | Accepted _ | Continue _ | Rejected -> Lwt.return_unit)
(*Lwt_stream.peek events >>= function >>= fun () -> proc res
| Some (`Char cc) -> (
match res with
| Accepted _ | Continue _ ->
F.epr
"Ui.process_events Lwt_stream.junk events@.";
proc ~skip:(`Char cc) res
| Rejected -> )
| Some (`Key _) | None -> proc res *)
>>=
fun () -> proc res
| `Char char -> | `Char char ->
F.epr "Ui.process_events `Char '%a'@." pp_uchar F.epr "Ui.process_events `Char '%a'@." pp_uchar
(Uchar.of_int char); (Uchar.of_int char);
@ -1170,10 +1145,9 @@ module Layout = struct
|> Lwd.map ~f:(fun tl -> frame ?size ~style (`TextEdit (t, tl))) |> Lwd.map ~f:(fun tl -> frame ?size ~style (`TextEdit (t, tl)))
|> Lwt.return |> Lwt.return
let system ui ?(style = textedit_style) d (telist : TextEdit.t list) let system ui ?(style = textedit_style) d
= (telist : TextEdit.t list Lwd.var) =
let cursor = Lwd.var 0 in let cursor = Lwd.var 0 in
let len = List.length telist in
Ui.update_bindings ui (fun a -> Ui.update_bindings ui (fun a ->
a a
|> Event.adds |> Event.adds
@ -1183,11 +1157,13 @@ module Layout = struct
( "window_next", ( "window_next",
fun () -> fun () ->
Lwd.set cursor Lwd.set cursor
(if Lwd.peek cursor < len - 1 then (if
Lwd.peek cursor + 1 Lwd.peek cursor
< (List.length @@ Lwd.peek telist) - 1
then Lwd.peek cursor + 1
else 0); else 0);
TextEdit.default_bindings TextEdit.default_bindings
(List.nth telist (Lwd.peek cursor)) (List.nth (Lwd.peek telist) (Lwd.peek cursor))
ui; ui;
Lwt.return_unit ); Lwt.return_unit );
] ]
@ -1200,14 +1176,16 @@ module Layout = struct
Lwd.set cursor Lwd.set cursor
(if Lwd.peek cursor > 0 then (if Lwd.peek cursor > 0 then
Lwd.peek cursor - 1 Lwd.peek cursor - 1
else len - 1); else (Lwd.peek telist |> List.length) - 1);
TextEdit.default_bindings TextEdit.default_bindings
(List.nth telist (Lwd.peek cursor)) (List.nth (Lwd.peek telist) (Lwd.peek cursor))
ui; ui;
Lwt.return_unit ); Lwt.return_unit );
]); ]);
(* let teln = List.length telist in *) (* let teln = List.length telist in *)
(* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *) (* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *)
Lwd.map
~f:(fun tl ->
Lwt_list.mapi_s Lwt_list.mapi_s
(fun n te -> (fun n te ->
textedit textedit
@ -1232,8 +1210,11 @@ module Layout = struct
}; };
}) })
|> Lwt.return) |> Lwt.return)
telist tl
>>= fun framelist -> box ~style d framelist |> Lwt.return >>= fun framelist -> box ~style d framelist |> Lwt.return)
(Lwd.get telist)
|> lwt_lwd
>>= fun d -> Lwd.join d |> Lwt.return
let pp_dir ppf (t : [ `X | `Y | `Z ]) = let pp_dir ppf (t : [ `X | `Y | `Z ]) =
F.pf ppf "%s" F.pf ppf "%s"

View File

@ -160,7 +160,6 @@ let main =
[ [
[ [
Key (Press, X, [ Control ]); Key (Press, X, [ Control ]);
Key (Release, X, [ Control ]);
Key (Press, E, [ Control ]); Key (Press, E, [ Control ]);
]; ];
] ]
@ -168,7 +167,6 @@ let main =
Custom Custom
( "toplevel_execute", ( "toplevel_execute",
fun () -> fun () ->
F.epr "Ctrl-X Ctrl-E@.";
TextBuffer.peek tb_init >>= fun str -> TextBuffer.peek tb_init >>= fun str ->
Toploop.use_input out_ppf (String str) Toploop.use_input out_ppf (String str)
|> F.epr "Toploop.use_input=%b@."; |> F.epr "Toploop.use_input=%b@.";
@ -179,7 +177,11 @@ let main =
system ui `Y system ui `Y
~style: ~style:
Style.{ default with margin = Margin.symmetric 10.0 10.0 } Style.{ default with margin = Margin.symmetric 10.0 10.0 }
[ TextEdit.multiline ui tb_init; TextEdit.multiline ui to_init ]) (Lwd.var
[
TextEdit.multiline ui tb_init;
TextEdit.multiline ui to_init;
]))
>>= fun page -> >>= fun page ->
let page_root = Lwd.observe page in let page_root = Lwd.observe page in