Module: Pry::Helpers

Defined in:
lib/pry/helpers/text.rb,
lib/pry/helpers/table.rb,
lib/pry/helpers/platform.rb,
lib/pry/helpers/base_helpers.rb,
lib/pry/helpers/command_helpers.rb,
lib/pry/helpers/options_helpers.rb,
lib/pry/helpers/documentation_helpers.rb

Defined Under Namespace

Modules: BaseHelpers, CommandHelpers, DocumentationHelpers, OptionsHelpers, Platform, Text Classes: Table

Class Method Summary collapse

Class Method Details

.tablify(things, line_length, config = Pry.config) ⇒ Object



24
25
26
27
28
29
# File 'lib/pry/helpers/table.rb', line 24

def self.tablify(things, line_length, config = Pry.config)
  table = Table.new(things, { column_count: things.size }, config)
  table.column_count -= 1 until 1 == table.column_count or
    table.fits_on_line?(line_length)
  table
end

.tablify_or_one_line(heading, things, config = Pry.config) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/pry/helpers/table.rb', line 3

def self.tablify_or_one_line(heading, things, config = Pry.config)
  plain_heading = Pry::Helpers::Text.strip_color(heading)
  attempt = Table.new(things, column_count: things.size)
  if attempt.fits_on_line?(Terminal.width! - plain_heading.size - 2)
    "#{heading}: #{attempt}\n"
  else
    "#{heading}: \n#{tablify_to_screen_width(things, { indent: '  ' }, config)}\n"
  end
end

.tablify_to_screen_width(things, options, config = Pry.config) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/pry/helpers/table.rb', line 13

def self.tablify_to_screen_width(things, options, config = Pry.config)
  options ||= {}
  things = things.compact
  if (indent = options[:indent])
    usable_width = Terminal.width! - indent.size
    tablify(things, usable_width, config).to_s.gsub(/^/, indent)
  else
    tablify(things, Terminal.width!, config).to_s
  end
end