module FerretsOnFire::DSL::LoggerDSL

Constants

COLORS
DEFAULT_PREFIXES
FANCY_PREFIXES
SUFFIXES

Public Instance Methods

action(msg) { |: nil| ... } click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 130
       def action(msg)
  print log(msg, :action) if $stdout.tty?

  return_value = block_given? ? yield : nil

  puts "\r#{log(msg, :success)}"
  return_value
end
banner(string, color: :white, background: :black) click to toggle source
choose(msg, options, default: nil) click to toggle source

Generates a question with the specified msg. If output is true (default) it will be printed. @param [String] msg The message @param [Array<Object>] options Array of option @return [Object] The chosen option value

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 79
       def choose(msg, options, default: nil)
  default_idx = default.nil? ? 0 : options.index(default)

  get_prompt.select(log(msg + (default.nil? ? '' : " (Default: #{default})"), :question), per_page: 7) do |menu|
    menu.default default_idx + 1
    options.each { |opt| menu.choice opt }
  end
end
crash(msg, output, command: nil, exit: true) click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 109
       def crash(msg, output, command: nil, exit: true)
  puts
  error msg
  puts
  puts '=====================[ CRASH REPORT ]====================='.red

  unless command.nil?
    puts
    puts 'COMMAND: '.red
    puts command
  end

  puts
  puts 'ERROR:'.red
  puts output
  puts
  puts '=========================================================='.red
  puts
  exit 1 if exit
end
error(msg) click to toggle source

Outputs a error message @param [String] msg The message

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 62
       def error(msg)
  puts log(msg, :error)
end
highlight(str) click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 104
       def highlight(str)
  str.light_blue
end
info(msg) click to toggle source

Outputs a info message @param [String] msg The message

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 49
       def info(msg)
  puts log(msg, :info)
end
linebreak() click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 100
       def linebreak
  puts
end
success(msg) click to toggle source

Outputs a success message @param [String] msg The message

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 70
       def success(msg)
  puts log(msg, :success)
end
warn(msg) click to toggle source

Outputs a warning message @param [String] msg The message

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 55
       def warn(msg)
  puts log(msg, :warn)
end
yes_no(msg, default = true) click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 88
       def yes_no(msg, default = true)
  get_prompt.yes?(log(msg, :question)) do |q|
    q.default default
  end
end

Private Instance Methods

_shell_action(msg) { || ... } click to toggle source

@param [String] msg Message to display

# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 141
        def _shell_action(msg)
  print log(msg, :action, '  ...  ') if $stdout.tty?
  cmd_output = ''
  bm = ::Benchmark.measure { cmd_output = yield }
  time = '%.2f' % bm.real.round(2)
  info = "#{time.rjust(6)}s"
  puts ($stdout.tty? ? "\r" : '') + log(msg, :success, info)

  [cmd_output, $?.to_i]
end
get_prompt() click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 95
        def get_prompt
  TTY::Prompt.new(help_color: :white)
end
log(msg, type, info = '') click to toggle source
# File lib/ferrets_on_fire/dsl/logger_dsl.rb, line 153
        def log(msg, type, info = '')
  prefix = (RUBY_PLATFORM.include?('darwin') && $stdout.tty? ? FANCY_PREFIXES : DEFAULT_PREFIXES)[type]
  suffix = SUFFIXES[type]
  color = COLORS[type]

  info = info.empty? ? '' : "[#{info}] "

  output = "#{prefix} #{info}#{msg}#{suffix}"
  color.nil? ? output : output.send(color)
end