Skip to content

Commit

Permalink
🐛 Fix cell data type ref when showing row numbers
Browse files Browse the repository at this point in the history
Closes #208
  • Loading branch information
ronisbr committed Jul 21, 2023
1 parent 739100b commit dd5e008
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backends/text/print_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 26 additions & 6 deletions test/text_backend/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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

0 comments on commit dd5e008

Please sign in to comment.