class Sus::Output::Text
def [] key
def [] key @styles[key] end
def []= key, value
def []= key, value @styles[key] = value end
def append(buffer)
def append(buffer) buffer.each do |operation| self.public_send(*operation) end end
def buffered
def buffered Buffered.new(self) end
def colors?
def colors? false end
def indent
def indent @indent << INDENTATION end
def indented
def indented self.indent yield ensure self.outdent end
def initialize(io)
def initialize(io) @io = io @styles = {reset: self.reset} @indent = String.new @styles[:indent] = @indent end
def interactive?
def interactive? @io.tty? end
def outdent
def outdent @indent.slice!(INDENTATION) end
def puts(*arguments)
def puts(*arguments) write(*arguments) @io.puts(self.reset) end
def reset
def reset end
def size
def size [24, 80] end
def style(foreground, background = nil, *attributes)
def style(foreground, background = nil, *attributes) end
def width
def width size.last end
def write(*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 io stream.
Print out the given arguments.
def write(*arguments) arguments.each do |argument| case argument when Symbol @io.write(self[argument]) when Proc argument.call(self) else if argument.respond_to?(:print) argument.print(self) else @io.write(argument) end end end end