module Riffer::Rig::Terminal::Help
Constants
- POINTER
Public Instance Methods
(Riffer::Rig::Terminal::Autocomplete::_Entry command) → String
Source
# File lib/riffer/rig/terminal/help.rb, line 37 def about(command) # A line break in a description would split its row in two. command.description.gsub(/[[:cntrl:]]+/, ' ').strip end
@rbs command: Riffer::Rig::Terminal::Autocomplete::_Entry @rbs return: String
(Array[Riffer::Rig::Terminal::Autocomplete::_Entry] commands) → String
Source
# File lib/riffer/rig/terminal/help.rb, line 11 def call(commands) sorted = commands.sort_by(&:name) width = width(sorted) # The notice's wrap hangs a long description under its column only after # a gap of at least two spaces, and only while the names fill less than # half the line. rows = sorted.map { |command| "#{label(command, width)} #{about(command)}" } [*rows, '', POINTER].join("\n") end
@rbs commands: Array @rbs return: String
(Riffer::Rig::Terminal::Autocomplete::_Entry command, Integer width) → String
Source
# File lib/riffer/rig/terminal/help.rb, line 30 def label(command, width) padding = ' ' * (width - Riffer::Rig::Terminal::Columns.width(command.name)) "#{Riffer::Rig::Terminal::Autocomplete::TRIGGER}#{command.name}#{padding}" end
@rbs command: Riffer::Rig::Terminal::Autocomplete::_Entry @rbs width: Integer @rbs return: String
(Array[Riffer::Rig::Terminal::Autocomplete::_Entry] commands) → Integer
Source
# File lib/riffer/rig/terminal/help.rb, line 23 def width(commands) commands.map { |command| Riffer::Rig::Terminal::Columns.width(command.name) }.max.to_i end
@rbs commands: Array @rbs return: Integer