module Wpxf::Cli::Output

Methods for handling output to the screen.

Attributes

indent[RW]
indent_level[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/wpxf/cli/output.rb, line 7
def initialize
  super
  self.indent = '  '
  self.indent_level = 1
end

Public Instance Methods

calculate_col_widths(data) click to toggle source
# File lib/wpxf/cli/output.rb, line 77
def calculate_col_widths(data)
  widths = {}
  data.each do |row|
    row.keys.each do |col|
      if widths[col].nil? || row[col].to_s.length > widths[col]
        widths[col] = row[col].to_s.length
      end
    end
  end
  widths
end
indent_cursor(level = 1) { || ... } click to toggle source
# File lib/wpxf/cli/output.rb, line 13
def indent_cursor(level = 1)
  self.indent_level += level
  yield
  self.indent_level -= level
end
indent_without_wrap(value) click to toggle source
# File lib/wpxf/cli/output.rb, line 28
def indent_without_wrap(value)
  value.gsub(/\n/, "\n#{indent * indent_level}")
end
print_bad(msg) click to toggle source
print_good(msg) click to toggle source
print_header_separator(widths) click to toggle source
print_info(msg) click to toggle source
print_std(msg) click to toggle source
print_table(data, pad_with_new_lines = false) click to toggle source
print_table_header(data, col_widths) click to toggle source
print_table_row(data, widths) click to toggle source
print_warning(msg) click to toggle source
remove_new_lines_and_wrap_text(value, padding = 0, width = 78) click to toggle source
# File lib/wpxf/cli/output.rb, line 19
def remove_new_lines_and_wrap_text(value, padding = 0, width = 78)
  wrap_text(value.tr("\n", ''), padding, width)
end
wrap_text(value, padding = 0, width = 78) click to toggle source
# File lib/wpxf/cli/output.rb, line 23
def wrap_text(value, padding = 0, width = 78)
  value.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n#{indent * indent_level}#{' ' * padding}").chomp
       .gsub(/\s+$/, '')
end