Class: Generators::Avo::SkillsInstallPanel
- Inherits:
-
Object
- Object
- Generators::Avo::SkillsInstallPanel
- Defined in:
- lib/generators/avo/skills_install_panel.rb
Overview
The rails g avo:skills install flow: one question per screen, answered
up front, then the generator runs to completion without interrupting.
Two screen kinds. A :radio moves its selection with the arrows, so down-then-enter picks the second option — pressing space to commit a highlighted row is a step people miss. A :checkbox has an independent state per row, so there space is the toggle and the arrows only move.
Written against io/console from stdlib rather than a prompt gem: avo is a dependency of other people's apps, and a TUI is not worth adding one for.
Defined Under Namespace
Classes: Option, Result, Screen
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(screens, defaults: {}, input: $stdin, output: $stdout) ⇒ SkillsInstallPanel
constructor
defaultsseeds each screen, including one that never becomes visible — its default is then simply the answer. -
#run ⇒ Object
stepcarries the direction, so a skipped screen is stepped over the way it was entered — otherwise going back would walk into it forwards.
Constructor Details
#initialize(screens, defaults: {}, input: $stdin, output: $stdout) ⇒ SkillsInstallPanel
defaults seeds each screen, including one that never becomes visible —
its default is then simply the answer.
35 36 37 38 39 40 41 |
# File 'lib/generators/avo/skills_install_panel.rb', line 35 def initialize(screens, defaults: {}, input: $stdin, output: $stdout) @screens = screens @input = input @output = output @answers = {} @screens.each { |s| @answers[s.key] = defaults.fetch(s.key) { initial_for(s) } } end |
Class Method Details
.interactive? ⇒ Boolean
29 30 31 |
# File 'lib/generators/avo/skills_install_panel.rb', line 29 def self.interactive? $stdin.tty? && $stdout.tty? end |
Instance Method Details
#run ⇒ Object
step carries the direction, so a skipped screen is stepped over the
way it was entered — otherwise going back would walk into it forwards.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/avo/skills_install_panel.rb', line 45 def run index = 0 step = 1 while index < @screens.length screen = @screens[index] unless visible?(screen) index += step next end case ask(screen, first: first_visible?(index)) when :back then step = -1 when :cancel then return Result.new({}, true) else step = 1 end index += step end Result.new(@answers, false) end |