Skip to content

Commit e88894a

Browse files
lukstafic-cube
authored andcommitted
Fixes #28: no misleading uptick for empty tree nodes
1 parent 9c785e5 commit e88894a

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/printbox-text/PrintBox_text.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,16 @@ end = struct
623623
assert (Array.length a > 0);
624624
if (size n).y > 0 && has_border (Pos.move_y pos' ~-1) conn_m.m then
625625
conn_m.m <- create_or_update ~ct:`Nontree ~bottom:true (Pos.move_y pos' ~-1) conn_m.m;
626+
(* To blend-in an empty tree root with a "wall" to the left: *)
627+
(* if (size n).y = 0 then
628+
conn_m.m <- create_or_update ~ct:`Nontree ~right:true (Pos.move_x pos' ~-1) conn_m.m; *)
626629
let _ = _array_foldi
627630
(fun pos' i b ->
628-
let s = "└─" in
629-
conn_m.m <- create_or_update ~ct:`Tree ~top:true ~right:true pos' conn_m.m;
631+
let s = if pos'.y = pos.y then "──" else "└─" in
632+
if pos'.y <> pos.y then
633+
conn_m.m <- create_or_update ~ct:`Tree ~top:true ~right:true pos' conn_m.m
634+
else
635+
conn_m.m <- create_or_update ~ct:`Tree ~left:true ~right:true pos' conn_m.m;
630636
conn_m.m <- create_or_update ~ct:`Tree ~left:true ~right:true (Pos.move_x pos' 1) conn_m.m;
631637
conn_m.m <- create_or_update ~ct:`Tree ~top:true (Pos.move_y pos' 1) conn_m.m;
632638
if i<Array.length a-1 then (

test/test_ann_0_3.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
│ ├──────────────────────────────────────────────────────────────┤
1515
│ │Matt │
1616
├─────────────────┼──────────────────────────────────────────────────────────────┤
17-
│dependencies │─mandatory │
17+
│dependencies │─mandatory │
1818
│ ││ ├─dune │
1919
│ ││ ├─bytes │
2020
│ ││ ├─uutf │

test/test_blending.expected

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@
66
│ └───────┘
77
├─child 2
88
├─┬──────────────────┐
9-
│ │─┬────────┐ │
9+
│ │─┬────────┐ │
1010
│ │ │header 3│ │
1111
│ │ ├────────┘ │
1212
│ │ └─┬──────────┐ │
1313
│ │ │subchild 3│ │
1414
│ │ └──────────┘ │
1515
│ └──────────────────┘
16-
├──┬────────┐
16+
├──┬────────┐
1717
│ │header 4│
1818
│ ├────────┘
1919
│ └─┬──────────┐
2020
│ │subchild 4│
2121
│ └──────────┘
22-
└─┬───────┐
23-
│child 5│
24-
└───────┘
22+
├─┬───────┐
23+
│ │child 5│
24+
│ └───────┘
25+
└─┬──────────────────┐
26+
│┌────────┐ │
27+
││header 6│ │
28+
│├────────┘ │
29+
│└─┬───────┐ │
30+
│ │child 6│ │
31+
│ ├───────┘ │
32+
│ └─┬──────────┐ │
33+
│ │subchild 6│ │
34+
│ └──────────┘ │
35+
└──────────────────┘

test/test_blending.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ let b =
99
tree empty [
1010
tree (frame @@ text "header 4") [frame @@ text "subchild 4"]
1111
];
12-
frame @@ text "child 5"
12+
frame @@ text "child 5";
13+
frame @@ tree (frame @@ text "header 6") [
14+
tree (frame @@ text "child 6") [frame @@ text "subchild 6"]
15+
]
1316
]
1417

1518
let () = print_endline @@ PrintBox_text.to_string b

0 commit comments

Comments
 (0)