Class: DialogTui::UserAction::UserActions
- Inherits:
-
Object
- Object
- DialogTui::UserAction::UserActions
- Defined in:
- lib/dialog_tui/user_action.rb
Constant Summary collapse
- DSL_METHODS =
%i[ ctrl_c enter esc up down left right ]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ UserActions
constructor
A new instance of UserActions.
- #run ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ UserActions
Returns a new instance of UserActions.
21 22 23 24 |
# File 'lib/dialog_tui/user_action.rb', line 21 def initialize @actions = [] yield self end |
Class Method Details
.run(&block) ⇒ Object
17 18 19 |
# File 'lib/dialog_tui/user_action.rb', line 17 def self.run &block new(&block).run end |
Instance Method Details
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dialog_tui/user_action.rb', line 46 def run loop { input = UserAction.read_char matched = @actions.select { |x| x.matches? input } if matched.any? matched.each &:call break else # just ignore and wait for next input end } end |