Class: Configs::Console::Color

Inherits:
Object
  • Object
show all
Defined in:
docs/000_a_root.rb

Overview

Represents a terminal color with optional TrueColor (RGB) support.

Each color has a required ANSI fallback value for terminals that do not support TrueColor.

Author:

  • Logic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ansi_fallback, red = nil, green = nil, blue = nil) ⇒ Color

Creates a new color.

Parameters:

  • ansi_fallback (Integer) —

    Required 16-color fallback code.

  • red (Integer, nil) (defaults to: nil) —

    Red component (0–255) or nil.

  • green (Integer, nil) (defaults to: nil) —

    Green component (0–255) or nil.

  • blue (Integer, nil) (defaults to: nil) —

    Blue component (0–255) or nil.

Raises:

  • (RuntimeError) —

    If the fallback is nil or the RGB values are invalid.



560
561
# File 'docs/000_a_root.rb', line 560

def initialize(ansi_fallback, red = nil, green = nil, blue = nil)
end

Instance Attribute Details

#ansi_fallback ⇒ Integer

16-color ANSI fallback code.

Returns:

  • (Integer)


552
553
554
# File 'docs/000_a_root.rb', line 552

def ansi_fallback
  @ansi_fallback
end

#blue ⇒ Integer?

Blue component (0–255), or nil if fallback-only.

Returns:

  • (Integer, nil)


549
550
551
# File 'docs/000_a_root.rb', line 549

def blue
  @blue
end

#green ⇒ Integer?

Green component (0–255), or nil if fallback-only.

Returns:

  • (Integer, nil)


546
547
548
# File 'docs/000_a_root.rb', line 546

def green
  @green
end

#red ⇒ Integer?

Red component (0–255), or nil if fallback-only.

Returns:

  • (Integer, nil)


543
544
545
# File 'docs/000_a_root.rb', line 543

def red
  @red
end

Instance Method Details

#ansi

Returns the ANSI fallback value.



594
595
# File 'docs/000_a_root.rb', line 594

def ansi
end

#ansi=(ansi)

Sets the ANSI fallback value.



591
592
# File 'docs/000_a_root.rb', line 591

def ansi=(ansi)
end

#set_color(red, green, blue)

This method returns an undefined value.

Sets the RGB color values.

Parameters:

  • red (Integer)
  • green (Integer)
  • blue (Integer)

Raises:

  • (ArgumentError) —

    If the values are not within 0–255.



588
589
# File 'docs/000_a_root.rb', line 588

def set_color(red, green, blue)
end

#to_ansi_str ⇒ String

Converts the RGB values into a TrueColor ANSI escape sequence.

Returns:

  • (String) —

    ANSI escape sequence such as "\e[38;2;255;0;0m".

Raises:

  • (RuntimeError) —

    If any RGB value is nil.



574
575
# File 'docs/000_a_root.rb', line 574

def to_ansi_str
end

#use_fallback? ⇒ Boolean

Whether this color should use its ANSI fallback instead of RGB.

Returns:

  • (Boolean) —

    true if all RGB components are nil.



579
580
# File 'docs/000_a_root.rb', line 579

def use_fallback?
end

#valid_color?(red, green, blue) ⇒ Boolean

Checks whether an RGB triplet is valid.

Parameters:

  • red (Integer, nil)
  • green (Integer, nil)
  • blue (Integer, nil)

Returns:

  • (Boolean) —

    true if all values are within 0–255 or all nil.



568
569
# File 'docs/000_a_root.rb', line 568

def valid_color?(red, green, blue)
end