Class: Tmux::StatusBar::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/tmux/status_bar/field.rb

Overview

This class represents a field in a status bar. Every status bar has two fields, one on the left side and one on the right side.

A field can either display a simple text, or display a widget. While only one widget can be displayed at a time per field, a field will keep a stack of widgets, to and from which new widgets can be pushed and popped. This is useful for example when temporarily displaying a progress bar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_bar, side) ⇒ Field

Returns a new instance of Field



14
15
16
17
18
19
# File 'lib/tmux/status_bar/field.rb', line 14

def initialize(status_bar, side)
  @status_bar = status_bar
  @side      = side
  @widgets   = []
  @backups   = []
end

Instance Attribute Details

#background_colorSymbol

Returns:

  • (Symbol)


90
91
92
# File 'lib/tmux/status_bar/field.rb', line 90

def background_color
  @status_bar.session.options.get "status-#@side-bg"
end

#foreground_colorSymbol

Returns:

  • (Symbol)


100
101
102
# File 'lib/tmux/status_bar/field.rb', line 100

def foreground_color
  @status_bar.session.options.get "status-#@side-fg"
end

#max_lengthNumber

Returns:

  • (Number)


111
112
113
# File 'lib/tmux/status_bar/field.rb', line 111

def max_length
  @status_bar.session.options.get "status-#@side-length"
end

#textString

Returns:

  • (String)


79
80
81
# File 'lib/tmux/status_bar/field.rb', line 79

def text
  @status_bar.session.options.get "status-#@side"
end

#widgetWidget

The currently displayed widget, that is the one on top of the stack.

Setting this overwrites the stack of widgets and makes widget the only widget.

Returns:



59
60
61
# File 'lib/tmux/status_bar/field.rb', line 59

def widget
  @widgets.last
end

Instance Method Details

#pop_widget(pop = nil) ⇒ Widget? Also known as: remove_widget

Removes the current widget from the stack.

Parameters:

  • pop (Widget) (defaults to: nil)

    If not nil, try to remove the specified widget instead of popping off the topmost one.

Returns:



39
40
41
42
43
44
45
46
47
48
# File 'lib/tmux/status_bar/field.rb', line 39

def pop_widget(pop = nil)
  widget = pop || @widgets.first
  pos = @widgets.index(widget)
  @widgets.delete_at(pos)
  backup = @backups.delete_at(pos)

  self.text = backup if backup and pos == 0
  @widgets.last.field = self if @widgets.last
  widget
end

#push_widget(widget) Also known as: add_widget

This method returns an undefined value.

Pushes a widget to the stack, making it the currently visible one.

Parameters:

  • widget (Widget)

    the widget to push to the stack



26
27
28
29
30
31
# File 'lib/tmux/status_bar/field.rb', line 26

def push_widget(widget)
  @backups << self.text
  @widgets.last.field = nil if @widgets.last
  @widgets << widget
  widget.field = self
end

#restore

This method returns an undefined value.

Removes all widgets from the stack, restoring the status bar's original state.



72
73
74
# File 'lib/tmux/status_bar/field.rb', line 72

def restore
  while pop_widget; end
end