Class: Console::Terminal::XTerm

Inherits:
Text
  • Object
show all
Defined in:
lib/console/terminal/xterm.rb

Constant Summary collapse

COLORS =
{
  black: 0,
  red: 1,
  green: 2,
  yellow: 3,
  blue: 4,
  magenta: 5,
  cyan: 6,
  white: 7,
  default: 9,
}
ATTRIBUTES =
{
  normal: 0,
  bold: 1,
  bright: 1,
  faint: 2,
  italic: 3,
  underline: 4,
  blink: 5,
  reverse: 7,
  hidden: 8,
}

Instance Method Summary collapse

Methods inherited from Text

#[], #[]=, #initialize, #print, #print_line, #puts, #write

Constructor Details

This class inherits a constructor from Console::Terminal::Text

Instance Method Details

#colors?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/console/terminal/xterm.rb', line 55

def colors?
  true
end

#resetObject



81
82
83
# File 'lib/console/terminal/xterm.rb', line 81

def reset
  "\e[0m"
end

#sizeObject



59
60
61
# File 'lib/console/terminal/xterm.rb', line 59

def size
  @output.winsize
end

#style(foreground, background = nil, *attributes) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/console/terminal/xterm.rb', line 63

def style(foreground, background = nil, *attributes)
  tokens = []
  
  if foreground
    tokens << 30 + COLORS.fetch(foreground)
  end
  
  if background
    tokens << 40 + COLORS.fetch(background)
  end
  
  attributes.each do |attribute|
    tokens << ATTRIBUTES.fetch(attribute){attribute.to_i}
  end
  
  return "\e[#{tokens.join(';')}m"
end