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

background_color[RW]

@return [Symbol]

foreground_color[RW]

@return [Symbol]

max_length[RW]

@return [Number]

text[RW]

@return [String]

widget[RW]

@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

new(status_bar, side) click to toggle source
# 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

add_widget(widget)
Alias for: push_widget
background_color=(color) click to toggle source
# File lib/tmux/status_bar/field.rb, line 100
def background_color=(color)
  @status_bar.session.options.set "status-#@side-bg", color
end
foreground_color=(color) click to toggle source
# File lib/tmux/status_bar/field.rb, line 112
def foreground_color=(color)
  @status_bar.session.options.set "status-#@side-fg", color
end
max_length=(num) click to toggle source
# File lib/tmux/status_bar/field.rb, line 124
def max_length=(num)
  @status_bar.session.options.set "status-#@side-length", num
end
pop_widget(pop = nil) click to toggle source

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
Also aliased as: remove_widget
push_widget(widget) click to toggle source

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
Also aliased as: add_widget
remove_widget(pop = nil)
Alias for: pop_widget
restore() click to toggle source

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
text=(val) click to toggle source
# File lib/tmux/status_bar/field.rb, line 87
def text=(val)
  meth = "status_#@side="
  @status_bar.session.options.set "status-#@side", val
end
widget=(widget) click to toggle source
# File lib/tmux/status_bar/field.rb, line 66
def widget=(widget)
  restore
  push_widget(widget)
end