class Samovar::Output::UsageFormatter
Formats and prints usage information to a terminal.
Uses the ‘mapping` gem to handle different output object types with custom formatting rules.
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/usage_formatter.rb, line 39 def initialize(output) @output = output @width = 80 @first = true @terminal = Console::Terminal.for(@output) @terminal[:header] = @terminal.style(nil, nil, :bright) @terminal[:description] = @terminal.style(:blue) @terminal[:error] = @terminal.style(:red) end
Initialize a new usage formatter.
@parameter rows [Rows] The rows to format. @parameter output [IO] The output stream to print to.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/usage_formatter.rb, line 27 def self.print(rows, output) formatter = self.new(output) yield formatter if block_given? formatter.print(rows) end
Print usage information to the output.
@parameter rows [Rows] The rows to format and print. @parameter output [IO] The output stream to print to. @yields {|formatter| …} Optional block to customize the formatter.
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/usage_formatter.rb, line 84 def print(rows, first: @first) @first = first map(rows) end
Print the formatted usage output.