class Formatador

def display(string = '')

def display(string = '')
  print(format("[indent]#{string}"))
  STDOUT.flush
  nil
end

def display_line(string = '')

def display_line(string = '')
  display(string)
  print("\n")
  nil
end

def display_table(hashes, keys = nil)

def display_table(hashes, keys = nil)
  headers = keys || []
  widths = {}
  for hash in hashes
    for key, value in hash.keys
      unless keys
        headers << key
      end
      widths[key] = [key.to_s.length, widths[key] || 0, hash[key] && hash[key].to_s.length || 0].max
    end
    headers = headers.uniq
  end
  split = "+"
  for header in headers
    split << ('-' * (widths[header] + 2)) << '+'
  end
  display_line(split)
  columns = []
  for header in headers
    columns << "#{header}#{' ' * (widths[header] - header.to_s.length)}"
  end
  display_line("| #{columns.join(' | ')} |")
  display_line(split)
  for hash in hashes
    columns = []
    for header in headers
      datum = hash[header] || ''
      columns << "#{datum}#{' ' * (widths[header] - datum.to_s.length)}"
    end
    display_line("| #{columns.join(' | ')} |")
    display_line(split)
  end
  nil
end

def format(string)

def format(string)
  if STDOUT.tty?
    string.gsub(FORMAT_REGEX) { "\e[#{STYLES[$1.to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
  else
    string.gsub(FORMAT_REGEX, '').gsub(INDENT_REGEX) { indentation }
  end
end

def indent(&block)

def indent(&block)
  @indent += 1
  yield
  @indent -= 1
end

def indentation

def indentation
  '  ' * @indent
end

def initialize

def initialize
  @indent = 1
end

def redisplay(string = '')

def redisplay(string = '')
  print("\r")
  display("#{string}")
  nil
end