Module: KmsTools::CLI::Output

Defined in:
lib/kms-tools/cli/output.rb

Overview

Helper functions for terminal interaction

Class Method Summary collapse

Class Method Details

.ask(*args, &block) ⇒ Object



46
47
48
# File 'lib/kms-tools/cli/output.rb', line 46

def self.ask(*args, &block)
  terminal.ask(*args, &block)
end

.color_schemeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kms-tools/cli/output.rb', line 12

def self.color_scheme
  @@color_scheme ||= HighLine::ColorScheme.new(
      :normal => [],
      :error => [:bold, :red],
      :warning => [:bold, :yellow],
      :verbose => [:bold, :magenta],
      :debug => [:bold, :cyan],
      :success => [:bold, :green],
      :addition => [:bold, :green],
      :removal => [:bold, :red],
      :modification => [:bold, :yellow],
  )
end

.format(msg, log_style = :normal) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/kms-tools/cli/output.rb', line 30

def self.format(msg, log_style=:normal)
  if Config.color
    terminal.color(msg.to_s, log_style)
  else
    msg
  end
end

.say(msg, log_style = :normal) ⇒ Object



26
27
28
# File 'lib/kms-tools/cli/output.rb', line 26

def self.say(msg, log_style=:normal)
  terminal.say format(msg, log_style)
end

.say_debug(msg, log_style = :debug) ⇒ Object



42
43
44
# File 'lib/kms-tools/cli/output.rb', line 42

def self.say_debug(msg, log_style=:debug)
  terminal.say format(msg.to_s, log_style) if Config.debug
end

.say_verbose(msg) ⇒ Object



38
39
40
# File 'lib/kms-tools/cli/output.rb', line 38

def self.say_verbose(msg)
  terminal.say format(msg.to_s, 'verbose') if Config.verbose
end

.select_from_list(prompt, options) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/kms-tools/cli/output.rb', line 50

def self.select_from_list(prompt, options)
  puts prompt
  options.each_with_index do |key, index|
    puts "#{index+1}. #{key}"
  end
  choice = Output.ask("? ", Integer) { |q| q.in = 1..options.length }
  options[choice-1]
end

.terminalObject



7
8
9
10
# File 'lib/kms-tools/cli/output.rb', line 7

def self.terminal
  HighLine.color_scheme = color_scheme
  @@terminal ||= HighLine.new
end