formatting bro

This commit is contained in:
cqc
2021-07-14 18:14:55 -05:00
parent bff1adc740
commit ca5ea42759
2 changed files with 30 additions and 22 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
_build/

View File

@ -277,9 +277,9 @@ let pane_vbox (subpanes:Display.pane list) (so:Display.state) =
List.fold_left List.fold_left
(fun (sp, (_, ip)) (pane:Display.pane) -> (fun (sp, (_, ip)) (pane:Display.pane) ->
let sr, (br, ir) = pane sp in let sr, (br, ir) = pane sp in
F.epr "pane_vbox: %s\n" (str_of_box br);
let _, (_, sir) = path_box (Color.v 0.125 0.125 1.0 0.125) br sp in let _, (_, sir) = path_box (Color.v 0.125 0.125 1.0 0.125) br sp in
({sr with box = (Box2.of_pts (Box2.tl_pt br) (Box2.max sp.box))}, ({sr with box = (Box2.of_pts (Box2.tl_pt br) (Box2.max sp.box))}, (br, Image.seq [ ip; sir; ir])))
(br, Image.seq [ ip; sir; ir])))
(so, (so.box, Image.empty)) subpanes (so, (so.box, Image.empty)) subpanes
in in
let b = Box2.of_pts (Box2.o so.box) (Box2.max br) in let b = Box2.of_pts (Box2.o so.box) (Box2.max br) in
@ -333,19 +333,21 @@ type Format.stag += Color_bg of Wall.color
type Format.stag += Color_fg of Wall.color type Format.stag += Color_fg of Wall.color
type Format.stag += Cursor of Wall.color type Format.stag += Cursor of Wall.color
let draw_pp height fpp (s:Display.state) = let draw_pp height fpp (s:Display.state) =
F.epr "draw_pp: %s\n" (str_of_box s.box);
let node, sc, box = ref I.empty, ref s, ref Box2.zero in let node, sc, box = ref I.empty, ref s, ref Box2.zero in
let push (s, (b, i)) = node := I.stack !node i; sc := s; box := b in let push (s, (b, i)) = node := I.stack !node i; sc := s; box := b in
let f = Text.Font.make ~size:height (Lazy.force font_sans) in let f = Text.Font.make ~size:height (Lazy.force font_sans) in
let fm = Text.Font.font_metrics f in let fm = Text.Font.font_metrics f in
let font_height = fm.ascent -. fm.descent +. fm.line_gap in let font_height = fm.ascent -. fm.descent +. fm.line_gap in
let max_x = ref 0. in
let out_string text o l = let out_string text o l =
let text = String.sub text o l in let text = String.sub text o l in
let sp = !sc in let sp = !sc in
push @@ simple_text f text !sc; push @@ simple_text f text !sc;
max_x := max !max_x (Box2.maxx !box);
sc := {!sc with box = (Box2.of_pts (P2.v (Box2.maxx !box) (Box2.oy sp.box)) (Box2.max sp.box))}; sc := {!sc with box = (Box2.of_pts (P2.v (Box2.maxx !box) (Box2.oy sp.box)) (Box2.max sp.box))};
in in
let out_flush () = let out_flush () = () in
(* F.epr "out_flush: () %s\n" (str_of_box !sc.box) ; *)() in
let out_newline () = let out_newline () =
sc := {!sc with box = Box2.of_pts (P2.v (Box2.ox s.box) ((Box2.oy !sc.box) +. font_height)) (Box2.max s.box)}; sc := {!sc with box = Box2.of_pts (P2.v (Box2.ox s.box) ((Box2.oy !sc.box) +. font_height)) (Box2.max s.box)};
in in
@ -382,7 +384,7 @@ let draw_pp height fpp (s:Display.state) =
Format.pp_safe_set_geometry pp ~max_indent ~margin; Format.pp_safe_set_geometry pp ~max_indent ~margin;
fpp pp; fpp pp;
Format.pp_force_newline pp (); Format.pp_force_newline pp ();
!sc, ((Box2.of_pts (Box2.o s.box) (Box2.max !sc.box)), !node) !sc, ((Box2.of_pts (Box2.o s.box) (P2.v !max_x (Box2.maxy !box))), !node)
(*let draw_spp height fpp (s:Display.state) = (*let draw_spp height fpp (s:Display.state) =
let node, sc, box = ref I.empty, ref s, ref Box2.zero in let node, sc, box = ref I.empty, ref s, ref Box2.zero in
@ -605,32 +607,33 @@ end
type textedit = {ze: unit Zed_edit.t; zc: Zed_cursor.t} type textedit = {ze: unit Zed_edit.t; zc: Zed_cursor.t}
let make_textedit () = let z = Zed_edit.create () in {ze = z; zc = Zed_edit.new_cursor z;} let make_textedit () = let z = Zed_edit.create () in {ze = z; zc = Zed_edit.new_cursor z;}
let draw_textedit (te:textedit) height (s:Display.state) = let draw_textedit (te:textedit) height (s:Display.state) =
F.epr "draw_textedit: (Zed_cursor.get_position te.zc)=%d\n" (Zed_cursor.get_position te.zc);
let ctx = Zed_edit.context te.ze te.zc in let ctx = Zed_edit.context te.ze te.zc in
List.iter List.iter (function
(function | `Key_up (k:Display.key) ->
| `Key_up (k:Display.key) -> (match k with
(match k with | {keycode=0x40000052}(*up*) -> ignore (Zed_edit.prev_line ctx)
| {keycode=0x40000052}(*up*) -> ignore (Zed_edit.prev_line ctx) | {keycode=0x40000051}(*down*) -> ignore (Zed_edit.next_line ctx)
| {keycode=0x40000051}(*down*) -> ignore (Zed_edit.next_line ctx) | {keycode=0x40000050}(*left*) -> ignore (Zed_edit.prev_char ctx)
| {keycode=0x40000050}(*left*) -> ignore (Zed_edit.prev_char ctx) | {keycode=0x4000004f}(*right*)-> ignore (Zed_edit.next_char ctx)
| {keycode=0x4000004f}(*right*)-> ignore (Zed_edit.next_char ctx) | {char='\r'; ctrl=false; shift=false; meta=false; fn=false} -> Zed_edit.newline ctx
| {char='\r'; ctrl=false; shift=false; meta=false; fn=false} -> Zed_edit.newline ctx | {char='\b';} -> Zed_edit.remove_prev ctx 1
| {char='\b';} -> Zed_edit.remove_prev ctx 1 | {char='\t'} -> Zed_edit.insert_char ctx (CamomileLibrary.UChar.of_char '\t')
| {char='\t'} -> Zed_edit.insert_char ctx (CamomileLibrary.UChar.of_char '\t') | _ -> Zed_edit.insert_char ctx (Display.key_to_uchar k); ())
| _ -> Zed_edit.insert_char ctx (Display.key_to_uchar k); ()) | `Key_down _ -> ()
| `Key_down _ -> () | _ -> ()) s.events;
| _ -> ()) s.events;
draw_pp 30. (fun pp -> draw_pp 30. (fun pp ->
let zrb, zra = Zed_rope.break (Zed_edit.text te.ze) (Zed_cursor.get_position te.zc) in let zrb, zra = Zed_rope.break (Zed_edit.text te.ze) (Zed_cursor.get_position te.zc) in
let before_cursor = Zed_string.to_utf8 (Zed_rope.to_string zrb) in let before_cursor = Zed_string.to_utf8 (Zed_rope.to_string zrb) in
let after_cursor = Zed_string.to_utf8 (Zed_rope.to_string zra) in let after_cursor = Zed_string.to_utf8 (Zed_rope.to_string zra) in
Format.pp_open_hvbox pp 0;
F.pf pp "> "; F.pf pp "> ";
F.text pp before_cursor; F.text pp before_cursor;
Format.pp_open_stag pp (Cursor (Wall.Color.v 0.99 0.99 0.125 0.3)); Format.pp_open_stag pp (Cursor (Wall.Color.v 0.99 0.99 0.125 0.3));
F.pf pp ""; F.pf pp "";
Format.pp_close_stag pp (); Format.pp_close_stag pp ();
F.text pp after_cursor; F.pf pp "@.@.";) s F.text pp after_cursor;
Format.pp_close_box pp ();
F.pf pp "@.@.";) s
let str_of_textedit (te:textedit) = Zed_string.to_utf8 (Zed_rope.to_string (Zed_edit.text te.ze)) let str_of_textedit (te:textedit) = Zed_string.to_utf8 (Zed_rope.to_string (Zed_edit.text te.ze))
type top_instance = {te: textedit; res: Buffer.t} type top_instance = {te: textedit; res: Buffer.t}
@ -645,7 +648,10 @@ let draw_top (t:top_instance) height (s:Display.state) =
pane_vbox [ pane_vbox [
draw_textedit t.te 30.; draw_textedit t.te 30.;
draw_pp 30. (fun pp -> draw_pp 30. (fun pp ->
F.pf pp "%s@." (Buffer.contents t.res); Format.pp_open_hvbox pp 0;
F.text pp (Buffer.contents t.res);
F.pf pp "@.";
Format.pp_close_box pp ();
F.flush pp () F.flush pp ()
); );
] s ] s