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
(fun (sp, (_, ip)) (pane:Display.pane) ->
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
({sr with box = (Box2.of_pts (Box2.tl_pt br) (Box2.max sp.box))},
(br, Image.seq [ ip; sir; ir])))
({sr with box = (Box2.of_pts (Box2.tl_pt br) (Box2.max sp.box))}, (br, Image.seq [ ip; sir; ir])))
(so, (so.box, Image.empty)) subpanes
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 += Cursor of Wall.color
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 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 fm = Text.Font.font_metrics f 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 text = String.sub text o l in
let sp = !sc in
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))};
in
let out_flush () =
(* F.epr "out_flush: () %s\n" (str_of_box !sc.box) ; *)() in
let out_flush () = () in
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)};
in
@ -382,7 +384,7 @@ let draw_pp height fpp (s:Display.state) =
Format.pp_safe_set_geometry pp ~max_indent ~margin;
fpp 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 node, sc, box = ref I.empty, ref s, ref Box2.zero in
@ -605,10 +607,8 @@ end
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 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
List.iter
(function
List.iter (function
| `Key_up (k:Display.key) ->
(match k with
| {keycode=0x40000052}(*up*) -> ignore (Zed_edit.prev_line ctx)
@ -625,12 +625,15 @@ let draw_textedit (te:textedit) height (s:Display.state) =
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 after_cursor = Zed_string.to_utf8 (Zed_rope.to_string zra) in
Format.pp_open_hvbox pp 0;
F.pf pp "> ";
F.text pp before_cursor;
Format.pp_open_stag pp (Cursor (Wall.Color.v 0.99 0.99 0.125 0.3));
F.pf 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))
type top_instance = {te: textedit; res: Buffer.t}
@ -645,7 +648,10 @@ let draw_top (t:top_instance) height (s:Display.state) =
pane_vbox [
draw_textedit t.te 30.;
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 ()
);
] s