class Console::Terminal::Text
def [] key
def [] key @styles[key] end
def []= key, value
def []= key, value @styles[key] = value end
def colors?
def colors? false end
def initialize(output)
def initialize(output) @output = output @styles = {reset: self.reset} end
def print(*arguments)
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 out the given arguments.
def print(*arguments) arguments.each do |argument| case argument when Symbol @output.write(self[argument]) when Proc argument.call(self) else @output.write(argument) end end end
def print_line(*arguments)
def print_line(*arguments) print(*arguments) @output.puts(self.reset) end
def puts(*arguments, style: nil)
def puts(*arguments, style: nil) if style and prefix = self[style] @output.write(prefix) @output.puts(*arguments) @output.write(self.reset) else @output.puts(*arguments) end end
def reset
def reset end
def style(foreground, background = nil, *attributes)
def style(foreground, background = nil, *attributes) end
def write(*arguments, style: nil)
def write(*arguments, style: nil) if style and prefix = self[style] @output.write(prefix) @output.write(*arguments) @output.write(self.reset) else @output.write(*arguments) end end