piotrmurach/pastel

pastel with color-element in a variable

gtom opened this issue · 1 comments

gtom commented

I'm playing around with beautiful lib pastel on linux and do not see a solution for my use case. I want to define colors for some cells in variables. But in this case I don't see my values in cell but whole pastel-string. How can I get over this?
Example:

`

require 'tty'
require 'pastel'
pastel=Pastel.new

puts "This works:"
table = TTY::Table.new ['header1', 'header2'], [[{value: pastel.blue('a1'),alignment: :center}, 'a2'], ['b1', 'b2']]
t = table.render do |renderer|
end
puts t

puts "This does not:"
val1 = "{value: pastel.blue('a1'),alignment: :center}"
table = TTY::Table.new ['header1', 'header2'], [[val1, 'a2'], ['b1', 'b2']]
t = table.render do |renderer|
end
puts t

`
This is my output (a1 is blue in first table):

`

This works:
header1 header2
a1 a2
b1 b2
This does not:
header1 header2
{value: pastel.blue('a1'),alignment: :center} a2
b1 b2
`
Did I miss something in documentation?

gtom commented

Silly me,
val1 has to be a hash like this:
val1 = Hash[value: pastel.blue('a1'),alignment: :center]

Now it works like a charm!