0

I'm working on modifying Brett Weaver's Trello CLI ruby-based utility to include information from a Trello card object, namely the label colors associated with that card. Right now, I can do something like the following to iterate through the labels on each card:

list_cards.each_with_index do |card, i|

  puts "#{i+1} #{card.name}"

    card.labels.each do |label|
      puts "(#{label.name})"
    end
end

Rather than printing the label.name attribute, I would prefer to print a solid colored square that corresponds to the label.color attribute. An example of this can be seen in another library seen here. I've read about using the colorize library to get the color, but first I can't figure out how to get it to print a color dynamically rather than explicitly and second, I can't figure out how I would print a square. Additionally, the colorize gem doesn't have the range of colors that are needed from Trello (like orange or purple).

mbeasley
  • 4,864
  • 5
  • 27
  • 39
  • @CarySwoveland That was extraneous; a result of me not being a ruby native and just copying the structure of the outside block. Editted. – mbeasley Mar 17 '14 at 10:55

1 Answers1

1

With the colorize gem, all you need to do is print two spaces on a background color, like:

puts "  ".colorize(background: :blue)

to display a blue square.

zwippie
  • 15,050
  • 3
  • 39
  • 54
  • But how would I tell it to print a color using the `label.color` attribute, which is a string (i.e. `"blue"`). – mbeasley Mar 17 '14 at 12:03
  • 1
    `puts " ".colorize(background: label.color.to_sym)` should work if your color names are not too foreign. – zwippie Mar 17 '14 at 12:45
  • But what about colors that are not included with colorize? Like orange or purple? – mbeasley Mar 17 '14 at 12:57
  • I added case statements for orange and purple to change them to colorize-compatible colors (realizing that no matter what I did, the terminal would not output certain colors. This worked great. Thanks! – mbeasley Mar 17 '14 at 13:05
  • The VT100 Terminal Emulator has basic support for the 8 colors as mentioned in [`colorize`](https://github.com/fazibear/colorize/blob/master/lib/colorize.rb). – zwippie Mar 17 '14 at 13:05