1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/ls/formatter.rb
Kyrylo Silin 63f12424d1 Refactor the way how ls displays constants
I also had to refactor global variables a bit, because the more entities
I have to display, the harder the code is.
2013-11-30 16:02:53 +02:00

46 lines
976 B
Ruby

class Pry
class Command::Ls < Pry::ClassCommand
class Formatter
attr_accessor :grep
def initialize(target)
@target = target
end
def color(type, str)
Pry::Helpers::Text.send(Pry.config.ls.send(:"#{type}_color"), str)
end
# Add a new section to the output.
# Outputs nothing if the section would be empty.
def output_section(heading, body)
return '' if body.compact.empty?
fancy_heading = Pry::Helpers::Text.bold(color(:heading, heading))
Pry::Helpers.tablify_or_one_line(fancy_heading, body)
end
def format_value(value)
Pry::ColorPrinter.pp(value, '')
end
def write_out
return false unless correct_opts?
output_self
end
def correct_opts?
@default_switch
end
def output_self
raise NotImplementedError
end
def grep
@grep || proc { |x| x }
end
end
end
end