Class: Weechat::Bar::Item

Inherits:
Object
  • Object
show all
Extended by:
Callbacks, Properties
Includes:
Pointer
Defined in:
lib/weechat/bar.rb

Instance Attribute Summary

Attributes included from Pointer

#ptr

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Callbacks

call_callback, callbacks, compute_free_id, compute_free_id, register_callback, unique_id

Methods included from Properties::ClassMethods

#all, #apply_rtransformation, #apply_transformation, #init_properties, #known_integer_properties, #known_properties, #known_string_properties, #mappings, #rtransformations, #settable_properties, #transformations, #type

Methods included from Pointer

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

Constructor Details

- (Item) initialize(name) {|window| ... }

Creates a new Bar Item, and registers it for use for Bars. is used in the :items option for Bars to display the bar item

Yields:

  • (window)

    The callback to generate and update the item

Yield Parameters:

  • window (Window, nil)

    If the bar this item is placed on is inside a window (ie the bar's type is :window), it will be the window the bar is present on. Otherwise it will be nil.

Yield Returns:

  • (String)

    The string used to render the item



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/weechat/bar.rb', line 68

def initialize(name, &build_callback)
  build_callback ||= method(:build)
  id = self.class.compute_free_id
  @ptr = Weechat.bar_item_new(name, "bar_build_callback", id.to_s)
  if @ptr.empty?
    raise "Could not create bar item"
  end

  self.class.register_callback(
                               :build_callback => Callback.new(build_callback),
                               :ptr            => @ptr
                               )
end

Class Method Details

+ (Object) call_build_callback(id, window)



96
97
98
99
# File 'lib/weechat/bar.rb', line 96

def call_build_callback(id, window)
  window = Window.from_ptr(window)
  call_callback(id, :build_callback, window).to_s
end

+ (Bar::Item?) find(name) Also known as: from_name

finds the Bar::Item with the given name



45
46
47
48
49
50
51
52
# File 'lib/weechat/bar.rb', line 45

def find(name)
  ptr = Weechat.bar_item_search(name)
  if !ptr.empty?
    from_ptr(ptr)
  else
    nil
  end
end

+ (Object) items Also known as: all



32
33
34
35
36
37
38
# File 'lib/weechat/bar.rb', line 32

def items
  items = []
  Weechat::Infolist.parse("bar_item").each do |item|
    items << Item.find(item[:name])
  end
  items
end

Instance Method Details

- (Object) build(window)

eigenclass



56
57
58
# File 'lib/weechat/bar.rb', line 56

def build(window)
  ""
end

- (Object) delete Also known as: remove

removes the bar item, it will no longer be able to be used on any Bars



89
90
91
92
# File 'lib/weechat/bar.rb', line 89

def delete
  # TODO mark deletion status
  Weechat.bar_item_remove(@ptr)
end

- (Object) update

Updates the bar item



83
84
85
# File 'lib/weechat/bar.rb', line 83

def update
  Weechat.bar_item_update(name)
end