123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::ThreadClient::Output

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/debug/thread_client.rb

Overview

copied from irb

Constant Summary

Class Method Summary

Instance Method Summary

::DEBUGGER__::Color - Included

#color_pp

See additional method definition at line 50.

#colored_inspect,
#colorize

See additional method definition at line 36.

#colorize_blue,
#colorize_code

See additional method definition at line 79.

#colorize_cyan, #colorize_dim, #colorize_magenta,
#irb_colorize

See additional method definition at line 27.

#with_inspection_error_guard

Constructor Details

.new(output) ⇒ Output

[ GitHub ]

  
# File 'lib/debug/thread_client.rb', line 1400

def initialize(output)
  @output = output
  @line_width = screen_width - MARGIN.length # right padding
end

Instance Method Details

#col_widths(strs, cols:) (private)

[ GitHub ]

  
# File 'lib/debug/thread_client.rb', line 1439

def col_widths(strs, cols:)
  cols.times.map do |col|
    (col...strs.size).step(cols).map do |i|
      strs[i].length
    end.max
  end
end

#dump(name, strs)

[ GitHub ]

  
# File 'lib/debug/thread_client.rb', line 1405

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

#fits_on_line?(strs, cols:, offset: 0) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/debug/thread_client.rb', line 1434

def fits_on_line?(strs, cols:, offset: 0)
  width = col_widths(strs, cols: cols).sum + MARGIN.length * (cols - 1)
  width <= @line_width - offset
end

#screen_width (private)

[ GitHub ]

  
# File 'lib/debug/thread_client.rb', line 1447

def screen_width
  SESSION.width
rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN>
  80
end