#!/usr/bin/env ruby #============================================================================== # Copyright 2020 William McCumstie # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #============================================================================== require "bundler/setup" require "output_mode" require 'erb' module DemoIndex extend OutputMode::TLDR::Index register_callable(header: 'Integer', row_color: [:yellow, :bold]) { |i| i } register_callable(header: 'Standard', header_color: [:strikethrough] ) { 'always visible' } register_callable(header: 'Verbose', verbose: true) { 'verbose visible' } register_callable(header: 'Simplified', verbose: false) { 'simplified visible' } register_callable(header: 'Yes/True') { true } register_callable(header: 'No/False', row_color: [:clear]) { false } register_callable(header: 'Missing') { nil } end module DemoShow extend OutputMode::TLDR::Show register_callable(header: 'Integer') { |i| i } register_callable(header: 'Standard') { 'always visible' } register_callable(header: 'Verbose', verbose: true) { 'verbose visible' } register_callable(header: 'Simplified', verbose: false) { 'simplified visible' } register_callable(header: 'Yes/True', section: :boolean) { true } register_callable(header: 'No/False', section: :boolean) { false } register_callable(header: 'Missing') { nil } end data = [1, 2, 3] other_template = ERB.new(<<~TEMPLATE, nil, '-') # Non boolean values <% each(:other) do |value, field:, padding:, **_| -%> <%= padding -%><%= pastel.blue.bold field -%><%= pastel.bold ':' -%> <%= pastel.green value %> <% end -%> # Boolean Values <% each(:boolean) do |value, field:, padding:, **_| -%> <%= padding -%><%= pastel.blue.bold field -%><%= pastel.bold ':' -%> <%= pastel.green value %> <% end -%> TEMPLATE puts <<~EOF #============================================================================== #============================================================================== # INDEX OUTPUTS #============================================================================== #============================================================================== #============================================================================== # Default Demo Index # Simplified in interactive shells, verbose in non-interactive #============================================================================== #{DemoIndex.build_output.render(*data)} #============================================================================== # Demo Verbose Index #============================================================================== #{DemoIndex.build_output(verbose: true).render(*data)} #============================================================================== # Demo "Simplified" Index #============================================================================== #{DemoIndex.build_output(verbose: false).render(*data)} #============================================================================== # Force Interactive # Always print as if the shell is interactive #============================================================================== #{DemoIndex.build_output(interactive: true).render(*data)} #============================================================================== # Force Non-Interactive # Always print as if the shell is non-interactive #============================================================================== #{DemoIndex.build_output(interactive: false).render(*data)} #============================================================================== # Demo ASCII Index #============================================================================== #{DemoIndex.build_output(ascii: true).render(*data)} #============================================================================== #============================================================================== # SHOW OUTPUTS #============================================================================== #============================================================================== #============================================================================== # Default Settings # Simplified in interactive shells, verbose in non-interactive #============================================================================== #{DemoShow.build_output.render(*data)} #============================================================================== # Demo Verbose Show #============================================================================== #{DemoShow.build_output(verbose: true).render(*data)} #============================================================================== # Demo "Simplified" Show #============================================================================== #{DemoShow.build_output(verbose: false).render(*data)} #============================================================================== # Force Interactive # Always print as if the shell is interactive #============================================================================== #{DemoShow.build_output(interactive: true).render(*data)} #============================================================================== # Force Non-Interactive # Always print as if the shell is non-interactive #============================================================================== #{DemoShow.build_output(interactive: false).render(*data)} #============================================================================== # Demo ASCII Index #============================================================================== #{DemoShow.build_output(ascii: true).render(*data)} #============================================================================== # Group the boolean value separately # NOTE: This only occurs in interactive mode # Non-Interactive sessions have a fix order #============================================================================== #{DemoShow.build_output(template: other_template).render(*data)} EOF