class Console::Terminal::XTerm

XTerm style terminal output.

def colors?

Whether the terminal supports colors.
def colors?
	true
end

def reset

@returns [String] The reset code.

Reset the style.
def reset
	"\e[0m"
end

def size

The size of the terminal.
def size
	@stream.winsize
rescue Errno::ENOTTY, Errno::ENODEV
	# Fake it...
	[24, 80]
end

def style(foreground, background = nil, *attributes)

@returns [String] The style code.
@parameter attributes [Array(Symbol)] The attributes to apply.
@parameter background [Symbol] The background color.
@parameter foreground [Symbol] The foreground color.

Apply the given style to the output.
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

def width

The width of the terminal.
def width
	size.last
end