Class: Tomo::Console
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/tomo/console.rb,
lib/tomo/console/menu.rb,
lib/tomo/console/key_reader.rb,
lib/tomo/console/non_interactive_error.rb
Defined Under Namespace
Classes: KeyReader, Menu, NonInteractiveError
Instance Method Summary
collapse
Constructor Details
#initialize(env = ENV, input = $stdin, output = $stdout) ⇒ Console
Returns a new instance of Console.
18
19
20
21
22
|
# File 'lib/tomo/console.rb', line 18
def initialize(env=ENV, input=$stdin, output=$stdout)
@env = env
@input = input
@output = output
end
|
Instance Method Details
#interactive? ⇒ Boolean
24
25
26
|
# File 'lib/tomo/console.rb', line 24
def interactive?
input.respond_to?(:raw) && input.respond_to?(:tty?) && input.tty? && !ci?
end
|
38
39
40
41
42
|
# File 'lib/tomo/console.rb', line 38
def (question, choices:)
assert_interactive
Menu.new(question, choices).prompt_for_selection
end
|
#prompt(question) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/tomo/console.rb', line 28
def prompt(question)
assert_interactive
output.print question
line = input.gets
raise_non_interactive if line.nil?
line.chomp
end
|