tj / terminal-table

Ruby ASCII Table Generator, simple and feature rich.
MIT License
1.53k stars 121 forks source link

:colspan creates conflicts with colorize #95

Closed FluffyCode closed 3 years ago

FluffyCode commented 6 years ago

(Say that title ten times fast...)

Using terminal-table has been fantastic for me, particularly due to its compatibility with colorize. I even combine colors with :border_x, :border_y and :border_i to create custom-colored tables/borders.

However I got around to experimenting with :colspan to split the display of "cell" data, and colorize ends up breaking :border_y.

table_sc

The tables turn out as such:

table_result

Of course, I can remove the :border_y styling to fix it...

table_result2

...but then I don't have my schnazzy blue dividers.

Capy-pasta-able code, in case you'd like to experiment:

require 'colorize' require 'terminal-table'

original_sample_data = [ ["Sep 2016", 33, [-38, -53.52], 46, [-25, -35.21]], ["Oct 2016", 35, [2, 6.06], 50, [4, 8.69]] ]

table = Terminal::Table.new headings: ["Month".cyan,"Monthly IT".cyan,"IT Difference OPM".cyan, "Monthly OOT".cyan,"OOT Difference OPM".cyan], rows: original_sample_data

table.style = { padding_left: 2, padding_right: 2, border_x: "-".blue, border_y: "|".blue, border_i: "+".blue }

puts table

puts "" puts "^ good table" puts "v wonky talbe" puts ""

split_column_sample_data = [ ["Sep 2016", 33, -38, -53.52, 46, -25, -35.21], ["Oct 2016", 35, 2, 6.06, 50, 4, 8.69] ]

table = Terminal::Table.new headings: ["Month".cyan,"Monthly IT".cyan, {value: "IT Difference OPM".cyan, colspan: 2}, "Monthly OOT".cyan, {value: "OOT Difference OPM".cyan, colspan: 2}], rows: split_column_sample_data

table.style = { padding_left: 2, padding_right: 2, border_x: "-".blue, border_y: "|".blue, border_i: "+".blue }

puts table

nanobowers commented 3 years ago

@nateberkopec I think this can be closed - bug fixed as part of #113