ratchet 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/gem_bin/ratchet +23 -0
  2. data/lib/ratchet.rb +613 -0
  3. data/lib/ratchet/aliases.rb +106 -0
  4. data/lib/ratchet/bufferparser.rb +409 -0
  5. data/lib/ratchet/commandbuffer.rb +66 -0
  6. data/lib/ratchet/commandparser.rb +668 -0
  7. data/lib/ratchet/configuration.rb +278 -0
  8. data/lib/ratchet/connections.rb +403 -0
  9. data/lib/ratchet/constants.rb +111 -0
  10. data/lib/ratchet/contrib/instance_exec.rb +21 -0
  11. data/lib/ratchet/eventparser.rb +486 -0
  12. data/lib/ratchet/gtk/bufferlistview.rb +514 -0
  13. data/lib/ratchet/gtk/bufferview.rb +167 -0
  14. data/lib/ratchet/gtk/configwindow.rb +229 -0
  15. data/lib/ratchet/gtk/connectionwindow.rb +218 -0
  16. data/lib/ratchet/gtk/keybinding.rb +356 -0
  17. data/lib/ratchet/gtk/linkwindow.rb +137 -0
  18. data/lib/ratchet/gtk/mainwindow.rb +504 -0
  19. data/lib/ratchet/gtk/networkpresenceconf.rb +567 -0
  20. data/lib/ratchet/gtk/pluginconfig.rb +94 -0
  21. data/lib/ratchet/gtk/pluginwindow.rb +146 -0
  22. data/lib/ratchet/gtk/userlistview.rb +161 -0
  23. data/lib/ratchet/help.rb +64 -0
  24. data/lib/ratchet/items.rb +271 -0
  25. data/lib/ratchet/lines.rb +63 -0
  26. data/lib/ratchet/networks.rb +652 -0
  27. data/lib/ratchet/plugins.rb +616 -0
  28. data/lib/ratchet/queue.rb +47 -0
  29. data/lib/ratchet/ratchet-version.rb +21 -0
  30. data/lib/ratchet/replies.rb +134 -0
  31. data/lib/ratchet/replyparser.rb +441 -0
  32. data/lib/ratchet/tabcomplete.rb +98 -0
  33. data/lib/ratchet/users.rb +237 -0
  34. data/lib/ratchet/utils.rb +178 -0
  35. data/share/defaults.yaml +169 -0
  36. data/share/glade/config.glade +2634 -0
  37. data/share/glade/connect.glade +950 -0
  38. data/share/glade/keybindings.glade +109 -0
  39. data/share/glade/linkwindow.glade +188 -0
  40. data/share/glade/mainwindow.glade +335 -0
  41. data/share/glade/network-presences.glade +1373 -0
  42. data/share/glade/pluginconf.glade +97 -0
  43. data/share/glade/plugins.glade +360 -0
  44. data/share/plugins/colorewrite.rb +193 -0
  45. data/share/plugins/highlighter.rb +115 -0
  46. data/share/plugins/mpdplay.rb +123 -0
  47. data/share/plugins/numberswitcher.rb +30 -0
  48. data/share/plugins/sysinfo.rb +82 -0
  49. metadata +96 -0
@@ -0,0 +1,193 @@
1
+ #inspects colors and adjusts any that would display poorly on your background color
2
+ #algorithms borrowed from http://www.easyrgb.com/math.php
3
+ include Ratchet
4
+
5
+ class ColoRewrite < Plugin
6
+
7
+ def rgb2xyz(r, g, b)
8
+ r /= 255.0
9
+ g /= 255.0
10
+ b /= 255.0
11
+
12
+ if r > 0.04045
13
+ r = ( ( r + 0.055 ) / 1.055 ) ** 2.4
14
+ else
15
+ r = r / 12.92
16
+ end
17
+
18
+ if g > 0.04045
19
+ g = ( ( g + 0.055 ) / 1.055 ) ** 2.4
20
+ else
21
+ g = g / 12.92
22
+ end
23
+
24
+ if b > 0.04045
25
+ b = ( ( b + 0.055 ) / 1.055 ) ** 2.4
26
+ else
27
+ b = b / 12.92
28
+ end
29
+
30
+ r *= 100
31
+ g *= 100
32
+ b *= 100
33
+
34
+ x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805)
35
+ y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722)
36
+ z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505)
37
+ return [x,y,z]
38
+ end
39
+
40
+ def xyz2rgb(x, y, z)
41
+ x /= 100
42
+ y /= 100
43
+ z /= 100
44
+
45
+ r = x * 3.2406 + y * -1.5372 + z * -0.4986
46
+ g = x * -0.9689 + y * 1.8758 + z * 0.0415
47
+ b = x * 0.0557 + y * -0.2040 + z * 1.0570
48
+
49
+ if r > 0.0031308
50
+ r = 1.055 * ( r ** ( 1 / 2.4 ) ) - 0.055
51
+ else
52
+ r *= 12.92
53
+ end
54
+
55
+ if g > 0.0031308
56
+ g = 1.055 * ( g ** ( 1 / 2.4 ) ) - 0.055
57
+ else
58
+ g *= 12.92
59
+ end
60
+
61
+ if b > 0.0031308
62
+ b = 1.055 * ( b ** ( 1 / 2.4 ) ) - 0.055
63
+ else
64
+ b *= 12.92
65
+ end
66
+
67
+
68
+ r *= 255
69
+ g *= 255
70
+ b *= 255
71
+
72
+ r = r.to_i.abs
73
+ g = g.to_i.abs
74
+ b = b.to_i.abs
75
+
76
+ r = 255 if r > 255
77
+ g = 255 if g > 255
78
+ b = 255 if b > 255
79
+
80
+ return[r,g,b]
81
+ end
82
+
83
+ def xyz2lab(x, y, z)
84
+ x /= 95.047
85
+ y /= 100.000
86
+ z /= 108.883
87
+
88
+ if x > 0.008856
89
+ x **= ( 1/3.0 )
90
+ else
91
+ x = ( 7.787 * x ) + ( 16 / 116.0 )
92
+ end
93
+
94
+ if y > 0.008856
95
+ y **= ( 1/3.0 )
96
+ else
97
+ y = ( 7.787 * y ) + ( 16 / 116.0 )
98
+ end
99
+
100
+ if z > 0.008856
101
+ z **= ( 1/3.0 )
102
+ else
103
+ z = ( 7.787 * z ) + ( 16 / 116.0 )
104
+ end
105
+
106
+ l = ( 116 * y ) - 16
107
+ a = 500 * ( x - y )
108
+ b = 200 * ( y - z )
109
+
110
+ return [l,a,b]
111
+ end
112
+
113
+ def lab2xyz(l, a, b)
114
+ l = ( l + 16 ) / 116
115
+ a = a / 500 + l
116
+ b = l - b / 200
117
+
118
+ if l**3 > 0.008856
119
+ l = l**3
120
+ else
121
+ l = ( l - 16 / 116 ) / 7.787
122
+ end
123
+
124
+ if a**3 > 0.008856
125
+ a = a**3
126
+ else
127
+ a = ( a - 16 / 116 ) / 7.787
128
+ end
129
+
130
+ if b**3 > 0.008856
131
+ b = b**3
132
+ else
133
+ b = ( b - 16 / 116 ) / 7.787
134
+ end
135
+
136
+ x = a * 95.047
137
+ y = l * 100.000
138
+ z = b * 108.883
139
+
140
+ return[x,y,z]
141
+ end
142
+
143
+ def colorcompare(r1, g1, b1, r2, g2, b2)
144
+ a = xyz2lab(*rgb2xyz(r1, g1, b1))
145
+ b = xyz2lab(*rgb2xyz(r2, g2, b2))
146
+
147
+ l1, a1, b1 = a
148
+ l2, a2, b2 = b
149
+
150
+ res = [(l1-l2).abs, (a1-a2).abs, (b1-b2).abs]
151
+ if res.select{|e| e/100 > 0.5}.length >= 2
152
+ return true
153
+ else
154
+ result = false
155
+ while result != true
156
+ #b[res.index(res.sort[2])]-= 5
157
+ b[res.index(res.sort[1])]+= 10
158
+ b[res.index(res.sort[0])]-= 1
159
+ #puts b[res.index(res.sort[1])]
160
+ l2, a2, b2 = b
161
+ result = [(l1-l2).abs, (a1-a2).abs, (b1-b2).abs].select{|e| e/100 > 0.6}.length >= 2
162
+ end
163
+ return xyz2rgb(*lab2xyz(*b))
164
+ end
165
+ end
166
+
167
+ def load
168
+ add_callback_after(self, Buffer, 'buffer_message') do |uname, pattern, users, insert_location|
169
+ #puts pattern
170
+ pattern.scan(/\<span foreground\s*=\s*\"#([0-9a-f]+)/i) do |m|
171
+ # puts pattern, m
172
+ # puts Color.hex_to_a($1), @@main.config['scw_even'].to_256
173
+ res = colorcompare(*(@@main.config['scw_even'].to_256+Color.hex_to_a($1)))
174
+ # puts res
175
+ if res.class == Array
176
+ hexcolor = Color.a_to_hex(res)
177
+ # puts 'match'
178
+ pattern.sub!($1, hexcolor)
179
+ end
180
+ # puts pattern
181
+ end
182
+ [uname, pattern, users, insert_location]
183
+ end
184
+ end
185
+ end
186
+
187
+ colorewrite = ColoRewrite.new
188
+ Plugin.register(colorewrite)
189
+
190
+ #puts colorcompare(255, 255, 255, 255, 255, 0)
191
+
192
+ #puts xyz2rgb(*lab2xyz(*xyz2lab(*rgb2xyz(255, 255, 255))))
193
+
@@ -0,0 +1,115 @@
1
+ # a highlighter plugin
2
+ include Ratchet
3
+
4
+ class Highlighter < Plugin
5
+ attr_accessor :terms
6
+ def load
7
+ @@main.config['highlightstrings'] ||= []
8
+ @@main.config['highlightplugincolor'] ||= Color.new(65535, 65535, 0)
9
+ @@main.config['highlightcommand'] ||= 'none'
10
+
11
+ #/add_highlight adds a highlight
12
+ help :cmd_add_highlight, "Add a highlight string"
13
+ add_method(self, Main, 'cmd_add_highlight') do |args, target|
14
+
15
+ unless @@main.config['highlightstrings'].include?(args)
16
+ puts 'added highlight for '+args
17
+ @@main.config['highlightstrings'].push(args)
18
+ end
19
+
20
+ @@main.config['highlightstrings'].sort! {|x, y| y.length<=>x.length}
21
+
22
+ end
23
+
24
+ #/del_highlight removes a highlight
25
+ help :cmd_del_highlight, "Delete a highlight string"
26
+ add_method(self, Main, 'cmd_del_highlight') do |args, target|
27
+
28
+ if @@main.config['highlightstrings'].include?(args)
29
+ puts 'removed highlight for '+args
30
+ @@main.config['highlightstrings'].delete(args)
31
+ end
32
+ end
33
+
34
+ #/highlights lists defined highlights
35
+ help :cmd_highlights, "List all highlight strings"
36
+ add_method(self, Main, 'cmd_highlights') do |args, target|
37
+
38
+ lines = ['Defined Highlights:']
39
+
40
+ @@main.config['highlightstrings'].each {|term| lines.push(term)}
41
+
42
+ lines.push(' ')
43
+
44
+ lines.each do |line|
45
+ event = {'msg' => line}
46
+ @window.currentbuffer.send_user_event(event, EVENT_NOTICE)
47
+ end
48
+ end
49
+
50
+ add_callback_after(self, Buffer, 'buffer_message') do |uname, pattern, users, insert_location|
51
+ #puts uname, pattern, users, insert_location
52
+
53
+ replace = false
54
+ replacements = []
55
+
56
+ @@main.config['highlightstrings'].each do |term|
57
+ exists = false
58
+ replacement = nil
59
+ #check for a regexp
60
+ if term[0].chr == '/' and term[-1].chr == '/'
61
+ #create a regexp object
62
+ re = Regexp.new(term[1...-1], Regexp::IGNORECASE)
63
+
64
+ md = re.match(pattern)
65
+
66
+ replacement = md[0] if md
67
+ else
68
+ if pattern.include?(term)
69
+ replacement = term
70
+ end
71
+ end
72
+ if replacement
73
+ replacements.each do |s|
74
+ exists = true if s.include?(replacement)
75
+ end
76
+ end
77
+
78
+ if !exists and replacement
79
+ replace = true
80
+ replacements.push(term)
81
+ color = @@main.config['highlightplugincolor'].to_hex
82
+ pattern.gsub!(replacement, '<span color="'+color+'">'+replacement+'</span>')#you can change the highlight color here...
83
+ end
84
+ end
85
+
86
+ if replace
87
+ if insert_location == BUFFER_END
88
+ command = @@main.config['highlightcommand']
89
+ if command != 'none'
90
+ system command
91
+ end
92
+ set_status(HIGHLIGHT)
93
+ end
94
+ end
95
+
96
+ [uname, pattern, users, insert_location]
97
+ end
98
+ end
99
+
100
+ def configure
101
+ value = @@main.config['highlightplugincolor']
102
+ value ||= Color.new(65535, 65535, 0)
103
+ return [{'type' => Color, 'name' => 'highlightplugincolor',
104
+ 'value' => value, 'description' => 'Highlight Color'},
105
+ {'type' => Array, 'name' => 'highlightstrings',
106
+ 'value' => @@main.config['highlightstrings'], 'description' => 'Strings or Regexp to highlight',
107
+ 'tooltip' => 'Comma seperated list of strings/regexps to highlight. Regexps are surrounded with /s'},
108
+ {'type' => String, 'name' => 'highlightcommand',
109
+ 'value' => @@main.config['highlightcommand'], 'description' => 'Highlight command',
110
+ 'tooltip' => 'System command to run when a highlight occured, none will do nothing'}]
111
+ end
112
+ end
113
+
114
+ highlighter = Highlighter.new
115
+ Plugin.register(highlighter)
@@ -0,0 +1,123 @@
1
+ #a now playing plugin for mpd
2
+ require 'socket'
3
+
4
+ include Ratchet
5
+ class MPDPlay < Plugin
6
+ def load
7
+ @@main.config['mpdformatstring'] = 'is listening to %A - %T [MPD]' unless @@main.config['mpdformatstring']
8
+ @@main.config['mpdhost'] = 'localhost' unless @@main.config['mpdhost']
9
+ @@main.config['mpdport'] = 6600 unless @@main.config['mpdport']
10
+ @@main.config['mpdpass'] = '' unless @@main.config['mpdpass']
11
+
12
+ help :cmd_np, "Display the currently playing song in MPD"
13
+ add_method(self, Main, 'cmd_np') do |args, target|
14
+ begin
15
+ result = query_mpd
16
+ rescue IOError
17
+ throw_error("MPD error: #{$!}")
18
+ return
19
+ else
20
+ artist, title, album = result
21
+ string = @@main.config['mpdformatstring'].dup
22
+ string.sub!('%A', artist)
23
+ string.sub!('%T', title)
24
+ string.sub!('%D', album)
25
+ send_command('nowplaying', "msg;#{target.identifier_string};msg=#{escape(string)};type=action") if target.network and target.network != target
26
+ target.send_user_event({'msg'=>string, 'type'=>'action'}, EVENT_USERMESSAGE)
27
+ end
28
+ end
29
+
30
+ help :cmd_next, "Skip to next song in MPD"
31
+ add_method(self, Main, 'cmd_next') do |args, channel, network, presence|
32
+ begin
33
+ result = command_mpd('next')
34
+ rescue IOError
35
+ throw_error("MPD error: #{$!}")
36
+ return
37
+ end
38
+ end
39
+
40
+ help :cmd_prev, "Skip to previous song in MPD"
41
+ add_method(self, Main, 'cmd_prev') do |args, channel, network, presence|
42
+ begin
43
+ result = command_mpd('previous')
44
+ rescue IOError
45
+ throw_error("MPD error: #{$!}")
46
+ return
47
+ end
48
+ end
49
+
50
+ help :cmd_pause, "Toggle play/pause in MPD"
51
+ add_method(self, Main, 'cmd_pause') do |args, channel, network, presence|
52
+ begin
53
+ result = command_mpd('pause')
54
+ rescue IOError
55
+ throw_error("MPD error: #{$!}")
56
+ return
57
+ end
58
+ end
59
+ end
60
+
61
+ def connect_mpd
62
+ begin
63
+ socket = TCPSocket.new(@@main.config['mpdhost'], @@main.config['mpdport'])
64
+ rescue Errno::ECONNREFUSED
65
+ raise IOError, 'Failed to connect'
66
+ end
67
+ socket.recv(30)#grab the connect message
68
+ if !@@main.config['mpdpass'] or !@@main.config['mpdpass'].empty?
69
+ socket.send('password '+ @@main.config['mpdpass'].to_s+"\n", Socket::MSG_DONTROUTE)
70
+ res = socket.recv(40)
71
+ if res =~ /^ACK /
72
+ raise IOError, 'Incorrect Password'
73
+ end
74
+ end
75
+ return socket
76
+ end
77
+
78
+ def command_mpd(command)
79
+ socket = connect_mpd
80
+ socket.send(command+"\n", Socket::MSG_DONTROUTE)
81
+ res = socket.recv(300)
82
+ socket.close
83
+ return res
84
+ end
85
+
86
+ def query_mpd
87
+ socket = connect_mpd
88
+ socket.send("currentsong\n", Socket::MSG_DONTROUTE)
89
+ res = socket.recv(300)
90
+ artist = 'Unknown'
91
+ album = 'Unknown'
92
+ title = 'Unknown'
93
+
94
+ res.split("\n").each do |line|
95
+ if line =~ /^Artist: (.+)/
96
+ artist = $1
97
+ elsif line =~ /^Album: (.+)/
98
+ album = $1
99
+ elsif line =~ /^Title: (.+)/
100
+ title = $1
101
+ end
102
+ end
103
+
104
+ socket.close
105
+
106
+ return [artist, title, album]
107
+ end
108
+
109
+ def configure
110
+ return [{'type' => String, 'name' => 'mpdformatstring',
111
+ 'value' => @@main.config['mpdformatstring'], 'description' => 'Format string'},
112
+ {'type' => String, 'name' => 'mpdhost',
113
+ 'value' => @@main.config['mpdhost'], 'description' => 'MPD host'},
114
+ {'type' => Integer, 'name' => 'mpdport',
115
+ 'value' => @@main.config['mpdport'], 'description' => 'MPD port'},
116
+ {'type' => String, 'name' => 'mpdpass',
117
+ 'value' => @@main.config['mpdpass'], 'description' => 'MPD password'}
118
+ ]
119
+ end
120
+ end
121
+
122
+ mpdplay = MPDPlay.new
123
+ Plugin.register(mpdplay)
@@ -0,0 +1,30 @@
1
+ #A simple plugin to test the command_missing callback
2
+ #allows commands like /12 to be issued which then will switch to that tab
3
+
4
+ include Ratchet
5
+
6
+ class NumberSwitcher < Plugin
7
+ def load
8
+ add_callback(self, Main, :command_missing) do |command, arguments, target|
9
+ # puts command.class, command
10
+ if command.numeric?
11
+ # puts 'is numeric', target
12
+ window = find_windows_with_buffer(target)
13
+ # puts window
14
+ unless window.empty?
15
+ buffer = window[0].buffers.model.structure[command.to_i]
16
+ if buffer
17
+ throw_message "I'd switch to #{buffer.name}"
18
+ window[0].buffers.set_active(buffer)
19
+ else
20
+ throw_error "Can't find a buffer numbered #{command}"
21
+ end
22
+ end
23
+ true
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ Plugin.register(NumberSwitcher.new)