Class: Omaship::HarborPicker
- Inherits:
-
Object
- Object
- Omaship::HarborPicker
- Includes:
- LinearPickerControls
- Defined in:
- lib/omaship/harbor_picker.rb
Instance Method Summary collapse
-
#initialize(harbors:, out: $stdout, input: $stdin) ⇒ HarborPicker
constructor
A new instance of HarborPicker.
- #pick ⇒ Object
Constructor Details
#initialize(harbors:, out: $stdout, input: $stdin) ⇒ HarborPicker
Returns a new instance of HarborPicker.
7 8 9 10 11 12 |
# File 'lib/omaship/harbor_picker.rb', line 7 def initialize(harbors:, out: $stdout, input: $stdin) @harbors = Array(harbors) @out = out @input = input @index = 0 end |
Instance Method Details
#pick ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/omaship/harbor_picker.rb', line 14 def pick render loop do key = (@input) case key when :previous @index = (@index - 1) % @harbors.size render when :next @index = (@index + 1) % @harbors.size render when :enter, "q" return @harbors.fetch(@index).fetch("id") when :ctrl_c raise Interrupt end end ensure @out.print "\e[?25h" @out.puts if @rendered_lines end |