Class: Flumtter::Keyboard

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/flumtter/app/core/keyboard.rb

Constant Summary collapse

@@commands =
[]

Class Method Summary collapse

Methods included from Util

command_value_regexp, dialog_for_index, error, error_handler, id2obj, if_tweet, index_regexp, index_with_dialog, logger, on_event, parse_index, parse_time, sarastire, sarastire_user, screen_name_regexp

Class Method Details

.add(command, help, &blk) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/flumtter/app/core/keyboard.rb', line 41

def add(command, help, &blk)
  @@commands << Command.new(command, help) do |*args|
    begin
      blk.call(*args)
    rescue SystemExit => e
      raise e
    rescue Exception => e
      error e
    end
  end
end

.callback(input, twitter) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flumtter/app/core/keyboard.rb', line 21

def callback(input, twitter)
  if input == "?"
    Window::Popup.new("Command List", <<~EOF).show
      #{Command.list(@@commands)}

      For more information, please see the following Home page.
      http://github.com/flum1025/flumtter3
      This software is released under the MIT License
      Copyright © @flum_ 2016
    EOF
  else
    @@commands.each do |command|
      if m = input.match(command.command)
        return command.call(m, twitter)
      end
    end
    puts "Command not found".color
  end
end

.input(twitter) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/flumtter/app/core/keyboard.rb', line 10

def input(twitter)
  loop do
    input = STDIN.noecho(&:gets)
    next if input.nil?
    twitter.pause
    callback(input.chomp, twitter)
    twitter.resume
  end
rescue Interrupt
end