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, 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", "      \#{Command.list(@@commands)}\n\n      For more information, please see the following Home page.\n      http://github.com/flum1025/flumtter3\n      This software is released under the MIT License\n      Copyright \u00A9 @flum_ 2016\n    EOF\n  else\n    @@commands.each do |command|\n      if m = input.match(command.command)\n        return command.call(m, twitter)\n      end\n    end\n    puts \"Command not found\".color\n  end\nend\n").show

.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