class DEBUGGER__::ThreadClient::Output

copied from irb

Constants

MARGIN

Public Class Methods

new(output) click to toggle source
# File debug-1.8.0/lib/debug/thread_client.rb, line 1399
def initialize(output)
  @output = output
  @line_width = screen_width - MARGIN.length # right padding
end

Public Instance Methods

dump(name, strs) click to toggle source
# File debug-1.8.0/lib/debug/thread_client.rb, line 1404
def dump(name, strs)
  strs = strs.sort
  return if strs.empty?

  line = "#{colorize_blue(name)}: "

  # Attempt a single line
  if fits_on_line?(strs, cols: strs.size, offset: "#{name}: ".length)
    line += strs.join(MARGIN)
    @output << line
    return
  end

  # Multi-line
  @output << line

  # Dump with the largest # of columns that fits on a line
  cols = strs.size
  until fits_on_line?(strs, cols: cols, offset: MARGIN.length) || cols == 1
    cols -= 1
  end
  widths = col_widths(strs, cols: cols)
  strs.each_slice(cols) do |ss|
    @output << ss.map.with_index { |s, i| "#{MARGIN}%-#{widths[i]}s" % s }.join
  end
end