Skip to content

Commit

Permalink
Fixes #28: no misleading uptick for empty tree nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi authored and c-cube committed Dec 31, 2023
1 parent 9c785e5 commit e88894a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/printbox-text/PrintBox_text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,16 @@ end = struct
assert (Array.length a > 0);
if (size n).y > 0 && has_border (Pos.move_y pos' ~-1) conn_m.m then
conn_m.m <- create_or_update ~ct:`Nontree ~bottom:true (Pos.move_y pos' ~-1) conn_m.m;
(* To blend-in an empty tree root with a "wall" to the left: *)
(* if (size n).y = 0 then
conn_m.m <- create_or_update ~ct:`Nontree ~right:true (Pos.move_x pos' ~-1) conn_m.m; *)
let _ = _array_foldi
(fun pos' i b ->
let s = "└─" in
conn_m.m <- create_or_update ~ct:`Tree ~top:true ~right:true pos' conn_m.m;
let s = if pos'.y = pos.y then "──" else "└─" in
if pos'.y <> pos.y then
conn_m.m <- create_or_update ~ct:`Tree ~top:true ~right:true pos' conn_m.m
else
conn_m.m <- create_or_update ~ct:`Tree ~left:true ~right:true pos' conn_m.m;
conn_m.m <- create_or_update ~ct:`Tree ~left:true ~right:true (Pos.move_x pos' 1) conn_m.m;
conn_m.m <- create_or_update ~ct:`Tree ~top:true (Pos.move_y pos' 1) conn_m.m;
if i<Array.length a-1 then (
Expand Down
2 changes: 1 addition & 1 deletion test/test_ann_0_3.expected
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
│ ├──────────────────────────────────────────────────────────────┤
│ │Matt │
├─────────────────┼──────────────────────────────────────────────────────────────┤
│dependencies │─mandatory │
│dependencies │─mandatory │
│ ││ ├─dune │
│ ││ ├─bytes │
│ ││ ├─uutf │
Expand Down
21 changes: 16 additions & 5 deletions test/test_blending.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@
│ └───────┘
├─child 2
├─┬──────────────────┐
│ │─┬────────┐ │
│ │─┬────────┐ │
│ │ │header 3│ │
│ │ ├────────┘ │
│ │ └─┬──────────┐ │
│ │ │subchild 3│ │
│ │ └──────────┘ │
│ └──────────────────┘
├──┬────────┐
├──┬────────┐
│ │header 4│
│ ├────────┘
│ └─┬──────────┐
│ │subchild 4│
│ └──────────┘
└─┬───────┐
│child 5│
└───────┘
├─┬───────┐
│ │child 5│
│ └───────┘
└─┬──────────────────┐
│┌────────┐ │
││header 6│ │
│├────────┘ │
│└─┬───────┐ │
│ │child 6│ │
│ ├───────┘ │
│ └─┬──────────┐ │
│ │subchild 6│ │
│ └──────────┘ │
└──────────────────┘
5 changes: 4 additions & 1 deletion test/test_blending.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ let b =
tree empty [
tree (frame @@ text "header 4") [frame @@ text "subchild 4"]
];
frame @@ text "child 5"
frame @@ text "child 5";
frame @@ tree (frame @@ text "header 6") [
tree (frame @@ text "child 6") [frame @@ text "subchild 6"]
]
]

let () = print_endline @@ PrintBox_text.to_string b

0 comments on commit e88894a

Please sign in to comment.