class AnsiPalette::ColoredString
Attributes
background[R]
color[R]
foreground[R]
modifier[RW]
string[R]
Public Class Methods
new(string:, color: nil, foreground: nil, background: nil, modifier: nil, bold: false, blink: false )
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 47 def initialize(string:, color: nil, foreground: nil, background: nil, modifier: nil, bold: false, blink: false ) @string = string @color = color @modifier = modifier @background = background @foreground = foreground @bold = bold @blink = blink end
Public Instance Methods
blink?()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 79 def blink?; blink; end
bold?()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 81 def bold?; bold; end
colored_string()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 71 def colored_string set_modifiers + set_foreground_color + set_background_color + string + reset_color end
Also aliased as: to_s
Private Instance Methods
escape_sequence(content)
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 139 def escape_sequence(content) START_ESCAPE + content + END_ESCAPE end
foreground_color()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 131 def foreground_color color || foreground end
reset_color()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 135 def reset_color escape_sequence(RESET_COLOR.to_s) end
set_background_color()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 119 def set_background_color set_color(background, "_BG") end
set_color(color, color_type)
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 123 def set_color(color, color_type) return "" if color.nil? escape_sequence( AnsiPalette.const_get(color.to_s.upcase + color_type).to_s ) end
set_foreground_color()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 115 def set_foreground_color set_color(foreground_color, "_FG") end
set_modifier()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 111 def set_modifier !modifier.nil? ? escape_sequence(modifier.to_s) : "" end
set_modifiers()
click to toggle source
# File lib/ansi_palette/colored_string.rb, line 92 def set_modifiers set_modifier + set_blink + set_bold + set_underline + set_blink + set_inverse_colors end