Class: EacCli::Speaker

Inherits:
Object show all
Includes:
EacRubyUtils::Speaker::Receiver
Defined in:
lib/eac_cli/speaker/_constants.rb,
lib/eac_cli/speaker.rb,
lib/eac_cli/speaker/list.rb,
lib/eac_cli/speaker/options.rb

Overview

Defined Under Namespace

Modules: Options Classes: List

Constant Summary collapse

STDERR =
::EacRubyUtils::ByReference.new { $stderr }
STDIN =
::EacRubyUtils::ByReference.new { $stdin }
STDOUT =
::EacRubyUtils::ByReference.new { $stdout }

Instance Method Summary collapse

Instance Method Details

#fatal_error(string) ⇒ Object



26
27
28
29
# File 'lib/eac_cli/speaker.rb', line 26

def fatal_error(string)
  puts "ERROR: #{string}".white.on_red
  Kernel.exit 1
end

#info(string) ⇒ Object



39
40
41
# File 'lib/eac_cli/speaker.rb', line 39

def info(string)
  puts string.to_s.white
end

#infom(string) ⇒ Object



43
44
45
# File 'lib/eac_cli/speaker.rb', line 43

def infom(string)
  puts string.to_s.light_yellow
end

#infov(*args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/eac_cli/speaker.rb', line 66

def infov(*args)
  r = []
  args.each_with_index do |v, i|
    if i.even?
      r << "#{v}: ".cyan
    else
      r.last << v.to_s
    end
  end
  puts r.join(', ')
end

#input(question, options = {}) ⇒ Object

Options:

+bool+ ([Boolean], default: +false+): requires a answer "yes" or "no".
+list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
+noecho+ ([Boolean], default: +false+): does not output answer.


55
56
57
58
59
60
61
62
63
64
# File 'lib/eac_cli/speaker.rb', line 55

def input(question, options = {})
  bool, list, noecho = options.to_options_consumer.consume_all(:bool, :list, :noecho)
  if list
    request_from_list(question, list, noecho)
  elsif bool
    request_from_bool(question, noecho)
  else
    request_string(question, noecho)
  end
end

#out(string = '') ⇒ Object



22
23
24
# File 'lib/eac_cli/speaker.rb', line 22

def out(string = '')
  out_out.write(string.to_s)
end

#puts(string = '') ⇒ Object



16
17
18
19
20
# File 'lib/eac_cli/speaker.rb', line 16

def puts(string = '')
  string.to_s.each_line do |line|
    err_out.puts(err_line_prefix.to_s + line)
  end
end

#success(string) ⇒ Object



78
79
80
# File 'lib/eac_cli/speaker.rb', line 78

def success(string)
  puts string.to_s.green
end

#title(string) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/eac_cli/speaker.rb', line 31

def title(string)
  string = string.to_s
  puts(('-' * (8 + string.length)).green)
  puts("--- #{string} ---".green)
  puts(('-' * (8 + string.length)).green)
  puts
end

#warn(string) ⇒ Object



47
48
49
# File 'lib/eac_cli/speaker.rb', line 47

def warn(string)
  puts string.to_s.yellow
end