Repository: zhiburt/tabled
Pull request #546 (2025-07-19 11:38:08)

Fix border span correction issue
ref #544


Patch:
diff --git a/papergrid/src/grid/peekable.rs b/papergrid/src/grid/peekable.rs
index cc63614..6567a31 100644
--- a/papergrid/src/grid/peekable.rs
+++ b/papergrid/src/grid/peekable.rs
@@ -1328,6 +1328,13 @@ mod grid_spanned {
                     let pos = (row, col).into();
 
                     if ctx.cfg.is_cell_covered_by_both_spans(pos) {
+                        let is_last_column = col + 1 == shape.count_columns;
+                        if is_last_column {
+                            let pos = (row, col + 1).into();
+                            let count_columns = shape.count_columns;
+                            print_vertical_char(f, ctx.cfg, pos, i, count_lines, count_columns)?;
+                        }
+
                         continue;
                     }
 
diff --git a/tabled/Cargo.toml b/tabled/Cargo.toml
index cf9d1eb..d7c0095 100644
--- a/tabled/Cargo.toml
+++ b/tabled/Cargo.toml
@@ -25,7 +25,7 @@ macros = ["std"]
 assert = ["testing_table"]
 
 [dependencies]
-papergrid = { version = "0.17", default-features = false }
+papergrid = { path = "../papergrid", default-features = false }
 tabled_derive = { version = "0.11", optional = true }
 testing_table = { version = "0.3", default-features = false, optional = true }
 ansi-str = { version = "0.9", optional = true }
diff --git a/tabled/examples/style_modern_rounded.rs b/tabled/examples/style_modern_rounded.rs
index 79ed82b..c5631ee 100644
--- a/tabled/examples/style_modern_rounded.rs
+++ b/tabled/examples/style_modern_rounded.rs
@@ -26,5 +26,5 @@ fn main() {
     let output2 = table2.to_string();
     let output = Table::new([(output1, output2)]);
 
-    println!("{}", output);
+    println!("{output}");
 }
diff --git a/tabled/src/settings/themes/border_correction.rs b/tabled/src/settings/themes/border_correction.rs
index c107287..57d6c47 100644
--- a/tabled/src/settings/themes/border_correction.rs
+++ b/tabled/src/settings/themes/border_correction.rs
@@ -178,6 +178,7 @@ fn correct_span_styles(cfg: &mut SpannedConfig, shape: (usize, usize)) {
 
         let has_right = col + 1 < shape.1 && has_top(cfg, (row, col + 1).into(), shape);
         let has_up = has_left(cfg, (row - 1, col).into(), shape);
+        let has_down = row + 1 < shape.0 && has_left(cfg, (row + 1, col).into(), shape);
 
         if has_up && !has_right {
             border.right_top_corner = borders.right_intersection;
@@ -187,11 +188,15 @@ fn correct_span_styles(cfg: &mut SpannedConfig, shape: (usize, usize)) {
             border.right_top_corner = borders.left_intersection;
         }
 
-        let has_down = row + 1 < shape.0 && has_left(cfg, (row + 1, col).into(), shape);
         if has_down {
             border.left_bottom_corner = borders.top_intersection;
         }
 
+        if !has_down && !has_up && !has_right {
+            border.right_top_corner = borders.vertical;
+            border.left_bottom_corner = borders.bottom;
+        }
+
         cfg.set_border((row, col).into(), border);
     }
 }


Test patch:
diff --git a/tabled/tests/settings/span_test.rs b/tabled/tests/settings/span_test.rs
index c0ece94..8f34fb6 100644
--- a/tabled/tests/settings/span_test.rs
+++ b/tabled/tests/settings/span_test.rs
@@ -1406,6 +1406,40 @@ test_table!(
     "+---+-----+-----+-----+"
 );
 
+test_table!(
+    border_correction_right_bottom_corner_0,
+    Matrix::new(3, 3)
+        .with(Style::modern())
+        .modify((1, 1), (Span::column(3), Span::row(3)))
+        .with(BorderCorrection::span()),
+    "┌───┬──────────┬──────────┬──────────┐"
+    "│ N │ column 0 │ column 1 │ column 2 │"
+    "├───┼──────────┴──────────┴──────────┤"
+    "│ 0 │              0-0               │"
+    "├───┤                                │"
+    "│ 1 │                                │"
+    "├───┤                                │"
+    "│ 2 │                                │"
+    "└───┴────────────────────────────────┘"
+);
+
+test_table!(
+    border_correction_right_bottom_corner_1,
+    Matrix::new(3, 3)
+        .with(Style::modern())
+        .modify((2, 2), (Span::column(2), Span::row(2)))
+        .with(BorderCorrection::span()),
+    "┌───┬──────────┬──────────┬──────────┐"
+    "│ N │ column 0 │ column 1 │ column 2 │"
+    "├───┼──────────┼──────────┼──────────┤"
+    "│ 0 │   0-0    │   0-1    │   0-2    │"
+    "├───┼──────────┼──────────┴──────────┤"
+    "│ 1 │   1-0    │         1-1         │"
+    "├───┼──────────┤                     │"
+    "│ 2 │   2-0    │                     │"
+    "└───┴──────────┴─────────────────────┘"
+);
+
 fn create_span_list(count_rows: usize, count_cols: usize) -> impl Iterator<Item = Position> {
     (0..count_rows).flat_map(move |r| (0..count_cols).map(move |c| (r, c).into()))
 }