Class: ChefLicensing::TUIEngine::TUIPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/tui_engine/tui_prompt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inputObject

Returns the value of attribute input.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10

def input
  @input
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_prompt.rb', line 10

def logger
  @logger
end

#outputObject

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_promptObject

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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.ask(message)
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(messages, prompt_attributes)
  header, choices_list = fetch_header_and_choices(messages, :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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.error(message)
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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.ok(message)
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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.say(message)
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(messages, prompt_attributes)
  header, choices_list = fetch_header_and_choices(messages, :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(messages, prompt_attributes)
  Array(messages).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(messages, prompt_attributes)
  timeout_helper(messages, 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(messages, prompt_attributes)
  timeout_helper(messages, 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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.warn(message)
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(messages, prompt_attributes)
  message = Array(messages).first
  @tty_prompt.yes?(message)
end