ruby/lib/irb/cmd/show_cmds.rb
Stan Lo 283b2fdab4 [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

82d1687302
2023-07-26 08:32:02 +00:00

38 lines
966 B
Ruby

# frozen_string_literal: true
require "stringio"
require_relative "nop"
require_relative "../pager"
module IRB
# :stopdoc:
module ExtendCommand
class ShowCmds < Nop
category "IRB"
description "List all available commands and their description."
def execute(*args)
commands_info = IRB::ExtendCommandBundle.all_commands_info
commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max
output = StringIO.new
commands_grouped_by_categories.each do |category, cmds|
output.puts Color.colorize(category, [:BOLD])
cmds.each do |cmd|
output.puts " #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)} #{cmd[:description]}"
end
output.puts
end
Pager.page_content(output.string)
end
end
end
# :startdoc:
end