Class: DialogTui::UserAction::UserActions

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize {|_self| ... } ⇒ UserActions

Returns a new instance of UserActions.

Yields:

  • (_self)

Yield Parameters:



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

#runObject



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