Class: ChefLicensing::TUIEngine::TUIPrompt
- Inherits:
-
Object
- Object
- ChefLicensing::TUIEngine::TUIPrompt
- Defined in:
- lib/chef-licensing/tui_engine/tui_prompt.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#output ⇒ Object
Returns the value of attribute output.
-
#tty_prompt ⇒ Object
Returns the value of attribute tty_prompt.
Instance Method Summary collapse
-
#ask(messages, prompt_attributes) ⇒ Object
ask prompts the user to enter a value.
-
#enum_select(messages, prompt_attributes) ⇒ Object
enum_select prompts the user to select an option from a list of options.
-
#error(messages, prompt_attributes) ⇒ Object
error prints the given message to the output stream in red color.
-
#initialize(opts = {}) ⇒ TUIPrompt
constructor
A new instance of TUIPrompt.
-
#ok(messages, prompt_attributes) ⇒ Object
ok prints the given message to the output stream in green color.
-
#say(messages, prompt_attributes) ⇒ Object
say prints the given message to the output stream.
-
#select(messages, prompt_attributes) ⇒ Object
select prompts the user to select an option from a list of options.
- #silent(messages, prompt_attributes) ⇒ Object
- #timeout_select(messages, prompt_attributes) ⇒ Object
-
#timeout_yes(messages, prompt_attributes) ⇒ Object
timeout_yes prompt wraps yes prompt with timeout.
-
#warn(messages, prompt_attributes) ⇒ Object
warn prints the given message to the output stream in yellow color.
-
#yes(messages, prompt_attributes) ⇒ Object
yes prompts the user with a yes/no question and returns true if the user answers yes and false if the user answers no.
Constructor Details
#initialize(opts = {}) ⇒ TUIPrompt
Returns a new instance of TUIPrompt.
12 13 14 15 16 17 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 12 def initialize(opts = {}) @output = ChefLicensing::Config.output @input = opts[:input] || STDIN @logger = ChefLicensing::Config.logger @tty_prompt = opts[:prompt] || TTY::Prompt.new(track_history: false, active_color: :bold, interrupt: :exit, output: output, input: input) end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
10 11 12 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10 def input @input end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10 def logger @logger end |
#output ⇒ Object
Returns the value of attribute output.
10 11 12 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10 def output @output end |
#tty_prompt ⇒ Object
Returns the value of attribute tty_prompt.
10 11 12 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10 def tty_prompt @tty_prompt end |
Instance Method Details
#ask(messages, prompt_attributes) ⇒ Object
ask prompts the user to enter a value. prompt_attributes is added to extend the prompt in future.
72 73 74 75 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 72 def ask(, prompt_attributes) = Array().first @tty_prompt.ask() end |
#enum_select(messages, prompt_attributes) ⇒ Object
enum_select prompts the user to select an option from a list of options. prompt_attributes is added to extend the prompt in future.
65 66 67 68 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 65 def enum_select(, prompt_attributes) header, choices_list = fetch_header_and_choices(, :enum_select) @tty_prompt.enum_select(header, choices_list) end |
#error(messages, prompt_attributes) ⇒ Object
error prints the given message to the output stream in red color. prompt_attributes is added to extend the prompt in future.
51 52 53 54 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 51 def error(, prompt_attributes) = Array().first @tty_prompt.error() end |
#ok(messages, prompt_attributes) ⇒ Object
ok prints the given message to the output stream in green color. prompt_attributes is added to extend the prompt in future.
37 38 39 40 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 37 def ok(, prompt_attributes) = Array().first @tty_prompt.ok() end |
#say(messages, prompt_attributes) ⇒ Object
say prints the given message to the output stream. default prompt_type of an interaction is say. prompt_attributes is added to extend the prompt in future.
30 31 32 33 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 30 def say(, prompt_attributes) = Array().first @tty_prompt.say() end |
#select(messages, prompt_attributes) ⇒ Object
select prompts the user to select an option from a list of options. prompt_attributes is added to extend the prompt in future.
58 59 60 61 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 58 def select(, prompt_attributes) header, choices_list = fetch_header_and_choices(, :select) @tty_prompt.select(header, choices_list) end |
#silent(messages, prompt_attributes) ⇒ Object
87 88 89 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 87 def silent(, prompt_attributes) Array().first end |
#timeout_select(messages, prompt_attributes) ⇒ Object
83 84 85 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 83 def timeout_select(, prompt_attributes) timeout_helper(, method(:select), prompt_attributes) end |
#timeout_yes(messages, prompt_attributes) ⇒ Object
timeout_yes prompt wraps yes prompt with timeout. prompt_attributes is added to extend the prompt in future.
79 80 81 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 79 def timeout_yes(, prompt_attributes) timeout_helper(, method(:yes), prompt_attributes) end |
#warn(messages, prompt_attributes) ⇒ Object
warn prints the given message to the output stream in yellow color. prompt_attributes is added to extend the prompt in future.
44 45 46 47 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 44 def warn(, prompt_attributes) = Array().first @tty_prompt.warn() end |
#yes(messages, prompt_attributes) ⇒ Object
yes prompts the user with a yes/no question and returns true if the user answers yes and false if the user answers no. prompt_attributes is added to extend the prompt in future.
22 23 24 25 |
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 22 def yes(, prompt_attributes) = Array().first @tty_prompt.yes?() end |