From dd5e0089992579d5506599cf58644c237b02b8c6 Mon Sep 17 00:00:00 2001 From: Ronan Arraes Jardim Chagas Date: Fri, 21 Jul 2023 13:13:50 -0300 Subject: [PATCH] :bug: Fix cell data type ref when showing row numbers Closes #208 --- src/backends/text/print_table.jl | 2 +- test/text_backend/issues.jl | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/backends/text/print_table.jl b/src/backends/text/print_table.jl index a56f2316..4e5f502e 100644 --- a/src/backends/text/print_table.jl +++ b/src/backends/text/print_table.jl @@ -248,7 +248,7 @@ function _print_table_data!( # In this case, we need to process the cell to apply the # correct alignment and highlighters before rendering # it. - cell_data = _get_element(ptable, rps.i_pt, jr) + cell_data = _get_element(ptable, rps.i_pt, j) cell_processed_str, cell_crayon = _process_data_cell_text( ptable, diff --git a/test/text_backend/issues.jl b/test/text_backend/issues.jl index 1896c233..a6ad560f 100644 --- a/test/text_backend/issues.jl +++ b/test/text_backend/issues.jl @@ -1157,13 +1157,13 @@ end │ Row │ B │ A │ │ │ Int64 │ AnsiTextCell │ ├─────┼───────┼──────────────┤ -│ 1 │ 1 │ 1 │ -│ 2 │ 2 │ 2 │ -│ 3 │ 3 │ 3 │ +│ 1 │ 1 │ 1\e[0m │ +│ 2 │ 2 │ 2\e[0m │ +│ 3 │ 3 │ 3\e[0m │ │ ⋮ │ ⋮ │ ⋮ │ -│ 98 │ 98 │ 98 │ -│ 99 │ 99 │ 99 │ -│ 100 │ 100 │ 100 │ +│ 98 │ 98 │ 98\e[0m │ +│ 99 │ 99 │ 99 \e[0m │ +│ 100 │ 100 │ 100\e[0m │ └─────┴───────┴──────────────┘ 94 rows omitted """ @@ -1183,3 +1183,23 @@ end @test result == expected end + +@testset "Issue #208 - Wrong cell type with custom cells and showing row numbers" begin + table = Dict( + :x => ["totally not an a"], + :xx => [AnsiTextCell("a")], + ) + + expected = """ +┌─────┬──────────────┬──────────────────┐ +│ Row │ xx │ x │ +│ │ AnsiTextCell │ String │ +├─────┼──────────────┼──────────────────┤ +│ 1 │ a\e[0m │ totally not an a │ +└─────┴──────────────┴──────────────────┘ +""" + + result = pretty_table(String, table; show_row_number = true) + + @test result == expected +end