Module: Weechat::Helper

Defined in:
lib/weechat.rb

Overview

Contains the callback for linking with the low level ruby api No need to call these methods manually

Constant Summary

SignalCallbackTransformations =

TODO add IRC parser TODO add support for filters TODO add support for ignores TODO add support for infolists by pointer

{
  [/irc_(channel|pv)_opened/, /^logger_(start|stop|backlog)$/,
   /^buffer_(closing|closed|lines_hidden|moved|opened|renamed|switch)$/,
   /^buffer_(title|type)_changed$/,
   /^buffer_localvar_(added|changed|removed)$/] => lambda { |v| Weechat::Buffer.from_ptr(v) },
  [/irc_server_(connecting|connected|disconnected)/] => lambda { |v| Weechat::Server.from_name(v) },
  [/weechat_(highlight|pv)/] => lambda { |v| Weechat::Line.parse(v) },
  [/window_(scrolled|unzooming|unzoomed|zooming|zoomed)/] => lambda { |v| Weechat::Window.from_ptr(v) },
  [/irc_(raw_)?((in)|(out))/] => lambda { |v| Weechat::IRC::Message.parse_message(v) },
  ["irc_ctcp"] => lambda { |v| Weechat::IRC::Message.new(v) },
}
ModifierCallbackTransformations =
{
  [/^irc_(in|out)_.+$/] => lambda { |v| Weechat::IRC::Server.from_name(v) },
  ['irc_color_decode', 'irc_color_encode'] => lambda { |v| Weechat.integer_to_bool(v) },
  [/^bar_condition_.+$/]                   => lambda { |v| Weechat::Window.from_ptr(v) },
  ["input_text_content", "input_text_display",
   "input_text_display_with_cursor", "history_add"]       => lambda { |v| Weechat::Buffer.from_ptr(v) },
  ["weechat_print"]                        => lambda { |v|
    parts = v.split(";")
    parts[0] = Weechat::Plugin.find(parts[0])
    parts[1] = Weechat::Buffer.find(parts[1], parts[0])
    if parts[2]
      parts[2] = parts[2].split(",")
    else
      parts[2] = []
    end
    parts
  },
}
ModifierCallbackRTransformations =
{
  [/^bar_condition_.+$/] => lambda { |v| Weechat.bool_to_integer(v) },
}

Instance Method Summary (collapse)

Instance Method Details

- (Object) bar_build_callback(id, item, window)

low level bar build callback



73
74
75
# File 'lib/weechat.rb', line 73

def bar_build_callback(id, item, window)
  Weechat::Bar::Item.call_build_callback(id, window)
end

- (Object) close_callback(method, buffer)

low level buffer close callback



68
69
70
# File 'lib/weechat.rb', line 68

def close_callback(method, buffer)
  Weechat::Buffer.call_close_callback(method, buffer)
end

- (Object) command_callback(id, buffer, args)

low level Callback method used for commands



48
49
50
# File 'lib/weechat.rb', line 48

def command_callback(id, buffer, args)
  Weechat::Command.find_by_id(id).call(Weechat::Buffer.from_ptr(buffer), args)
end

- (Object) command_run_callback(id, buffer, command)

low level Callback used for running commands



53
54
55
# File 'lib/weechat.rb', line 53

def command_run_callback(id, buffer, command)
  Weechat::Hooks::CommandRunHook.find_by_id(id).call(Weechat::Buffer.from_ptr(buffer), command)
end

- (Object) config_callback(id, option, value)

low level config callback



120
121
122
# File 'lib/weechat.rb', line 120

def config_callback(id, option, value)
  ret = Weechat::Hooks::Config.find_by_id(id).call(option, value)
end

- (Object) info_callback(id, info, arguments)

low level info callback



78
79
80
# File 'lib/weechat.rb', line 78

def info_callback(id, info, arguments)
  Weechat::Info.find_by_id(id).call(arguments).to_s
end

- (Object) input_callback(method, buffer, input)

low level buffer input callback



63
64
65
# File 'lib/weechat.rb', line 63

def input_callback(method, buffer, input)
  Weechat::Buffer.call_input_callback(method, buffer, input)
end

- (Object) modifier_callback(id, modifier, modifier_data, s)

low level modifier hook callback



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/weechat.rb', line 172

def modifier_callback(id, modifier, modifier_data, s)
  classes = Weechat::Hook.hook_classes
  modifier_data = Weechat::Utilities.apply_transformation(modifier, modifier_data, ModifierCallbackTransformations)
  modifier_data = [modifier_data] unless modifier_data.is_a?(Array)
  args = modifier_data + [Weechat::Line.parse(s)]

  callback = classes.map {|cls| cls.find_by_id(id)}.compact.first

  ret = callback.call(*args)
  return Weechat::Utilities.apply_transformation(modifier, ret, ModifierCallbackRTransformations).to_s
end

low level print callback



83
84
85
86
87
88
89
90
91
# File 'lib/weechat.rb', line 83

def print_callback(id, buffer, date, tags, displayed, highlight, prefix, message)
  buffer    = Weechat::Buffer.from_ptr(buffer)
  date      = Time.at(date.to_i)
  tags      = tags.split(",")
  displayed = Weechat.integer_to_bool(displayed)
  highlight = Weechat.integer_to_bool(highlight)
  line = PrintedLine.new(buffer, date, tags, displayed, highlight, prefix, message)
  Weechat::Hooks::Print.find_by_id(id).call(line)
end

- (Object) process_callback(id, command, code, stdout, stderr)

low level process callback



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/weechat.rb', line 125

def process_callback(id, command, code, stdout, stderr)
  code = case code
         when Weechat::WEECHAT_HOOK_PROCESS_RUNNING
           :running
         when Weechat::WEECHAT_HOOK_PROCESS_ERROR
           :error
         else
           code
         end

  process = Weechat::Process.find_by_id(id)
  if process.collect?
    process.buffer(stdout, stderr)
    if code == :error || code != :running
      process.call(code, process.stdout, process.stderr)
    end
  else
    process.call(code, stdout, stderr)
  end
end

- (Object) signal_callback(id, signal, data)

low level callback for signal hooks



114
115
116
117
# File 'lib/weechat.rb', line 114

def signal_callback(id, signal, data)
  data = Weechat::Utilities.apply_transformation(signal, data, SignalCallbackTransformations)
  Weechat::Hooks::Signal.find_by_id(id).call(signal, data)
end

- (Object) timer_callback(id, remaining)

low level Timer callback



58
59
60
# File 'lib/weechat.rb', line 58

def timer_callback(id, remaining)
  Weechat::Timer.find_by_id(id).call(remaining.to_i)
end