class Toys::Utils::Terminal

def interpret_style_string(style)


Transform various style string formats into a list of style codes.
#
def interpret_style_string(style)
  case style
  when /^[0-9a-fA-F]{6}$/
    rgb = style.to_i(16)
    [38, 2, rgb >> 16, (rgb & 0xff00) >> 8, rgb & 0xff]
  when /^[0-9a-fA-F]{3}$/
    rgb = style.to_i(16)
    [38, 2, (rgb >> 8) * 0x11, ((rgb & 0xf0) >> 4) * 0x11, (rgb & 0xf) * 0x11]
  when /^\e\[([\d;]+)m$/
    ::Regexp.last_match(1).split(";").map(&:to_i)
  end
end