class AnsiSys::SGR
Select Graphic Rendition
Constants
- CODE_LETTERS
Escape sequence codes processed in this Class
Attributes
background[R]
:black, :red, :green, :yellow, :blue, :magenta, :cyan, or :white
blink[R]
:off, :slow, or :rapid
conceal[R]
:off or :on
foreground[R]
:black, :red, :green, :yellow, :blue, :magenta, :cyan, or :white
image[R]
:positive or :negative
intensity[R]
:normal, :bold, or :faint
italic[R]
:off or :on
underline[R]
:none, :single, or :double
Public Class Methods
new()
click to toggle source
# File lib/ansisys.rb, line 272 def initialize reset! end
Public Instance Methods
==(other)
click to toggle source
true if all the attributes are same
# File lib/ansisys.rb, line 277 def ==(other) instance_variables.each do |ivar| return false unless instance_variable_get(ivar) == other.instance_variable_get(ivar) end return true end
apply_code!(letter = 'm', *pars)
click to toggle source
applies self an escape sequence code that ends with letter as String and with some pars as Integers
# File lib/ansisys.rb, line 291 def apply_code!(letter = 'm', *pars) raise AnsiSysError, "Invalid code for SGR: #{letter.inspect}" unless 'm' == letter pars = [0] unless pars pars.each do |code| case code when 0 @intensity = :normal @italic = :off @underline = :none @blink = :off @image = :positive @conceal = :off @foreground = :white @background = :black when 1..28 apply_code_table!(code) when 30..37 @foreground = COLOR[code - 30] @intensity = :normal when 39 reset! when 40..47 @background = COLOR[code - 40] @intensity = :normal when 49 reset! when 90..97 @foreground = COLOR[code - 90] @intensity = :bold when 99 reset! when 100..107 @background = COLOR[code - 100] @intensity = :bold when 109 reset! else raise AnsiSysError, "Invalid SGR code #{code.inspect}" unless CODE.has_key?(code) end end return self end
css_style(colors = Screen.default_css_colors)
click to toggle source
CSS stylelet
# File lib/ansisys.rb, line 361 def css_style(colors = Screen.default_css_colors) return CSSFormatter.hash_to_styles(css_styles(colors)) end
css_styles(colors = Screen.default_css_colors)
click to toggle source
a Hash of CSS stylelet
# File lib/ansisys.rb, line 366 def css_styles(colors = Screen.default_css_colors) r = Hash.new{|h, k| h[k] = Array.new} # intensity is not (yet) implemented r['font-style'] << 'italic' if @italic == :on r['text-decoration'] << 'underline' unless @underline == :none r['text-decoration'] << 'blink' unless @blink == :off case @image when :positive fg = @foreground bg = @background when :negative fg = @background bg = @foreground end fg = bg if @conceal == :on r['color'] << colors[@intensity][fg] unless fg == :white r['background-color'] << colors[@intensity][bg] unless bg == :black return r end
render(format = :html, position = :prefix, colors = Screen.default_css_colors)
click to toggle source
renders self as :html or :text format - makes a <span> html scriptlet. colors can be Screen.default_css_colors
(inverted, bright).
# File lib/ansisys.rb, line 336 def render(format = :html, position = :prefix, colors = Screen.default_css_colors) case format when :html case position when :prefix style_code = css_style(colors) if style_code return %Q|<span style="#{style_code}">| else return '' end when :postfix style_code = css_style(colors) if style_code return '</span>' else return '' end end when :text return '' end end
reset!()
click to toggle source
resets attributes
# File lib/ansisys.rb, line 285 def reset! apply_code!('m', 0) end
Private Instance Methods
apply_code_table!(code)
click to toggle source
# File lib/ansisys.rb, line 387 def apply_code_table!(code) raise AnsiSysError, "Invalid SGR code #{code.inspect}" unless CODE.has_key?(code) ivar, value = CODE[code] instance_variable_set("@#{ivar}", value) return self end