Class: Weechat::Modifier

Inherits:
Hook
  • Object
show all
Defined in:
lib/weechat/modifier.rb

Overview

Class for modifier hooks. These can hook onto events that trigger them, and alter what the event ends up doing.

List of default weechat and irc hooks

| Plugin  | Modifier                       | Arguments                                                                            | Output                                                                      |
|---------+--------------------------------+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------------|
| charset | charset_decode                 | plugin.buffer_name , any string                                                      | string decoded from charset found for plugin/buffer to UTF-8                |
| charset | charset_encode                 | plugin.buffer_name , any string                                                      | string encoded from UTF-8 to charset found for plugin/buffer                |
| irc     | irc_color_decode               | keep colors boolean, any string                                                      | string with WeeChat color codes, or without color                           |
| irc     | irc_color_encode               | keep colors boolean, any string                                                      | string with IRC color codes, or without color                               |
| irc     | irc_in_xxx (1)                 | server Buffer, content of message received from IRC server (before charset decoding) | new content of message                                                      |
| irc     | irc_in2_xxx (1)                | server Buffer, content of message received from IRC server (after charset decoding)  | new content of message                                                      |
| irc     | irc_out_xxx (1)                | server Buffer, content of message about to be sent to IRC server                     | new content of message                                                      |
| weechat | bar_condition_yyy (2)          | Window                                                                               | Boolean as to whether to display bar                                        |
| weechat | history_add                    | Buffer, input buffer (from user) to add in command history (buffer and global)       | string added to command history                                             |
| weechat | input_text_content             | Buffer , input buffer (from user)                                                    | new content of input buffer                                                 |
| weechat | input_text_display             | Buffer , input buffer (from user), without cursor tag                                | new content of input buffer, for display only (input buffer is not changed) |
| weechat | input_text_display_with_cursor | Buffer , input buffer (from user), with cursor tag                                   | new content of input buffer, for display only (input buffer is not changed) |
| weechat | weechat_print                  | Plugin,Buffer,array of tags, message printed                                         | new message printed                                                         |

Examples:

Modifier.new 'weechat_print' do |plugin, buffer, tags, line|
 line.message.upcase!
 line.to_s
end

Direct Known Subclasses

IRC::CTCP, Weechat::Modifiers::Print

Instance Attribute Summary collapse

Attributes inherited from Hook

#callback, #id

Attributes included from Pointer

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hook

all, #call, compute_free_id, find_by_id, #hooked?, init, register, unhook, #unhook, unhook_all, unregister

Methods included from Pointer

#==, #hash, included, #inspect, #to_s

Constructor Details

#initialize(modifier) {|*args| ... } ⇒ Modifier

creates a modifier hook.

Parameters:

  • modifier (String)

    The name of the modifier. Can contain wildcards (*) at the beginning and end to match multiple modifier hooks

Yields:

  • (*args)

    The block that is called for the modifier hook

Yield Parameters:

  • args (Array)

    The arguments for the modifier hook

Yield Returns:

  • The result for the modifier, depends on the modifier being hooked to



38
39
40
41
42
43
# File 'lib/weechat/modifier.rb', line 38

def initialize(modifier, &callback)
  super
  @modifier = modifier.to_s
  @callback         = Callback.new(callback)
  @ptr              = Weechat.hook_modifier(modifier, "modifier_callback", id.to_s)
end

Instance Attribute Details

#modifierObject (readonly)

Returns the value of attribute modifier



31
32
33
# File 'lib/weechat/modifier.rb', line 31

def modifier
  @modifier
end

Class Method Details

.call(modifier, data, string) ⇒ Object Also known as: exec



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

def call(modifier, data, string)
  Weechat.hook_modifier_exec(modifier.to_s, data.to_s, string.to_s)
end

.inherited(by) ⇒ Object



27
28
29
# File 'lib/weechat/modifier.rb', line 27

def self.inherited(by)
  Hook.inherited(by)
end

Instance Method Details

#execObject



45
# File 'lib/weechat/modifier.rb', line 45

alias_method :exec, :call