Skip to content

Commit

Permalink
Treat all direct colors the same
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed Jun 21, 2024
1 parent 2499427 commit d03bef2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
1.10.1
12 changes: 6 additions & 6 deletions lib/term/ansicolor/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def initialize(name, code, options = {})
if rgb = options[:true_color]
@true_color = true
@rgb = rgb
elsif rgb = options[:color8]
@color8 = true
elsif rgb = options[:direct]
@direct = true
@rgb = RGBTriple.from_html(rgb)
elsif html = options[:html]
@rgb = RGBTriple.from_html(html)
Expand All @@ -110,7 +110,7 @@ def code
background? ? "48;2;#{@rgb.to_a * ?;}" : "38;2;#{@rgb.to_a * ?;}"
elsif rgb_color?
background? ? "48;5;#{@code}" : "38;5;#{@code}"
elsif color8?
elsif direct?
background? ? (@code.to_i + 10).to_s : @code
else
@code
Expand All @@ -125,16 +125,16 @@ def background?
!!@background
end

def color8?
!!@color8
def direct?
!!@direct
end

attr_writer :background

attr_reader :rgb

def rgb_color?
!!@rgb && !@true_color && !@color8
!!@rgb && !@true_color && !@direct
end

def true_color?
Expand Down
32 changes: 16 additions & 16 deletions lib/term/ansicolor/attribute/color8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ module Term
module ANSIColor
class Attribute
class Color8
Attribute.set :black, 30, color8: '#000000'
Attribute.set :red, 31, color8: '#800000'
Attribute.set :green, 32, color8: '#008000'
Attribute.set :yellow, 33, color8: '#808000'
Attribute.set :blue, 34, color8: '#000080'
Attribute.set :magenta, 35, color8: '#800080'
Attribute.set :cyan, 36, color8: '#008080'
Attribute.set :white, 37, color8: '#c0c0c0'
Attribute.set :black, 30, direct: '#000000'
Attribute.set :red, 31, direct: '#800000'
Attribute.set :green, 32, direct: '#008000'
Attribute.set :yellow, 33, direct: '#808000'
Attribute.set :blue, 34, direct: '#000080'
Attribute.set :magenta, 35, direct: '#800080'
Attribute.set :cyan, 36, direct: '#008080'
Attribute.set :white, 37, direct: '#c0c0c0'

Attribute.set :on_black, 40, color8: '#000000'
Attribute.set :on_red, 41, color8: '#800000'
Attribute.set :on_green, 42, color8: '#008000'
Attribute.set :on_yellow, 43, color8: '#808000'
Attribute.set :on_blue, 44, color8: '#000080'
Attribute.set :on_magenta, 45, color8: '#800080'
Attribute.set :on_cyan, 46, color8: '#008080'
Attribute.set :on_white, 47, color8: '#808080'
Attribute.set :on_black, 40, direct: '#000000'
Attribute.set :on_red, 41, direct: '#800000'
Attribute.set :on_green, 42, direct: '#008000'
Attribute.set :on_yellow, 43, direct: '#808000'
Attribute.set :on_blue, 44, direct: '#000080'
Attribute.set :on_magenta, 45, direct: '#800080'
Attribute.set :on_cyan, 46, direct: '#008080'
Attribute.set :on_white, 47, direct: '#808080'
end
end
end
Expand Down
66 changes: 32 additions & 34 deletions lib/term/ansicolor/attribute/intense_color8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@ module Term
module ANSIColor
class Attribute
class IntenseColor8
# High intensity, aixterm (works in OS X)
Attribute.set :intense_black, 90
Attribute.set :bright_black, 90
Attribute.set :intense_red, 91
Attribute.set :bright_red, 91
Attribute.set :intense_green, 92
Attribute.set :bright_green, 92
Attribute.set :intense_yellow, 93
Attribute.set :bright_yellow, 93
Attribute.set :intense_blue, 94
Attribute.set :bright_blue, 94
Attribute.set :intense_magenta, 95
Attribute.set :bright_magenta, 95
Attribute.set :intense_cyan, 96
Attribute.set :bright_cyan, 96
Attribute.set :intense_white, 97
Attribute.set :bright_white, 97
Attribute.set :intense_black, 90, direct: '#808080'
Attribute.set :bright_black, 90, direct: '#808080'
Attribute.set :intense_red, 91, direct: '#ff0000'
Attribute.set :bright_red, 91, direct: '#ff0000'
Attribute.set :intense_green, 92, direct: '#00ff00'
Attribute.set :bright_green, 92, direct: '#00ff00'
Attribute.set :intense_yellow, 93, direct: '#ffff00'
Attribute.set :bright_yellow, 93, direct: '#ffff00'
Attribute.set :intense_blue, 94, direct: '#0000ff'
Attribute.set :bright_blue, 94, direct: '#0000ff'
Attribute.set :intense_magenta, 95, direct: '#ff00ff'
Attribute.set :bright_magenta, 95, direct: '#ff00ff'
Attribute.set :intense_cyan, 96, direct: '#00ffff'
Attribute.set :bright_cyan, 96, direct: '#00ffff'
Attribute.set :intense_white, 97, direct: '#ffffff'
Attribute.set :bright_white, 97, direct: '#ffffff'

# High intensity background, aixterm (works in OS X)
Attribute.set :on_intense_black, 100
Attribute.set :on_bright_black, 100
Attribute.set :on_intense_red, 101
Attribute.set :on_bright_red, 101
Attribute.set :on_intense_green, 102
Attribute.set :on_bright_green, 102
Attribute.set :on_intense_yellow, 103
Attribute.set :on_bright_yellow, 103
Attribute.set :on_intense_blue, 104
Attribute.set :on_bright_blue, 104
Attribute.set :on_intense_magenta, 105
Attribute.set :on_bright_magenta, 105
Attribute.set :on_intense_cyan, 106
Attribute.set :on_bright_cyan, 106
Attribute.set :on_intense_white, 107
Attribute.set :on_bright_white, 107
Attribute.set :on_intense_black, 100, direct: '#808080'
Attribute.set :on_bright_black, 100, direct: '#808080'
Attribute.set :on_intense_red, 101, direct: '#ff0000'
Attribute.set :on_bright_red, 101, direct: '#ff0000'
Attribute.set :on_intense_green, 102, direct: '#00ff00'
Attribute.set :on_bright_green, 102, direct: '#00ff00'
Attribute.set :on_intense_yellow, 103, direct: '#ffff00'
Attribute.set :on_bright_yellow, 103, direct: '#ffff00'
Attribute.set :on_intense_blue, 104, direct: '#0000ff'
Attribute.set :on_bright_blue, 104, direct: '#0000ff'
Attribute.set :on_intense_magenta, 105, direct: '#ff00ff'
Attribute.set :on_bright_magenta, 105, direct: '#ff00ff'
Attribute.set :on_intense_cyan, 106, direct: '#00ffff'
Attribute.set :on_bright_cyan, 106, direct: '#00ffff'
Attribute.set :on_intense_white, 107, direct: '#ffffff'
Attribute.set :on_bright_white, 107, direct: '#ffffff'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/term/ansicolor/attribute/underline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def underline(string = nil, color: nil, type: nil, &block)
if color
a = Term::ANSIColor::Attribute[color]
color_code =
if a.true_color? || a.rgb_color? || a.color8?
if a.true_color? || a.rgb_color? || a.direct?
color_code = "\e[58;2;#{a.rgb.to_a * ?;}"
else
raise ArgumentError, "invalid color #{a.name.inspect}"
Expand Down
2 changes: 1 addition & 1 deletion lib/term/ansicolor/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Term::ANSIColor
# Term::ANSIColor version
VERSION = '1.10.0'
VERSION = '1.10.1'
VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
Expand Down
4 changes: 2 additions & 2 deletions term-ansicolor.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
# stub: term-ansicolor 1.10.0 ruby lib
# stub: term-ansicolor 1.10.1 ruby lib

Gem::Specification.new do |s|
s.name = "term-ansicolor".freeze
s.version = "1.10.0".freeze
s.version = "1.10.1".freeze

s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
Expand Down

0 comments on commit d03bef2

Please sign in to comment.