def text_format(data, indent=0)
buffer = ''
if data.respond_to?(:keys)
justify_width = data.keys.map {|k| k.to_s.size }.max.to_i + 2
data.sort.each do |key, value|
justified_key = ui.color("#{key}:".ljust(justify_width), :cyan)
if should_enumerate?(value)
buffer << indent_line(justified_key, indent)
buffer << text_format(value, indent + 1)
else
buffer << indent_key_value(justified_key, value, justify_width, indent)
end
end
elsif data.kind_of?(Array)
data.each do |item|
if should_enumerate?(data)
buffer << text_format(item, indent + 1)
else
buffer << indent_line(item, indent)
end
end
else
buffer << indent_line(stringify_value(data), indent)
end
buffer
end