weechat 0.0.2 → 0.0.3
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.
- data/ChangeLog +37 -0
- data/Rakefile +1 -1
- data/lib/weechat.rb +25 -2
- data/lib/weechat/buffer.rb +10 -2
- data/lib/weechat/callback.rb +6 -0
- data/lib/weechat/channel.rb +18 -5
- data/lib/weechat/command.rb +1 -3
- data/lib/weechat/hook.rb +14 -9
- data/lib/weechat/hooks.rb +1 -0
- data/lib/weechat/hooks/command_run.rb +1 -1
- data/lib/weechat/hooks/config.rb +1 -1
- data/lib/weechat/hooks/print.rb +1 -1
- data/lib/weechat/hooks/signal.rb +11 -0
- data/lib/weechat/info.rb +0 -2
- data/lib/weechat/line.rb +5 -1
- data/lib/weechat/modifier.rb +30 -5
- data/lib/weechat/process.rb +1 -1
- data/lib/weechat/script.rb +1 -1
- data/lib/weechat/timer.rb +1 -1
- data/lib/weechat/user.rb +6 -0
- data/lib/weechat/utilities.rb +21 -7
- metadata +3 -2
data/ChangeLog
CHANGED
@@ -1,5 +1,42 @@
|
|
1
|
+
2009-12-24 Dominik Honnef <dominikho@gmx.net>
|
2
|
+
|
3
|
+
* lib/weechat.rb (Weechat): bumped version to 0.0.3
|
4
|
+
|
5
|
+
* lib/weechat/buffer.rb (Weechat::Buffer.find): added method for finding buffers
|
6
|
+
|
7
|
+
* lib/weechat/channel.rb (Weechat::IRC::Channel.channels)
|
8
|
+
(Weechat::IRC::Channel.find): added methods for finding channels
|
9
|
+
|
10
|
+
* lib/weechat/user.rb (Weechat::IRC::User#==): made user comparable
|
11
|
+
|
12
|
+
* lib/weechat/hooks.rb: added signal hooks
|
13
|
+
* lib/weechat/hooks/signal.rb (Weechat::Hooks::Signal): added signal hooks
|
14
|
+
* lib/weechat.rb (Weechat::Helper#signal_callback): added signal hooks
|
15
|
+
|
16
|
+
2009-12-23 Dominik Honnef <dominikho@gmx.net>
|
17
|
+
|
18
|
+
|
19
|
+
* lib/weechat/hook.rb (Weechat::Hook)
|
20
|
+
(Weechat::Hook::compute_free_id): rewrote uid generation
|
21
|
+
|
22
|
+
* lib/weechat.rb (Weechat::Helper#modifier_callback): added support for specific modifiers
|
23
|
+
* lib/weechat/modifier.rb (Weechat::Modifier::inherited): added support for specific modifiers
|
24
|
+
* lib/weechat/modifier.rb (Weechat::Modifiers::Print): added Print modifier
|
25
|
+
|
26
|
+
|
27
|
+
* lib/weechat/channel.rb (Weechat::IRC::Channel#get_infolist): fixed parsing
|
28
|
+
|
1
29
|
2009-12-21 Dominik Honnef <dominikho@gmx.net>
|
2
30
|
|
31
|
+
* lib/weechat/line.rb (Weechat::Line#parse): fix line parsing
|
32
|
+
|
33
|
+
* lib/weechat/info.rb: fixed comments
|
34
|
+
* lib/weechat/command.rb: fixed comments
|
35
|
+
* lib/weechat/modifier.rb: fixed comments
|
36
|
+
|
37
|
+
* lib/weechat/script.rb (Weechat::Script::Skeleton::InstanceMethods#weechat_init):
|
38
|
+
fixed version comparison
|
39
|
+
|
3
40
|
* Rakefile: bumped version to 0.0.2
|
4
41
|
* lib/weechat.rb (Weechat): bumped version to 0.0.2
|
5
42
|
|
data/Rakefile
CHANGED
data/lib/weechat.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
require 'pp'
|
7
7
|
|
8
8
|
module Weechat
|
9
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.3"
|
10
10
|
module Helper
|
11
11
|
def command_callback(id, buffer, args)
|
12
12
|
Weechat::Command.find_by_id(id).call(Weechat::Buffer.new(buffer), args)
|
@@ -41,6 +41,26 @@ module Weechat
|
|
41
41
|
Weechat::Hooks::Print.find_by_id(id).call(buffer, date, tags, displayed, highlight, prefix, message)
|
42
42
|
end
|
43
43
|
|
44
|
+
# TODO add IRC parser
|
45
|
+
# TODO add support for filters
|
46
|
+
# TODO add support for ignores
|
47
|
+
# TODO add support for infolists by pointer
|
48
|
+
#
|
49
|
+
SignalCallbackTransformations = {
|
50
|
+
[/irc_(channel|pv)_opened/, /^logger_(start|stop|backlog)$/,
|
51
|
+
/^buffer_(closing|closed|lines_hidden|moved|opened|renamed|switch)$/,
|
52
|
+
/^buffer_(title|type)_changed$/,
|
53
|
+
/^buffer_localvar_(added|changed|removed)$/] => lambda { |v| Weechat::Buffer.new(v) },
|
54
|
+
[/irc_server_(connecting|connected|disconnected)/] => lambda { |v| Weechat::Server.new(v) },
|
55
|
+
[/weechat_(highlight|pv)/] => lambda { |v| Weechat::Line.parse(v) },
|
56
|
+
[/window_(scrolled|unzooming|unzoomed|zooming|zoomed)/] => lambda { |v| Weechat::Window.new(v) },
|
57
|
+
}
|
58
|
+
|
59
|
+
def signal_callback(id, signal, data)
|
60
|
+
data = Weechat::Utilities.apply_transformation(signal, data, SignalCallbackTransformations)
|
61
|
+
Weechat::Hooks::Signal.find_by_id(id).call(signal, data)
|
62
|
+
end
|
63
|
+
|
44
64
|
def config_callback(id, option, value)
|
45
65
|
ret = Weechat::Hooks::Config.find_by_id(id).call(option, value)
|
46
66
|
end
|
@@ -89,9 +109,12 @@ module Weechat
|
|
89
109
|
}
|
90
110
|
|
91
111
|
def modifier_callback(id, modifier, modifier_data, s)
|
112
|
+
klass = Weechat::Modifiers::Mappings[modifier] || Weechat::Modifier
|
92
113
|
modifier_data = Weechat::Utilities.apply_transformation(modifier, modifier_data, ModifierCallbackTransformations)
|
93
114
|
args = modifier_data + [Weechat::Line.parse(s)]
|
94
|
-
|
115
|
+
callback = klass.find_by_id(id)
|
116
|
+
callback ||= Weechat::Modifier.find_by_id(id)
|
117
|
+
ret = callback.call(*args)
|
95
118
|
return Weechat::Utilities.apply_transformation(modifier, ret, ModifierCallbackRTransformations).to_s
|
96
119
|
end
|
97
120
|
end
|
data/lib/weechat/buffer.rb
CHANGED
@@ -143,6 +143,7 @@ module Weechat
|
|
143
143
|
[:notify] => lambda {|v| NOTIFY_LEVELS[v] },
|
144
144
|
[:text_search] => lambda {|v| [:none, :backward, :foward][v] },
|
145
145
|
[:type] => lambda {|v| [:formatted, :free][v]},
|
146
|
+
[:plugin] => lambda {|v| Weechat::Plugin.new(v)},
|
146
147
|
}.freeze
|
147
148
|
|
148
149
|
# The transformation procedures that get applied to values before they
|
@@ -190,6 +191,13 @@ module Weechat
|
|
190
191
|
self.new(ptr)
|
191
192
|
end
|
192
193
|
|
194
|
+
def find(plugin, name)
|
195
|
+
plugin = Weechat::Plugin.from_name(plugin) if plugin.is_a?(String)
|
196
|
+
buffers.find {|buffer|
|
197
|
+
buffer.name == name && buffer.plugin == plugin
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
193
201
|
# Returns a list of all buffers
|
194
202
|
#
|
195
203
|
# @return [Array<Buffer>]
|
@@ -310,8 +318,8 @@ module Weechat
|
|
310
318
|
# @raise [Exception::DuplicateBufferName] In case a buffer with that name already exists
|
311
319
|
def create(name, input_callback, close_callback)
|
312
320
|
@callbacks << {
|
313
|
-
:input_callback =>
|
314
|
-
:close_callback =>
|
321
|
+
:input_callback => EvaluatedCallback.new(input_callback),
|
322
|
+
:close_callback => EvaluatedCallback.new(close_callback),
|
315
323
|
}
|
316
324
|
id = @callbacks.size - 1
|
317
325
|
ptr = Weechat.buffer_new(name.to_s, "input_callback", id.to_s, "close_callback", id.to_s)
|
data/lib/weechat/callback.rb
CHANGED
@@ -4,6 +4,12 @@ module Weechat
|
|
4
4
|
@callback = callback
|
5
5
|
end
|
6
6
|
|
7
|
+
def call(*args)
|
8
|
+
return Weechat::Utilities.safe_call {@callback.call(*args)}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class EvaluatedCallback < Callback
|
7
13
|
def call(*args)
|
8
14
|
return Weechat::Utilities.evaluate_call {@callback.call(*args)}
|
9
15
|
end
|
data/lib/weechat/channel.rb
CHANGED
@@ -12,6 +12,19 @@ module Weechat
|
|
12
12
|
|
13
13
|
init_properties
|
14
14
|
|
15
|
+
class << self
|
16
|
+
def channels
|
17
|
+
Weechat::Buffer.all.select {|b| b.channel?}.map{|b| b.channel}
|
18
|
+
end
|
19
|
+
alias_method :all, :channels
|
20
|
+
|
21
|
+
def find(server, channel)
|
22
|
+
server = server.name if server.respond_to?(:name)
|
23
|
+
channel = channel.name if channel.respond_to?(:name)
|
24
|
+
Weechat::Buffer.find("irc", "#{server}.#{channel}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
15
28
|
attr_reader :buffer
|
16
29
|
def initialize(buffer)
|
17
30
|
@buffer = Buffer.new(buffer.to_s)
|
@@ -22,11 +35,11 @@ module Weechat
|
|
22
35
|
end
|
23
36
|
|
24
37
|
def get_infolist
|
25
|
-
Weechat::
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
38
|
+
list = Weechat::Infolist.parse("irc_channel", "", server.name).select{|channel|
|
39
|
+
channel[:buffer] == @ptr
|
40
|
+
}
|
41
|
+
|
42
|
+
list.empty? ? [{}] : list
|
30
43
|
end
|
31
44
|
|
32
45
|
def server
|
data/lib/weechat/command.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
module Weechat
|
2
|
-
# Note: As opposed to plain WeeChat, we properly parse arguments
|
3
|
-
# given to a command, like a shell would.
|
4
2
|
class Command < Hook
|
5
3
|
attr_reader :command
|
6
4
|
attr_reader :description
|
@@ -46,7 +44,7 @@ module Weechat
|
|
46
44
|
end
|
47
45
|
|
48
46
|
@command[0..0] = '' if @command[0..0] == '/'
|
49
|
-
@callback =
|
47
|
+
@callback = EvaluatedCallback.new(callback)
|
50
48
|
@ptr = Weechat.hook_command(@command,
|
51
49
|
@description.to_s,
|
52
50
|
@args.to_s,
|
data/lib/weechat/hook.rb
CHANGED
@@ -3,17 +3,21 @@ module Weechat
|
|
3
3
|
# callback, which then calls the appropriate callback.
|
4
4
|
class Hook
|
5
5
|
include Weechat::Pointer
|
6
|
+
@@unique_id = 0
|
6
7
|
|
7
8
|
@hook_classes = [self]
|
8
|
-
|
9
|
-
by
|
10
|
-
|
11
|
-
|
9
|
+
class << self
|
10
|
+
def inherited(by)
|
11
|
+
by.init
|
12
|
+
@hook_classes << by
|
13
|
+
end
|
12
14
|
|
13
|
-
|
15
|
+
def hooks; @hooks; end
|
16
|
+
alias_method :all, :hooks
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
def init
|
19
|
+
@hooks = {}
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
init
|
@@ -29,7 +33,7 @@ module Weechat
|
|
29
33
|
end
|
30
34
|
|
31
35
|
def callback=(callback)
|
32
|
-
@callback =
|
36
|
+
@callback = EvaluatedCallback.new(callback)
|
33
37
|
end
|
34
38
|
|
35
39
|
class << self
|
@@ -78,8 +82,9 @@ module Weechat
|
|
78
82
|
@hooks[id.to_i]
|
79
83
|
end
|
80
84
|
|
85
|
+
# Returns a new, unique ID.
|
81
86
|
def self.compute_free_id
|
82
|
-
|
87
|
+
@@unique_id += 1
|
83
88
|
end
|
84
89
|
|
85
90
|
def self.register(hook)
|
data/lib/weechat/hooks.rb
CHANGED
@@ -14,7 +14,7 @@ module Weechat
|
|
14
14
|
command.to_s
|
15
15
|
end
|
16
16
|
|
17
|
-
@callback =
|
17
|
+
@callback = EvaluatedCallback.new(callback)
|
18
18
|
@ptr = Weechat.hook_command_run(@command, "command_run_callback", id.to_s)
|
19
19
|
if also_arguments
|
20
20
|
@ptr2 = Weechat.hook_command_run("#@command *", "command_run_callback", id.to_s)
|
data/lib/weechat/hooks/config.rb
CHANGED
data/lib/weechat/hooks/print.rb
CHANGED
@@ -6,7 +6,7 @@ module Weechat
|
|
6
6
|
buffer = buffer.ptr if buffer.respond_to?(:ptr)
|
7
7
|
tags = tags.join(",")
|
8
8
|
strip_colors = Weechat.bool_to_integer(strip_colors)
|
9
|
-
@callback =
|
9
|
+
@callback = EvaluatedCallback.new(callback)
|
10
10
|
@ptr = Weechat.hook_print(buffer, tags, message, strip_colors, "print_callback", id.to_s)
|
11
11
|
end
|
12
12
|
end
|
data/lib/weechat/info.rb
CHANGED
data/lib/weechat/line.rb
CHANGED
data/lib/weechat/modifier.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Weechat
|
2
|
-
# Note: As opposed to plain WeeChat, we properly parse arguments
|
3
|
-
# given to a command, like a shell would.
|
4
2
|
class Modifier < Hook
|
3
|
+
def self.inherited(by)
|
4
|
+
Hook.inherited(by)
|
5
|
+
end
|
6
|
+
|
5
7
|
attr_reader :modifier
|
6
8
|
def initialize(modifier, &callback)
|
7
9
|
super
|
8
10
|
@modifier = modifier.to_s
|
9
|
-
@callback = callback
|
10
|
-
# here because we need the return
|
11
|
-
# value of the callback
|
11
|
+
@callback = Callback.new(callback)
|
12
12
|
@ptr = Weechat.hook_modifier(modifier, "modifier_callback", id.to_s)
|
13
13
|
end
|
14
14
|
|
@@ -21,4 +21,29 @@ module Weechat
|
|
21
21
|
alias_method :exec, :call
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
module Modifiers
|
26
|
+
class Print < Weechat::Modifier
|
27
|
+
class PrintModifierCallback < Weechat::Callback
|
28
|
+
def call(plugin, buffer, tags, line)
|
29
|
+
begin
|
30
|
+
ret = @callback.call(plugin, buffer, tags, line)
|
31
|
+
rescue => e
|
32
|
+
Weechat::Utilities.format_exception(e)
|
33
|
+
return line
|
34
|
+
end
|
35
|
+
return ret
|
36
|
+
end
|
37
|
+
end # PrintModifierCallback
|
38
|
+
|
39
|
+
def initialize(&callback)
|
40
|
+
super("weechat_print", &callback)
|
41
|
+
@callback = PrintModifierCallback.new(callback)
|
42
|
+
end
|
43
|
+
end # Print
|
44
|
+
|
45
|
+
Mappings = {
|
46
|
+
'weechat_print' => Print,
|
47
|
+
}
|
48
|
+
end # Modifiers
|
24
49
|
end
|
data/lib/weechat/process.rb
CHANGED
@@ -12,7 +12,7 @@ module Weechat
|
|
12
12
|
@command = command
|
13
13
|
@collect = collect
|
14
14
|
@stdout, @stderr = [], []
|
15
|
-
@callback =
|
15
|
+
@callback = EvaluatedCallback.new(callback)
|
16
16
|
@ptr = Weechat.hook_process(command, timeout, "process_callback", id.to_s)
|
17
17
|
end
|
18
18
|
|
data/lib/weechat/script.rb
CHANGED
@@ -26,7 +26,7 @@ module Weechat
|
|
26
26
|
|
27
27
|
module InstanceMethods
|
28
28
|
def weechat_init
|
29
|
-
if (self.script[:gem_version].split('.') <=> Weechat::VERSION.split('.')) > 0
|
29
|
+
if (self.script[:gem_version].split('.').map{|i| i.to_i} <=> Weechat::VERSION.split('.').map{|i| i.to_i}) > 0
|
30
30
|
Weechat.puts "This script ('#{self.script[:name]}') "\
|
31
31
|
"requires a version of the weechat ruby gem of at least #{self.script[:gem_version]}. "\
|
32
32
|
"You are currently using the version #{Weechat::VERSION}"
|
data/lib/weechat/timer.rb
CHANGED
data/lib/weechat/user.rb
CHANGED
@@ -19,6 +19,12 @@ module Weechat
|
|
19
19
|
alias_method :opped?, :op?
|
20
20
|
alias_method :voiced?, :voice?
|
21
21
|
|
22
|
+
def ==(other)
|
23
|
+
@name == other.name && @host == other.host && @channel == other.channel
|
24
|
+
end
|
25
|
+
alias_method :eql?, "=="
|
26
|
+
alias_method :equal?, :eql?
|
27
|
+
|
22
28
|
def op
|
23
29
|
@channel.exec("/op #@name")
|
24
30
|
end
|
data/lib/weechat/utilities.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
module Weechat
|
2
2
|
module Utilities
|
3
|
+
def self.format_exception(e)
|
4
|
+
prefix = Weechat.prefix("error")
|
5
|
+
|
6
|
+
line1 = e.backtrace[0] + ": " + e.message + " (" + e.class.name + ")"
|
7
|
+
backtrace = " " + e.backtrace[1..-1].join("\n ")
|
8
|
+
|
9
|
+
Weechat.puts("#{prefix}error in evaluated call: #{line1}")
|
10
|
+
Weechat.puts("#{prefix}#{backtrace}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.safe_call
|
14
|
+
begin
|
15
|
+
ret = yield
|
16
|
+
rescue => e
|
17
|
+
format_exception(e)
|
18
|
+
return Weechat::WEECHAT_RC_ERROR
|
19
|
+
end
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
|
3
23
|
def self.evaluate_call
|
4
24
|
begin
|
5
25
|
yield
|
@@ -10,13 +30,7 @@ module Weechat
|
|
10
30
|
rescue Weechat::Exception::WEECHAT_RC_ERROR
|
11
31
|
return Weechat::WEECHAT_RC_ERROR
|
12
32
|
rescue => e
|
13
|
-
|
14
|
-
|
15
|
-
line1 = e.backtrace[0] + ": " + e.message + " (" + e.class.name + ")"
|
16
|
-
backtrace = " " + e.backtrace[1..-1].join("\n ")
|
17
|
-
|
18
|
-
Weechat.puts("#{prefix}error in evaluated call: #{line1}")
|
19
|
-
Weechat.puts("#{prefix}#{backtrace}")
|
33
|
+
format_exception(e)
|
20
34
|
return Weechat::WEECHAT_RC_ERROR
|
21
35
|
end
|
22
36
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weechat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Honnef
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-24 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/weechat/hooks/print.rb
|
48
48
|
- lib/weechat/hooks/config.rb
|
49
49
|
- lib/weechat/hooks/command_run.rb
|
50
|
+
- lib/weechat/hooks/signal.rb
|
50
51
|
- lib/weechat/line.rb
|
51
52
|
- lib/weechat/exceptions.rb
|
52
53
|
- lib/weechat/command.rb
|