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
Private Instance Methods
col_widths(strs, cols:)
click to toggle source
# File debug-1.8.0/lib/debug/thread_client.rb, line 1438 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
fits_on_line?(strs, cols:, offset: 0)
click to toggle source
# File debug-1.8.0/lib/debug/thread_client.rb, line 1433 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()
click to toggle source
# File debug-1.8.0/lib/debug/thread_client.rb, line 1446 def screen_width SESSION.width rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN> 80 end