Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rex Table command column width based on longest dispatcher command #18893

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/rex/ui/text/dispatcher_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def cmd_help_tabs(str, words)
#
# Return a pretty, user-readable table of commands provided by this
# dispatcher.
# The command column width can be modified by passing in :command_width.
#
def help_to_s(opts={})
# If this dispatcher has no commands, we can't do anything useful.
Expand All @@ -250,7 +251,7 @@ def help_to_s(opts={})
{
'Command' =>
{
'Width' => 12
'Width' => opts[:command_width]
}
})

Expand Down Expand Up @@ -656,8 +657,10 @@ def current_dispatcher
def help_to_s(opts = {})
str = ''

max_command_length = dispatcher_stack.flat_map { |dispatcher| dispatcher.commands.to_a }.map { |(name, _description)| name.length }.max

dispatcher_stack.reverse.each { |dispatcher|
str << dispatcher.help_to_s
str << dispatcher.help_to_s(opts.merge({ command_width: [max_command_length, 12].max }))
}

return str
Expand Down
Loading