class Tmux::StatusBar::Field
This class represents a field in a {StatusBar status bar}. Every {StatusBar status bar} has two fields, one on the left side and one on the right side.
A field can either display a simple {#text text}, or display a {Widget widget}. While only one {Widget widget} can be displayed at a time per field, a field will keep a stack of widgets, to and from which new {Widget widgets} can be {#push_widget pushed} and {#pop_widget popped}. This is useful for example when temporarily displaying a {Widgets::ProgressBar progress bar}.
Attributes
@return [Symbol]
@return [Symbol]
@return [Number]
@return [String]
@overload widget
@return [Widget] The currently displayed {Widget widget}, that is the one on top of the stack.
@overload widget=(widget)
Overwrites the stack of {Widget widgets} and makes `widget` the only {Widget widget}. @return [Widget]
@return [Widget] The currently displayed {Widget widget},
that is the one on top of the stack.
Public Class Methods
# File lib/tmux/status_bar/field.rb, line 14 def initialize(status_bar, side) @status_bar = status_bar @side = side @widgets = [] @backups = [] end
Public Instance Methods
# File lib/tmux/status_bar/field.rb, line 100 def background_color=(color) @status_bar.session.options.set "status-#@side-bg", color end
# File lib/tmux/status_bar/field.rb, line 112 def foreground_color=(color) @status_bar.session.options.set "status-#@side-fg", color end
# File lib/tmux/status_bar/field.rb, line 124 def max_length=(num) @status_bar.session.options.set "status-#@side-length", num end
Removes the current {Widget widget} from the stack.
@param [Widget] pop If not nil, try to remove the specified
widget instead of popping off the topmost one.
@return [Widget, nil] the {Widget widget} which has been popped
# 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
Pushes a widget to the stack, making it the currently visible one.
@param [Widget] widget the widget to push to the stack @return [void]
# File lib/tmux/status_bar/field.rb, line 26 def push_widget(widget) @backups << self.text @widgets << widget widget.field = self end
Removes all {Widget widgets} from the stack, restoring the {StatusBar status bar's} original state.
@return [void]
# File lib/tmux/status_bar/field.rb, line 75 def restore while pop_widget; end end
# File lib/tmux/status_bar/field.rb, line 87 def text=(val) meth = "status_#@side=" @status_bar.session.options.set "status-#@side", val end
# File lib/tmux/status_bar/field.rb, line 66 def widget=(widget) restore push_widget(widget) end