ok it works now

This commit is contained in:
cqc
2022-03-20 13:06:06 -05:00
parent fd7db32917
commit 98e78d81ec

126
human.ml
View File

@ -1295,6 +1295,9 @@ module Panel = struct
let node (t : t) = let node (t : t) =
set_parent_on_children {parent= None; t; n= node_n ()} set_parent_on_children {parent= None; t; n= node_n ()}
let atom (a : atom) = node (`Atom a)
let attr (a : attr) (child : node) = node (`Attr (a, child))
let join (d : dir) (a : node) (b : node) = node (`Join (d, a, b))
let empty_image = (Image.empty, V2.zero) let empty_image = (Image.empty, V2.zero)
let empty_node () = node (`Atom `Empty) let empty_node () = node (`Atom `Empty)
let style (s : Style.t) (n : node) = node (`Attr (`Style s, n)) let style (s : Style.t) (n : node) = node (`Attr (`Style s, n))
@ -1448,13 +1451,9 @@ module Panel = struct
| `Attr (_, n) -> n | `Attr (_, n) -> n
| `Join (_, a, _) -> a | `Join (_, a, _) -> a
let join_ d (a : node) (b : node) = let join_x = join `X
set_parent_on_children let join_y = join `Y
{parent= a.parent; t= `Join (d, a, b); n= node_n ()} let join_z = join `Z
let join_x = join_ `X
let join_y = join_ `Y
let join_z = join_ `Z
let pack_x : node Lwd_utils.monoid = (empty_node (), join_x) let pack_x : node Lwd_utils.monoid = (empty_node (), join_x)
let pack_y : node Lwd_utils.monoid = (empty_node (), join_y) let pack_y : node Lwd_utils.monoid = (empty_node (), join_y)
let pack_z : node Lwd_utils.monoid = (empty_node (), join_z) let pack_z : node Lwd_utils.monoid = (empty_node (), join_z)
@ -1463,8 +1462,7 @@ module Panel = struct
let ( ^*^ ) = join_z let ( ^*^ ) = join_z
let append_ d (l : node -> node) (a : node) : node -> node = let append_ d (l : node -> node) (a : node) : node -> node =
F.epr "append_%a@." pp_dir d ; fun n -> l (join d a n)
fun n -> l (join_ d a n)
let empty_append = Fun.id let empty_append = Fun.id
let append_x = append_ `X let append_x = append_ `X
@ -1480,82 +1478,49 @@ module Panel = struct
*) *)
module Text = struct module Text = struct
let rec _of_string let rec decode dec (l : 'a) :
(segmenter : 'a * [< `Await | `End | `Uchar of Uchar.t] =
'a
-> [`Uchar of Uchar.t | `Await | `End]
-> 'a * [`Uchar of Uchar.t | `Await | `End] ) dec (ly, lx)
=
F.epr "_of_string@." ;
let rec segment aa ll =
F.epr "segment %s -> "
( match aa with
| `Await -> "`Await"
| `End -> "`End"
| `Uchar c -> F.str "`Uchar U+%x" (Uchar.to_int c) ) ;
match segmenter ll aa with
| (ly', lx'), `Await -> (
F.epr "`Await -> decode@." ;
match Uutf.decode dec with match Uutf.decode dec with
| `Malformed b -> | `Malformed b ->
F.epr F.epr "Text.dec (Uutf.decode uudec)=`Malformed \"%s\"@."
"Text.dec (Uutf.decode uudec)=`Malformed \"%s\"@."
(String.escaped b) ; (String.escaped b) ;
_of_string segmenter dec decode dec (append_x l (of_string (String.escaped b)))
(ly', append_x lx' (of_string (String.escaped b))) | (`Await | `End | `Uchar _) as s -> (l, s)
| (`End | `Await | `Uchar _) as a -> segment a (lx', ly')
) and _of_string dec l =
| (ly', lx'), `Uchar c -> match decode dec l with
F.epr "`Uchar U+%04x -> `Await@." (Uchar.to_int c) ; | l, `End -> l (atom (`Boundary `Text))
segment `Await | l, `Uchar c -> _of_string dec (append_x l (atom (`Uchar c)))
(ly', append_x lx' (node (`Atom (`Uchar c)))) | l, _ -> _of_string dec l
| (ly', lx'), `End ->
F.epr "`End ;@." ;
append_y ly' (lx' (node (`Atom (`Boundary `Text))))
in
let r = segment `Await (ly, lx) in
F.epr "@." ; r
and of_string str = and of_string str =
(_of_string _of_string
(fun l s ->
F.epr "segmenter[of_string] %s -> "
( match s with
| `Await -> "`Await"
| `End -> "`End"
| `Uchar c -> F.str "`Uchar U+%x" (Uchar.to_int c) ) ;
(l, s) )
(Uutf.decoder (Uutf.decoder
~nln:(`Readline (Uchar.of_int 0x000A)) ~nln:(`Readline (Uchar.of_int 0x000A))
(`String str) ) (`String str) )
(empty_append, empty_append) ) empty_append
(node (`Atom (`Boundary `Text)))
and lines str = and _lines u d ly (lx, s) =
let rec line_seg u (ly, lx) s =
F.epr "line_seg %s -> "
( match s with
| `Await -> "`Await"
| `End -> "`End"
| `Uchar c -> F.str "`Uchar U+%x" (Uchar.to_int c) ) ;
match Uuseg.add u s with match Uuseg.add u s with
| (`End | `Await | `Uchar _) as s' -> ((lx, ly), s')
| `Boundary when Uuseg.mandatory u -> | `Boundary when Uuseg.mandatory u ->
line_seg u _lines u d
( append_y ly (lx (node (`Atom (`Boundary `Line)))) (append_y ly (lx (atom (`Boundary `Line))))
, empty_append ) (empty_append, `Await)
`Await
| `Boundary -> | `Boundary ->
line_seg u _lines u d ly (append_x lx (atom (`Hint `Line)), `Await)
(ly, append_x lx (node (`Atom (`Hint `Line)))) | `End -> ly (lx (atom (`Boundary `Text)))
`Await in | `Await -> _lines u d ly (decode d lx)
(_of_string | `Uchar c ->
(line_seg (Uuseg.create `Line_break)) _lines u d ly (append_x lx (atom (`Uchar c)), `Await)
let lines str =
_lines
(Uuseg.create `Line_break)
(Uutf.decoder (Uutf.decoder
~nln:(`Readline (Uchar.of_int 0x000A)) ~nln:(`Readline (Uchar.of_int 0x000A))
(`String str) ) (`String str) )
(empty_append, empty_append) ) empty_append
(node (`Atom (`Boundary `Text))) (empty_append, `Await)
end end
let text = Text.lines let text = Text.lines
@ -1856,19 +1821,15 @@ module Panel = struct
match Key.Bind.resolve_events bind [e] with match Key.Bind.resolve_events bind [e] with
| x :: _ -> | x :: _ ->
c.sel <- remove_attr c.sel ; c.sel <- remove_attr c.sel ;
F.epr (*F.epr
"textedit_handler c.root=@.@[%a@]@.c.sel=%a@." "textedit_handler c.sel.n=%d@ c.root=@ @[%a@]@."
pp_node_structure c.root pp_node c.sel ; pp_node_n c.sel pp_node_structure c.root ; *)
( match perform_action x c with ( match perform_action x c with
| Some _ -> | Some _ ->
F.epr F.epr "textedit action @[%a@] Success@."
"textedit_handler perform_action @[%a@] \
success@."
Action.pp_t x Action.pp_t x
| None -> | None ->
F.epr F.epr "textedit action @[%a@] Failure@."
"textedit_handler perform_action @[%a@] \
FAILURE@."
Action.pp_t x ) ; Action.pp_t x ) ;
c.sel <- insert_attr cursor_attr c.sel ; c.sel <- insert_attr cursor_attr c.sel ;
Lwt.return_none Lwt.return_none
@ -1913,7 +1874,7 @@ module Panel = struct
(Lwd.pure (Lwd.pure
(textedit_handler (textedit_handler
(style Style.dark (style Style.dark
(* (join_y (join_y
(join_y (join_y
(Text.of_string (Text.of_string
"-- welcome to my land of idiocy ---" ) "-- welcome to my land of idiocy ---" )
@ -1921,9 +1882,8 @@ module Panel = struct
^^ Text.of_string "!\n sup daddy" ) ^^ Text.of_string "!\n sup daddy" )
^/^ (text "hello bitch" ^^ text "!\n sup daddy") ^/^ (text "hello bitch" ^^ text "!\n sup daddy")
^/^ text "hello bitch" ^/^ text "!\n sup daddy" ^/^ text "hello bitch" ^/^ text "!\n sup daddy"
) ) *) ) )
(Text.of_string "123") (Text.of_string "123") ) ) ) )
(* )p *) ) ) )
end end
end end