Method: Color.format
- Defined in:
- lib/color.rb
.format(style, string) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/color.rb', line 20 def self.format(style, string) codes = [*style].map { |name| SGR_CODES.fetch(name.to_s) } color = false codes.each_with_index do |code, i| next unless code >= 30 codes[i] += 10 if color color = true end "\e[#{ codes.join(";") }m#{ string }\e[m" end |