Module: OutputMode::TLDR::Index
- Includes:
- BuilderDSL
- Defined in:
- lib/output_mode/tldr/index.rb
Instance Method Summary collapse
-
#build_output(verbose: nil, ascii: nil, interactive: nil, header_color: [:blue, :bold], row_color: :green, context: {}) ⇒ Object
Creates an new
output
from the verbosity flag. -
#register_callable(header: , verbose: true) {|model| ... } ⇒ Object
(also: #register_column)
Register a new column in the Index table.
Methods included from BuilderDSL
Instance Method Details
#build_output(verbose: nil, ascii: nil, interactive: nil, header_color: [:blue, :bold], row_color: :green, context: {}) ⇒ Object
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 output 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 Outputs::Tabulated. This is intended for human consumption and will obey the provided verbose
flag.
If $stdout is non-interactive, then it will display using Outputs::Delimited using tab delimiters. This is intended for consumption by machines. This output ignores the provided verbose
flag as it is always verbose.
An interative/ non-interactive output can be forced by setting the interactive
flag to true
/false
respectively
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/output_mode/tldr/index.rb', line 74 def build_output(verbose: nil, ascii: nil, interactive: nil, header_color: [:blue, :bold], row_color: :green, context: {}) # 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 if interactive # Creates the human readable output opts = if ascii { yes: 'yes', no: 'no', renderer: :ascii } else { yes: '✓', no: '✕', renderer: :unicode, colorize: TTY::Color.color?, header_color: header_color, row_color: row_color } end Outputs::Tabulated.new(*callables, rotate: false, padding: [0,1], default: '(none)', context: context, **opts ) else # Creates the machine readable output Outputs::Delimited.new(*callables, col_sep: "\t", yes: 'yes', no: 'no', default: nil, context: context) end end |
#register_callable(header: , verbose: true) {|model| ... } ⇒ Object Also known as: register_column
Register a new column in the Index table
43 44 45 46 47 48 49 50 |
# File 'lib/output_mode/tldr/index.rb', line 43 def register_callable(modes: {}, header:, verbose: nil, interactive: nil, header_color: nil, row_color: nil, &b) modes = modes.map { |m| [m, true] }.to_h if modes.is_a? Array super(modes: modes.merge(verbose: verbose, interactive: interactive), header: header, header_color: header_color, row_color: row_color, &b) end |