Class: CreateRubyGem::UI::Prompter
- Inherits:
-
Object
- Object
- CreateRubyGem::UI::Prompter
- Defined in:
- lib/create_ruby_gem/ui/prompter.rb
Overview
Thin wrapper around cli-ui for all user interaction.
Every prompt the wizard issues goes through this class, making it easy to inject a test double.
Class Method Summary collapse
-
.setup! ⇒ void
Enables the
cli-uistdout router and applies the Ctrl+B patch.
Instance Method Summary collapse
-
#choose(question, options:, default: nil) ⇒ String
Presents a single-choice list.
-
#confirm(question, default: true) ⇒ Boolean
Prompts for yes/no confirmation.
-
#frame(title) { ... } ⇒ void
Opens a visual frame with a title.
-
#initialize(out: $stdout) ⇒ Prompter
constructor
A new instance of Prompter.
-
#say(message) ⇒ void
Prints a formatted message to the output stream.
-
#text(question, default: nil, allow_empty: true) ⇒ String
Prompts for free-text input.
Constructor Details
#initialize(out: $stdout) ⇒ Prompter
Returns a new instance of Prompter.
24 25 26 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 24 def initialize(out: $stdout) @out = out end |
Class Method Details
.setup! ⇒ void
This method returns an undefined value.
Enables the cli-ui stdout router and applies the Ctrl+B patch.
Call once before creating a Prompter instance. Idempotent.
18 19 20 21 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 18 def self.setup! ::CLI::UI::StdoutRouter.enable BackNavigationPatch.apply! end |
Instance Method Details
#choose(question, options:, default: nil) ⇒ String
Presents a single-choice list.
43 44 45 46 47 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 43 def choose(question, options:, default: nil) ::CLI::UI.ask(question, options: , default: default, filter_ui: false) rescue BackKeyPressed Wizard::BACK end |
#confirm(question, default: true) ⇒ Boolean
Prompts for yes/no confirmation.
64 65 66 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 64 def confirm(question, default: true) ::CLI::UI.confirm(question, default: default) end |
#frame(title) { ... } ⇒ void
This method returns an undefined value.
Opens a visual frame with a title.
33 34 35 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 33 def frame(title, &) ::CLI::UI::Frame.open(title, &) end |
#say(message) ⇒ void
This method returns an undefined value.
Prints a formatted message to the output stream.
72 73 74 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 72 def say() @out.puts(::CLI::UI.fmt()) end |
#text(question, default: nil, allow_empty: true) ⇒ String
Prompts for free-text input.
55 56 57 |
# File 'lib/create_ruby_gem/ui/prompter.rb', line 55 def text(question, default: nil, allow_empty: true) ::CLI::UI.ask(question, default: default, allow_empty: allow_empty) end |