diff options
author | Stan Lo <stan001212@gmail.com> | 2023-07-26 09:31:58 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-07-26 08:32:02 +0000 |
commit | 283b2fdab4be77d8721d7cf298168eb6e3798490 (patch) | |
tree | a660b377328de9a6aee25c859cf212a9e56a1865 /lib/irb/cmd | |
parent | 26aef1c73639718bc00c271ce7176bf3ee565c12 (diff) |
[ruby/irb] Page `ls`'s output (https://github.com/ruby/irb/pull/657)
* Page ls command's output
* Use Pager.page_content in show_cmds too
https://github.com/ruby/irb/commit/82d1687302
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r-- | lib/irb/cmd/ls.rb | 17 | ||||
-rw-r--r-- | lib/irb/cmd/show_cmds.rb | 4 |
2 files changed, 13 insertions, 8 deletions
diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb index 063a88d33f..791b1c1b21 100644 --- a/lib/irb/cmd/ls.rb +++ b/lib/irb/cmd/ls.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true require "reline" +require "stringio" require_relative "nop" +require_relative "../pager" require_relative "../color" module IRB @@ -33,7 +35,7 @@ module IRB o.dump("instance variables", obj.instance_variables) o.dump("class variables", klass.class_variables) o.dump("locals", locals) - nil + o.print_result end def dump_methods(o, klass, obj) @@ -77,6 +79,11 @@ module IRB def initialize(grep: nil) @grep = grep @line_width = screen_width - MARGIN.length # right padding + @io = StringIO.new + end + + def print_result + Pager.page_content(@io.string) end def dump(name, strs) @@ -85,12 +92,12 @@ module IRB return if strs.empty? # Attempt a single line - print "#{Color.colorize(name, [:BOLD, :BLUE])}: " + @io.print "#{Color.colorize(name, [:BOLD, :BLUE])}: " if fits_on_line?(strs, cols: strs.size, offset: "#{name}: ".length) - puts strs.join(MARGIN) + @io.puts strs.join(MARGIN) return end - puts + @io.puts # Dump with the largest # of columns that fits on a line cols = strs.size @@ -99,7 +106,7 @@ module IRB end widths = col_widths(strs, cols: cols) strs.each_slice(cols) do |ss| - puts ss.map.with_index { |s, i| "#{MARGIN}%-#{widths[i]}s" % s }.join + @io.puts ss.map.with_index { |s, i| "#{MARGIN}%-#{widths[i]}s" % s }.join end end diff --git a/lib/irb/cmd/show_cmds.rb b/lib/irb/cmd/show_cmds.rb index 1c9f1ea19a..cef6254ca0 100644 --- a/lib/irb/cmd/show_cmds.rb +++ b/lib/irb/cmd/show_cmds.rb @@ -29,9 +29,7 @@ module IRB output.puts end - Pager.page do |io| - io.puts output.string - end + Pager.page_content(output.string) end end end |