rum 0.0.1-universal-darwin-10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGELOG +3 -0
  2. data/README +30 -0
  3. data/Rakefile +134 -0
  4. data/bin/rum-client +124 -0
  5. data/doc/basic.rb +10 -0
  6. data/doc/doc.html +602 -0
  7. data/doc/example.rb +59 -0
  8. data/doc/reference.rb +415 -0
  9. data/doc/resources/bg.png +0 -0
  10. data/doc/resources/bottom.png +0 -0
  11. data/doc/resources/build.rb +235 -0
  12. data/doc/resources/doc.haml +167 -0
  13. data/doc/resources/emacs-auto-completion.png +0 -0
  14. data/doc/resources/flash.png +0 -0
  15. data/doc/resources/highlight.css +94 -0
  16. data/doc/resources/intro.rb +17 -0
  17. data/doc/resources/left.png +0 -0
  18. data/doc/resources/logo.png +0 -0
  19. data/doc/resources/screen.css +420 -0
  20. data/doc/resources/screenshot.png +0 -0
  21. data/doc/resources/top.png +0 -0
  22. data/ext/mac/keyboard_hook/English.lproj/InfoPlist.strings +0 -0
  23. data/ext/mac/keyboard_hook/Event.h +17 -0
  24. data/ext/mac/keyboard_hook/Event.m +18 -0
  25. data/ext/mac/keyboard_hook/EventTap.h +11 -0
  26. data/ext/mac/keyboard_hook/EventTap.m +77 -0
  27. data/ext/mac/keyboard_hook/Info.plist +26 -0
  28. data/ext/mac/keyboard_hook/KeyboardHook.xcodeproj/TemplateIcon.icns +0 -0
  29. data/ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj +323 -0
  30. data/ext/mac/keyboard_hook/KeyboardHook_Prefix.pch +7 -0
  31. data/ext/mac/keyboard_hook/version.plist +16 -0
  32. data/ext/windows/keyboard_hook/extconf.rb +2 -0
  33. data/ext/windows/keyboard_hook/keyboard_hook.c +126 -0
  34. data/ext/windows/system/autohotkey_stuff.c +255 -0
  35. data/ext/windows/system/autohotkey_stuff.h +2 -0
  36. data/ext/windows/system/clipboard_watcher.c +58 -0
  37. data/ext/windows/system/clipboard_watcher.h +2 -0
  38. data/ext/windows/system/extconf.rb +3 -0
  39. data/ext/windows/system/input_box.c +239 -0
  40. data/ext/windows/system/input_box.h +4 -0
  41. data/ext/windows/system/system.c +273 -0
  42. data/lib/rum.rb +4 -0
  43. data/lib/rum/apps.rb +4 -0
  44. data/lib/rum/barrel.rb +157 -0
  45. data/lib/rum/barrel/emacs.rb +44 -0
  46. data/lib/rum/barrel/emacs_client.rb +74 -0
  47. data/lib/rum/core.rb +125 -0
  48. data/lib/rum/dsl.rb +109 -0
  49. data/lib/rum/gui.rb +93 -0
  50. data/lib/rum/help.rb +128 -0
  51. data/lib/rum/hotkey_core.rb +479 -0
  52. data/lib/rum/mac.rb +18 -0
  53. data/lib/rum/mac/app.rb +4 -0
  54. data/lib/rum/mac/apps.rb +19 -0
  55. data/lib/rum/mac/gui.rb +26 -0
  56. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Info.plist +28 -0
  57. data/lib/rum/mac/gui/CocoaDialog.app/Contents/MacOS/CocoaDialog +0 -0
  58. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Info.plist +28 -0
  59. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/InfoPlist.strings +0 -0
  60. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Inputbox.nib/classes.nib +51 -0
  61. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Inputbox.nib/info.nib +16 -0
  62. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib +0 -0
  63. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/MainMenu.nib/classes.nib +7 -0
  64. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/MainMenu.nib/info.nib +21 -0
  65. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/MainMenu.nib/info.nib.orig +21 -0
  66. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/MainMenu.nib/objects.nib +0 -0
  67. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/MainMenu.nib/objects.nib.orig +0 -0
  68. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Msgbox.nib/classes.nib +27 -0
  69. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Msgbox.nib/info.nib +16 -0
  70. data/lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Msgbox.nib/keyedobjects.nib +0 -0
  71. data/lib/rum/mac/gui/Growl.framework/Growl +0 -0
  72. data/lib/rum/mac/gui/Growl.framework/Versions/A/Growl +0 -0
  73. data/lib/rum/mac/gui/Growl.framework/Versions/A/Headers/Growl.h +6 -0
  74. data/lib/rum/mac/gui/Growl.framework/Versions/A/Headers/GrowlApplicationBridge-Carbon.h +780 -0
  75. data/lib/rum/mac/gui/Growl.framework/Versions/A/Headers/GrowlApplicationBridge.h +575 -0
  76. data/lib/rum/mac/gui/Growl.framework/Versions/A/Headers/GrowlDefines.h +348 -0
  77. data/lib/rum/mac/gui/Growl.framework/Versions/A/Resources/Info.plist +24 -0
  78. data/lib/rum/mac/gui/growl.rb +54 -0
  79. data/lib/rum/mac/irb/completion.rb +207 -0
  80. data/lib/rum/mac/keyboard_hook.rb +73 -0
  81. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/KeyboardHook +0 -0
  82. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/KeyboardHook +0 -0
  83. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/English.lproj/InfoPlist.strings +0 -0
  84. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/Info.plist +22 -0
  85. data/lib/rum/mac/layouts.rb +146 -0
  86. data/lib/rum/mac/system.rb +45 -0
  87. data/lib/rum/remote.rb +48 -0
  88. data/lib/rum/server.rb +92 -0
  89. data/lib/rum/windows.rb +23 -0
  90. data/lib/rum/windows/app.rb +72 -0
  91. data/lib/rum/windows/apps.rb +25 -0
  92. data/lib/rum/windows/gui.rb +116 -0
  93. data/lib/rum/windows/keyboard.rb +80 -0
  94. data/lib/rum/windows/keyboard_hook.rb +20 -0
  95. data/lib/rum/windows/layouts.rb +232 -0
  96. data/lib/rum/windows/system.rb +310 -0
  97. data/lib/rum/windows/system_foreign_functions.rb +129 -0
  98. data/rum.gemspec +14 -0
  99. metadata +166 -0
@@ -0,0 +1,73 @@
1
+ framework "ApplicationServices"
2
+ framework "#{File.dirname(__FILE__)}/keyboard_hook/KeyboardHook.framework"
3
+ framework 'Cocoa'
4
+
5
+ module KeyboardHook
6
+ def self.start &block
7
+ @tap = EventTap.new
8
+ @tap.on_event &block
9
+ NSApplication.sharedApplication.run()
10
+ end
11
+
12
+ def self.stop
13
+ # Todo: cleanup, unregister hook
14
+ NSApplication.sharedApplication.terminate(nil)
15
+ end
16
+ end
17
+
18
+ class EventTap
19
+ def handleEvent(event)
20
+ event if @proc.call(event)
21
+ end
22
+
23
+ def on_event(&proc)
24
+ @proc = proc
25
+ end
26
+ end
27
+
28
+ class Event
29
+ def set_event_source(source)
30
+ CGEventSetSource(eventRef, source)
31
+ end
32
+
33
+ def set_keycode(code)
34
+ set_integer_value_field(KCGKeyboardEventKeycode, code)
35
+ end
36
+
37
+ def down?
38
+ down != 0
39
+ end
40
+
41
+ def keycode
42
+ get_integer_value_field(KCGKeyboardEventKeycode)
43
+ end
44
+
45
+ def id
46
+ get_integer_value_field(KCGKeyboardEventKeycode)
47
+ end
48
+
49
+ def to_s
50
+ "#{down? ? 'Down' : 'Up'}: Id #{id}"
51
+ end
52
+
53
+ def set_integer_value_field(field, value)
54
+ CGEventSetIntegerValueField(eventRef, field, value)
55
+ end
56
+
57
+ def get_integer_value_field(field)
58
+ CGEventGetIntegerValueField(eventRef, field)
59
+ end
60
+
61
+ def get_user_data
62
+ CGEventGetIntegerValueField(eventRef, KCGEventSourceUnixProcessID)
63
+ end
64
+
65
+ def get_flags
66
+ CGEventGetFlags(eventRef)
67
+ end
68
+
69
+ def set_flags(flags)
70
+ CGEventSetFlags(eventRef, flags)
71
+ end
72
+ end
73
+
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>KeyboardHook</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>com.yourcompany.KeyboardHook</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>KeyboardHook</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleSignature</key>
18
+ <string>????</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>1.0</string>
21
+ </dict>
22
+ </plist>
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+
3
+ module Rum
4
+ module Layouts
5
+ module_function
6
+
7
+ def default_layout
8
+ us
9
+ end
10
+
11
+ # /System/Library/Frameworks/Carbon.framework/.../Events.h
12
+ def core
13
+ core = Layout.new
14
+
15
+ [['return', "\n", 36],
16
+ ['tab', 48],
17
+ ['space', ' ', 49],
18
+ ['delete', 51],
19
+ ['escape', 53],
20
+ ['rightcommand', 54],
21
+ ['command', 55],
22
+ ['shift', 56],
23
+ ['capslock', 57],
24
+ ['option', 58],
25
+ ['control', 59],
26
+ ['rightshift', 60],
27
+ ['rightoption', 61],
28
+ ['rightcontrol', 62],
29
+ ['function', 63],
30
+ ['f17', 64],
31
+ ['volumeup', 72],
32
+ ['volumedown', 73],
33
+ ['mute', 74],
34
+ ['f18', 79],
35
+ ['f19', 80],
36
+ ['f20', 90],
37
+ ['f5', 96],
38
+ ['f6', 97],
39
+ ['f7', 98],
40
+ ['f3', 99],
41
+ ['f8', 100],
42
+ ['f9', 101],
43
+ ['f11', 103],
44
+ ['f13', 105],
45
+ ['f16', 106],
46
+ ['f14', 107],
47
+ ['f10', 109],
48
+ ['f12', 111],
49
+ ['f15', 113],
50
+ ['help', 114],
51
+ ['home', 115],
52
+ ['pageup', 116],
53
+ ['forward_delete', 117],
54
+ ['f4', 118],
55
+ ['end', 119],
56
+ ['f2', 120],
57
+ ['pagedown', 121],
58
+ ['f1', 122],
59
+ ['leftarrow', 123],
60
+ ['rightarrow', 124],
61
+ ['downarrow', 125],
62
+ ['uparrow', 126]].each { |key| core.add *key }
63
+
64
+ core
65
+ end
66
+
67
+ def basic
68
+ basic = core
69
+
70
+ [['decimal', 65],
71
+ ['multiply', 67],
72
+ ['add', 69],
73
+ ['numlock', 71],
74
+ ['divide', 75],
75
+ ['numpadenter', 76],
76
+ ['subtract', 78],
77
+ ['numpad0', 82],
78
+ ['numpad1', 83],
79
+ ['numpad2', 84],
80
+ ['numpad3', 85],
81
+ ['numpad4', 86],
82
+ ['numpad5', 87],
83
+ ['numpad6', 88],
84
+ ['numpad7', 89],
85
+ ['numpad8', 91],
86
+ ['numpad9', 92],
87
+ ['apps', 110]].each { |key| basic.add *key }
88
+
89
+ basic.remap 'rightshift', 'shift'
90
+ basic.remap 'rightcontrol', 'control'
91
+ basic.remap 'rightoption', 'option'
92
+ basic.remap 'rightcommand', 'command'
93
+
94
+ basic.rename 'uparrow', 'up'
95
+ basic.rename 'rightarrow', 'right'
96
+ basic.rename 'downarrow', 'down'
97
+ basic.rename 'leftarrow', 'left'
98
+ basic.rename 'help', 'insert'
99
+ basic.alias 'insert', 'help'
100
+ basic.rename 'delete', 'backspace'
101
+ basic.rename 'forward_delete', 'delete'
102
+ basic.rename 'return', 'enter'
103
+ basic.alias 'enter', 'return'
104
+ basic.rename 'capslock', 'caps'
105
+
106
+ basic.alias 'f13', 'print'
107
+ basic.alias 'f14', 'scroll'
108
+ basic.alias 'f15', 'pause'
109
+
110
+ basic.alias 'command', 'cmd'
111
+ basic.alias 'function', 'fn'
112
+
113
+ %w{command control option shift function}.each do |key|
114
+ basic.core_modifier key
115
+ end
116
+
117
+ basic
118
+ end
119
+
120
+ def us
121
+ us = basic
122
+ %w{a s d f h g z x c v § b q w e r y t 1 2 3 4 6
123
+ 5 = 9 7 - 8 0 ] o u [ i p _ l j _ k ; _ , / n m .}.each_with_index do |key, id|
124
+ us.add key, id unless key == '_'
125
+ end
126
+
127
+ us.add "'", 39
128
+ us.add '\\', 42
129
+ us.add '`', 50
130
+
131
+ us
132
+ end
133
+
134
+ def german
135
+ german = basic
136
+ %w{a s d f h g z x c v ^ b q w e r y t 1 2 3 4 6
137
+ 5 ´ 9 7 ß 8 0 + o u ü i p _ l j ä k ö # , - n m .}.each_with_index do |key, id|
138
+ german.add key, id unless key == '_'
139
+ end
140
+
141
+ german.add '<', 50
142
+
143
+ german
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,45 @@
1
+ module Rum
2
+ module System
3
+ extend self
4
+
5
+ def applescript src
6
+ pointer = Pointer.new_with_type("@")
7
+ as = NSAppleScript.alloc.initWithSource(src)
8
+ as.executeAndReturnError(pointer)
9
+ end
10
+
11
+ def start *args
12
+ system 'open', *args
13
+ end
14
+
15
+ def escape_shell_word str
16
+ if str.empty? or %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ str
17
+ str
18
+ else
19
+ result = ''
20
+ str.scan(/('+)|[^']+/) {
21
+ if $1
22
+ result << %q{\'} * $1.length
23
+ else
24
+ result << "'#{$&}'"
25
+ end
26
+ }
27
+ result
28
+ end
29
+ end
30
+
31
+ def applescript_quote_string str
32
+ str.gsub!('\\', '\\\\\\\\')
33
+ str.gsub!('"', '\\"')
34
+ '"' << str << '"'
35
+ end
36
+
37
+ def spawn_in_terminal(*args)
38
+ close = args.delete :close_if_successful
39
+ command = args.map { |arg| escape_shell_word(arg) }.join(' ')
40
+ command << ';[ $? -eq 0 ] && exit' if close
41
+ command = applescript_quote_string(command)
42
+ applescript 'tell application "Terminal" to do script ' + command
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ require 'socket'
2
+
3
+ module Rum
4
+ class Remote
5
+ def initialize(port=Remote.default_port)
6
+ @connection = Connection.new(TCPSocket.open('127.0.0.1', port))
7
+ end
8
+
9
+ def eval code
10
+ @connection.dispatch code
11
+ @connection.receive
12
+ end
13
+
14
+ def disconnect
15
+ @connection.close
16
+ end
17
+
18
+ def self.default_port
19
+ if (port = ENV['RUM_PORT'].to_i) and port.nonzero?
20
+ port
21
+ else
22
+ 1994
23
+ end
24
+ end
25
+
26
+ module Connection
27
+ module Messaging
28
+ # Assumes message is not larger than 4,3 GB ((2**(4*8) - 1) bytes)
29
+ def dispatch(msg)
30
+ msg.encode! Encoding::UTF_8
31
+ msg.force_encoding Encoding::BINARY
32
+ write([msg.length].pack('N') + msg)
33
+ end
34
+
35
+ def receive
36
+ if message_size = read(4) # sizeof (N)
37
+ message_size = message_size.unpack('N')[0]
38
+ read(message_size).force_encoding(Encoding::UTF_8)
39
+ end
40
+ end
41
+ end
42
+
43
+ def Connection.new(stream)
44
+ stream.extend Messaging
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,92 @@
1
+ require 'rum/remote'
2
+
3
+ module Rum
4
+ module Server
5
+ module_function
6
+
7
+ # This makes it easier for code to check if it runs inside the server thread.
8
+ def thread
9
+ @thread
10
+ end
11
+
12
+ def start
13
+ return if @thread
14
+ @thread = Thread.new do
15
+ @server = TCPServer.new('127.0.0.1', Remote.default_port)
16
+ puts "Server started."
17
+ begin
18
+ @connection = nil
19
+ loop do
20
+ @connection = Remote::Connection.new(@server.accept)
21
+ handle(@connection)
22
+ @connection.close
23
+ end
24
+ ensure # clean up when thread gets killed
25
+ close_connections
26
+ end
27
+ end
28
+ end
29
+
30
+ # Temporary hack.
31
+ # MacRuby crashes on the ensure clause above when
32
+ # the server thread is killed.
33
+ # This function allows for manually closing the connections.
34
+ def close_connections
35
+ [@server, @connection].compact.each { |e| e.close unless e.closed? }
36
+ end
37
+
38
+ def stop
39
+ if @thread
40
+ @thread.kill
41
+ # Kill can return before the thread has finished execution. A Ruby bug?
42
+ @thread.join
43
+ @thread = nil
44
+ end
45
+ end
46
+
47
+ EvalBinding = TOPLEVEL_BINDING
48
+
49
+ def handle(connection)
50
+ return nil unless message = connection.receive
51
+ result = begin
52
+ eval(message, EvalBinding).inspect
53
+ rescue Exception => exception
54
+ error_message(exception)
55
+ end
56
+ connection.dispatch(result)
57
+ rescue SystemCallError # connection errors
58
+ end
59
+
60
+ def error_message(exception)
61
+ # Hide the internals from the backtrace
62
+ backtrace = exception.backtrace.reject { |frame| frame =~ /^#{__FILE__}/ }
63
+ msg = ["Rum-Server: Evaluation Error."]
64
+ msg << "#{exception.class}: #{exception}"
65
+ msg += backtrace
66
+ msg.join "\n"
67
+ end
68
+
69
+ module IRBCompletion
70
+ Glue = 'binding = Rum::Server::EvalBinding
71
+ workspace = Struct.new(:binding).new(binding)
72
+ context = Struct.new(:workspace).new(workspace)
73
+ @CONF = { MAIN_CONTEXT: context }
74
+
75
+ def IRB.conf
76
+ @CONF
77
+ end'
78
+
79
+ def self.setup
80
+ unless defined? IRB
81
+ # Since version 0.7, MacRuby ships with an incompatible IRB
82
+ # distribution called dietirb. Mac Rum includes a partial
83
+ # copy of the original IRB.
84
+ require Rum::Platform == :mac ? 'rum/mac/irb/completion' : 'irb/completion'
85
+ IRB.module_eval(Glue)
86
+ end
87
+ end
88
+ end
89
+
90
+ IRBCompletion.setup
91
+ end
92
+ end
@@ -0,0 +1,23 @@
1
+ require 'rum/windows/system'
2
+ require 'rum/windows/keyboard_hook'
3
+ require 'rum/windows/keyboard'
4
+ require 'rum/windows/gui'
5
+ require 'rum/windows/app'
6
+ require 'rum/windows/layouts'
7
+
8
+ module Rum
9
+ Platform = :windows
10
+
11
+ def self.restart_platform_specific
12
+ Rum::Server.stop
13
+ System.spawn_in_terminal('ruby', $PROGRAM_NAME)
14
+ sleep 0.01 # This prevents a strange lag. Wow.
15
+ System.terminal_window.close
16
+ end
17
+
18
+ class HotkeyProcessor
19
+ def inhibit_modifier_action
20
+ System.send_keypress @layout['control']
21
+ end
22
+ end
23
+ end