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)


93
94
95
# File 'lib/tmux/status_bar/field.rb', line 93

def background_color
  @background_color
end

#foreground_colorSymbol

Returns:

  • (Symbol)


105
106
107
# File 'lib/tmux/status_bar/field.rb', line 105

def foreground_color
  @foreground_color
end

#max_lengthNumber

Returns:

  • (Number)


117
118
119
# File 'lib/tmux/status_bar/field.rb', line 117

def max_length
  @max_length
end

#textString

Returns:

  • (String)


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

def text
  @text
end

#widgetWidget #widget=(widget) ⇒ Widget

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

Overloads:

  • #widgetWidget

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

    Returns:

    • (Widget)

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

  • #widget=(widget) ⇒ Widget

    Overwrites the stack of widgets and makes widget the only widget.

    Returns:

Returns:

  • (Widget)

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



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

def widget
  @widget
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:



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

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
  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
# File 'lib/tmux/status_bar/field.rb', line 26

def push_widget(widget)
  @backups << self.text
  @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.



75
76
77
# File 'lib/tmux/status_bar/field.rb', line 75

def restore
  while pop_widget; end
end