Class: EYCli::Term
- Inherits:
-
Object
- Object
- EYCli::Term
- Defined in:
- lib/ey_cli/term.rb
Instance Attribute Summary collapse
-
#terminal ⇒ Object
readonly
Returns the value of attribute terminal.
Instance Method Summary collapse
- #ask(prompt, protected_field = false) ⇒ Object
- #choose_resource(collection, message, prompt) ⇒ Object
- #error(message) ⇒ Object
-
#initialize(input = $stdin, output = $stdout) ⇒ Term
constructor
A new instance of Term.
- #print_errors(errors, message) ⇒ Object
- #say(message) ⇒ Object
- #success(message) ⇒ Object
- #warning(message) ⇒ Object
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
#terminal ⇒ Object (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, , prompt) say() terminal.choose do || .index = :number .index_suffix = ' ~> ' .prompt = prompt collection.each do |resource| .choice resource.name end end end |
#error(message) ⇒ Object
30 31 32 |
# File 'lib/ey_cli/term.rb', line 30 def error() terminal.say(%Q{<%= color("#{}", :error)%>}) end |
#print_errors(errors, message) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ey_cli/term.rb', line 42 def print_errors(errors, ) error() 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() terminal.say() end |
#success(message) ⇒ Object
38 39 40 |
# File 'lib/ey_cli/term.rb', line 38 def success() terminal.say(%Q{<%= color("#{}", :debug)%>}) end |
#warning(message) ⇒ Object
34 35 36 |
# File 'lib/ey_cli/term.rb', line 34 def warning() terminal.say(%Q{<%= color("#{}", :warning)%>}) end |