module OutputMode::TLDR::Show
Public Instance Methods
Creates an new output
from the verbosity flag. This method only uses +$stdout+ as part of it's output class discovery logic. It does not print to the io directly
The ascii
flag disables the unicode formatting in interactive shells. Non interactive shells use ASCII by default.
The verbose
flag toggles the simplified and verbose outputs in the interactive output. Non-interactive outputs are always verbose
If +$stdout+ is an interactive shell (aka a TTY), then it will display using {OutputMode::Outputs::Templated}. This is intended for human consumption and will obey the provided verbose
flag.
If +$stdout+ is non-interactive, then it will display using {OutputMode::Outputs::Delimited} using tab delimiters. This is intended for consumption by machines. This output ignores the provided verbose
flag as it is always verbose.
The template
overrides the default erb template for interactive sessions. The non_interactive_template
overrides the template for non-interactive sessions.
An interative/ non-interactive output can be forced by setting the interactive
flag to true
/false
respectively
# File lib/output_mode/tldr/show.rb, line 78 def build_output(verbose: nil, ascii: nil, interactive: nil, context: {}, template: OutputMode::DEFAULT_ERB, non_interactive_template: OutputMode::NON_INTERACTIVE_ERB) # Set the interactive and verbose flags if not provided interactive = $stdout.tty? if interactive.nil? verbose = !interactive if verbose.nil? ascii = !interactive if ascii.nil? # Update the rendering context with the verbosity/interactive settings context = context.merge(interactive: interactive, verbose: verbose, ascii: ascii) callables = if verbose # Filter out columns that are explicitly not verbose output_callables.select { |o| o.verbose?(true) } else # Filter out columns that are explicitly verbose output_callables.reject(&:verbose?) end callables = if interactive # Filter out columns that are explicitly not interactive callables.select { |o| o.interactive?(true) } else # Filter out columns that are explicitly interactive callables.reject { |o| o.interactive? } end # Define the templating parameters opts = if ascii && interactive { yes: 'yes', no: 'no', colorize: false, default: '(none)', template: template } elsif interactive { yes: '✓', no: '✕', colorize: TTY::Color.color?, default: '(none)', template: template } else { yes: 'yes', no: 'no', colorize: false, default: '', template: non_interactive_template } end sections = callables.map { |o| o.config[:section] } Outputs::Templated.new(*callables, fields: callables.map { |c| c.config.fetch(:header, 'missing') }, sections: sections, context: context, **opts) end
Register a field when displaying a model @overload register_callable
(header:, verbose: true)
@param header: The human readable key to the field, uses the term 'header' for consistency @param verbose: Whether the field will be shown in the verbose output @param interactive: Whether the field will be show in the interactive output @param section: Define the grouping a callable belongs to. Ignored by default @param modes: Additional modes flags for the callable @yieldparam model The subject the column is describing, some sort of data model
OutputMode::BuilderDSL#register_callable
# File lib/output_mode/tldr/show.rb, line 44 def register_callable(modes: {}, header:, verbose: nil, interactive: nil, section: :default, &b) modes = modes.map { |m| [m, true] }.to_h if modes.is_a? Array super(modes: modes.merge(verbose: verbose, interactive: interactive), header: header, section: section, &b) end