class Console::Terminal::Text

A simple text-based terminal output.

def [] key

@returns [String] The style associated with the key.
@parameter key [Symbol] The key to look up.

Get the style associated with the given key.
def [] key
	@styles[key]
end

def []= key, value

@parameter value [String] The style to associate with the key.
@parameter key [Symbol] The key to associate the style with.

Set the style associated with the given key.
def []= key, value
	@styles[key] = value
end

def colors?

@returns [Boolean] Whether the terminal supports colors.
def colors?
	false
end

def initialize(stream)

@parameter stream [IO] The stream to write to.

Create a new text terminal output.
def initialize(stream)
	@stream = stream
	@styles = {reset: self.reset}
end

def print(*arguments)

@parameter arguments [Array] The arguments to print.

- When the argument is anything else, write it directly to the output.
- When the argument is a proc/lambda, call it with self as the argument.
- When the argument is a symbol, look up the style and inject it into the output stream.

Print rich text to the output stream.
def print(*arguments)
	arguments.each do |argument|
		case argument
		when Symbol
			@stream.write(self[argument])
		when Proc
			argument.call(self)
		else
			@stream.write(argument)
		end
	end
end

def print_line(*arguments)

@parameter arguments [Array] The arguments to print.

Print rich text to the output stream, followed by the reset sequence and a newline.
def print_line(*arguments)
	print(*arguments)
	@stream.puts(self.reset)
end

def puts(*arguments, style: nil)

@parameter style [Symbol] The style to apply.
@parameter arguments [Array] The arguments to write, each on a new line.

appended at the end of each line.
Write the given arguments to the output stream using the given style. The reset sequence is automatically
def puts(*arguments, style: nil)
	if style and prefix = self[style]
		arguments.each do |argument|
			argument.to_s.lines.each do |line|
				@stream.write(prefix, line.chomp)
				@stream.puts(self.reset)
			end
		end
	else
		@stream.puts(*arguments)
	end
end

def reset

@returns [String | Nil] The reset sequence if colors are supported, otherwise nil.

Generate a reset sequence.
def reset
end

def size

@returns [Tuple(Integer, Integer)] The size of the terminal, or a default value of [24, 80].
def size
	[24, 80]
end

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

@returns [String | Nil] The style string if colors are supported, otherwise nil.

Generate a style string for the given foreground, background, and attributes.
def style(foreground, background = nil, *attributes)
end

def width

@returns [Integer] The width of the terminal.
def width
	self.size.last
end

def write(*arguments, style: nil)

@parameter style [Symbol] The style to apply.
@parameter arguments [Array] The arguments to write.

Write the given arguments to the output stream using the given style. The reset sequence is automatically appended.
def write(*arguments, style: nil)
	if style and prefix = self[style]
		@stream.write(prefix)
		@stream.write(*arguments)
		@stream.write(self.reset)
	else
		@stream.write(*arguments)
	end
end