Class: EYCli::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_cli/term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout) ⇒ Term

Returns a new instance of Term.



7
8
9
10
# File 'lib/ey_cli/term.rb', line 7

def initialize(input = $stdin, output = $stdout)
  HighLine.color_scheme = HighLine::SampleColorScheme.new
  @terminal = HighLine.new(input, output)
end

Instance Attribute Details

#terminalObject (readonly)

Returns the value of attribute terminal.



5
6
7
# File 'lib/ey_cli/term.rb', line 5

def terminal
  @terminal
end

Instance Method Details

#ask(prompt, protected_field = false) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/ey_cli/term.rb', line 50

def ask(prompt, protected_field = false)
  if protected_field
    terminal.ask(prompt) {|q| q.echo = '*'}
  else
    terminal.ask(prompt) {|q| q.readline = true}
  end
end

#choose_resource(collection, message, prompt) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ey_cli/term.rb', line 12

def choose_resource(collection, message, prompt)
  say(message)

  terminal.choose do |menu|
    menu.index = :number
    menu.index_suffix = ' ~> '
    menu.prompt = prompt

    collection.each do |resource|
      menu.choice resource.name
    end
  end
end

#error(message) ⇒ Object



30
31
32
# File 'lib/ey_cli/term.rb', line 30

def error(message)
  terminal.say(%Q{<%= color("#{message}", :error)%>})
end


42
43
44
45
46
47
48
# File 'lib/ey_cli/term.rb', line 42

def print_errors(errors, message)
  error(message)
  errors.each do |key, value|
    alert = value.respond_to?(:join) ? value.join(',') : value.inspect
    error("\t- #{key}: #{alert}")
  end
end

#say(message) ⇒ Object



26
27
28
# File 'lib/ey_cli/term.rb', line 26

def say(message)
  terminal.say(message)
end

#success(message) ⇒ Object



38
39
40
# File 'lib/ey_cli/term.rb', line 38

def success(message)
  terminal.say(%Q{<%= color("#{message}", :debug)%>})
end

#warning(message) ⇒ Object



34
35
36
# File 'lib/ey_cli/term.rb', line 34

def warning(message)
  terminal.say(%Q{<%= color("#{message}", :warning)%>})
end