weechat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
 
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = "weechat"
data/lib/weechat.rb CHANGED
@@ -6,7 +6,7 @@ end
6
6
  require 'pp'
7
7
 
8
8
  module Weechat
9
- VERSION = "0.0.2"
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
- ret = Weechat::Modifier.find_by_id(id).call(*args)
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
@@ -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 => Callback.new(input_callback),
314
- :close_callback => Callback.new(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)
@@ -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
@@ -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::IRC::Server.all.map{|server|
26
- Weechat::Infolist.parse("irc_channel", "", server.name).find{|channel|
27
- channel[:buffer] == @ptr
28
- }
29
- }.compact
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
@@ -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 = Callback.new(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
- def self.inherited(by)
9
- by.init
10
- @hook_classes << by
11
- end
9
+ class << self
10
+ def inherited(by)
11
+ by.init
12
+ @hook_classes << by
13
+ end
12
14
 
13
- def self.hooks; @hooks; end
15
+ def hooks; @hooks; end
16
+ alias_method :all, :hooks
14
17
 
15
- def self.init
16
- @hooks = {}
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 = Callback.new(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
- (@hooks.keys.max || -1) + 1
87
+ @@unique_id += 1
83
88
  end
84
89
 
85
90
  def self.register(hook)
data/lib/weechat/hooks.rb CHANGED
@@ -6,3 +6,4 @@ end
6
6
  require 'weechat/hooks/command_run.rb'
7
7
  require 'weechat/hooks/print.rb'
8
8
  require 'weechat/hooks/config.rb'
9
+ require 'weechat/hooks/signal.rb'
@@ -14,7 +14,7 @@ module Weechat
14
14
  command.to_s
15
15
  end
16
16
 
17
- @callback = Callback.new(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)
@@ -3,7 +3,7 @@ module Weechat
3
3
  class Config < Hook
4
4
  def initialize(option, &callback)
5
5
  super
6
- @callback = Callback.new(callback)
6
+ @callback = EvaluatedCallback.new(callback)
7
7
  @ptr = Weechat.hook_config(option, "config_callback", id.to_s)
8
8
  end
9
9
  end
@@ -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 = Callback.new(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
@@ -0,0 +1,11 @@
1
+ module Weechat
2
+ module Hooks
3
+ class Signal < Hook
4
+ def initialize(signal='*', &callback)
5
+ super
6
+ @callback = EvaluatedCallback.new(callback)
7
+ @ptr = Weechat.hook_signal(signal, "signal_callback", id.to_s)
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/weechat/info.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 Info < Hook
5
3
  attr_reader :name
6
4
  attr_reader :description
data/lib/weechat/line.rb CHANGED
@@ -13,7 +13,11 @@ module Weechat
13
13
  when 0
14
14
  parts = ["", ""]
15
15
  when 1
16
- parts.unshift ""
16
+ if line =~ /\t(\t+)\Z/
17
+ parts << $1
18
+ else
19
+ parts.unshift ""
20
+ end
17
21
  when 2
18
22
  else
19
23
  parts = [parts[0], parts[1..-1].join("\t")]
@@ -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 # we do not use the Callback class
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
@@ -12,7 +12,7 @@ module Weechat
12
12
  @command = command
13
13
  @collect = collect
14
14
  @stdout, @stderr = [], []
15
- @callback = Callback.new(callback)
15
+ @callback = EvaluatedCallback.new(callback)
16
16
  @ptr = Weechat.hook_process(command, timeout, "process_callback", id.to_s)
17
17
  end
18
18
 
@@ -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
@@ -6,7 +6,7 @@ module Weechat
6
6
  def initialize(interval, max=0, align=0, &block)
7
7
  super
8
8
  @remaining= nil
9
- @callback = Callback.new(block)
9
+ @callback = EvaluatedCallback.new(block)
10
10
  @interval = interval
11
11
  @align = align
12
12
  @max = max
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
@@ -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
- prefix = Weechat.prefix("error")
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.2
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-21 00:00:00 +01:00
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