Class: Tmux::StatusBar::Field
- Inherits:
-
Object
- Object
- Tmux::StatusBar::Field
- 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
- #background_color ⇒ Symbol
- #foreground_color ⇒ Symbol
- #max_length ⇒ Number
- #text ⇒ String
-
#widget ⇒ Widget
The currently displayed widget, that is the one on top of the stack.
Instance Method Summary collapse
-
#initialize(status_bar, side) ⇒ Field
constructor
A new instance of Field.
-
#pop_widget(pop = nil) ⇒ Widget?
(also: #remove_widget)
Removes the current widget from the stack.
-
#push_widget(widget)
(also: #add_widget)
Pushes a widget to the stack, making it the currently visible one.
-
#restore
Removes all widgets from the stack, restoring the status bar's original state.
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(, side) @status_bar = @side = side @widgets = [] @backups = [] end |
Instance Attribute Details
#background_color ⇒ Symbol
93 94 95 |
# File 'lib/tmux/status_bar/field.rb', line 93 def background_color @background_color end |
#foreground_color ⇒ Symbol
105 106 107 |
# File 'lib/tmux/status_bar/field.rb', line 105 def foreground_color @foreground_color end |
#max_length ⇒ Number
117 118 119 |
# File 'lib/tmux/status_bar/field.rb', line 117 def max_length @max_length end |
#text ⇒ String
80 81 82 |
# File 'lib/tmux/status_bar/field.rb', line 80 def text @text end |
Instance Method Details
#pop_widget(pop = nil) ⇒ Widget? Also known as: remove_widget
Removes the current widget from the stack.
38 39 40 41 42 43 44 45 46 |
# File 'lib/tmux/status_bar/field.rb', line 38 def (pop = nil) = pop || @widgets.first pos = @widgets.index() @widgets.delete_at(pos) backup = @backups.delete_at(pos) self.text = backup if backup and pos == 0 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.
26 27 28 29 30 |
# File 'lib/tmux/status_bar/field.rb', line 26 def () @backups << self.text @widgets << .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 ; end end |