Module: WindowBlessing::XtermOutput::SetColor

Included in:
WindowBlessing::XtermOutput
Defined in:
lib/window_blessing/xterm_output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_bgObject (readonly)

Returns the value of attribute current_bg.



26
27
28
# File 'lib/window_blessing/xterm_output.rb', line 26

def current_bg
  @current_bg
end

#current_fgObject (readonly)

Returns the value of attribute current_fg.



26
27
28
# File 'lib/window_blessing/xterm_output.rb', line 26

def current_fg
  @current_fg
end

Instance Method Details

#change_bg(bg) ⇒ Object



13
14
15
16
# File 'lib/window_blessing/xterm_output.rb', line 13

def change_bg(bg)
  set_bg(bg) if bg!=@current_bg
  @current_bg = bg
end

#change_fg(fg) ⇒ Object



8
9
10
11
# File 'lib/window_blessing/xterm_output.rb', line 8

def change_fg(fg)
  set_fg(fg) if fg!=@current_fg
  @current_fg = fg
end

#out_color(txt, fg, bg) ⇒ Object



47
48
49
50
51
# File 'lib/window_blessing/xterm_output.rb', line 47

def out_color(txt, fg, bg)
  set_color(fg, bg)
  out txt
  reset_color
end

#reset_colorObject



41
42
43
44
45
# File 'lib/window_blessing/xterm_output.rb', line 41

def reset_color
  @current_fg = 7
  @current_bg = 0
  out "\x1b[0m"
end

#set_bg(bg) ⇒ Object



22
23
24
# File 'lib/window_blessing/xterm_output.rb', line 22

def set_bg(bg)
  out "\x1b[48;5;#{bg}m"
end

#set_boldObject



53
# File 'lib/window_blessing/xterm_output.rb', line 53

def set_bold; out "\x1b[1m" end

#set_color(fg, bg = nil) ⇒ Object



28
29
30
31
# File 'lib/window_blessing/xterm_output.rb', line 28

def set_color(fg, bg=nil)
  set_fg(fg) if fg
  set_bg(bg) if bg
end

#set_color_24bit(fg, bg = nil) ⇒ Object

fg and bg are r-g-b arrays: [0..255, 0..255, 0..255] This is not supported by iTerm2: code.google.com/p/iterm2/issues/detail?id=218 konsole supports it: github.com/robertknight/konsole/blob/master/user-doc/README.moreColors



36
37
38
39
# File 'lib/window_blessing/xterm_output.rb', line 36

def set_color_24bit(fg, bg=nil)
  out "\x1b[38;2;#{fg.join(';')}m" if fg
  out "\x1b[48;2;#{bg.join(';')}m" if bg
end

#set_fg(fg) ⇒ Object



18
19
20
# File 'lib/window_blessing/xterm_output.rb', line 18

def set_fg(fg)
  out "\x1b[38;5;#{fg}m"
end

#set_underlineObject



54
# File 'lib/window_blessing/xterm_output.rb', line 54

def set_underline; out "\x1b[4m" end