Class: VER::Status

Inherits:
Tk::Tile::Frame
  • Object
show all
Defined in:
lib/ver/status.rb,
lib/ver/status/mode.rb,
lib/ver/status/label.rb,
lib/ver/status/syntax.rb,
lib/ver/status/battery.rb,
lib/ver/status/percent.rb,
lib/ver/status/encoding.rb,
lib/ver/status/filename.rb,
lib/ver/status/position.rb,
lib/ver/status/nano_help.rb,
lib/ver/status/separator.rb,
lib/ver/status/nano_position.rb,
lib/ver/status/short_filename.rb,
lib/ver/status/buffer_position.rb,
lib/ver/status/diakonos_position.rb

Overview

The status bar

Defined Under Namespace

Modules: LabelToggle Classes: Battery, BufferPosition, DiakonosPosition, Encoding, Filename, Label, Mode, NanoHelp, NanoPosition, Percent, Position, Separator, ShortFilename, Syntax

Constant Summary collapse

LINES =
{
  vim: lambda{|status|
    [
      ShortFilename.new(status, weight: 1),
      Position.new(status),
      Percent.new(status),
      Mode.new(status),
      Syntax.new(status),
      Encoding.new(status),
    ]
  },
  emacs: lambda{|status|
    [
      ShortFilename.new(status, weight: 1),
      Position.new(status),
      Percent.new(status),
      Mode.new(status),
      Syntax.new(status),
      Encoding.new(status),
    ]
  },
  nano: lambda{|status|
    [
      NanoPosition.new(status, row: 0, column: 0, weight: 1, anchor: :center),
      NanoHelp.new(status, row: 1, column: 0, sticky: :nwse, weight: 1),
    ]
  },
  diakonos: lambda{|status|
    [
      Separator.new(status, orient: :horizontal),
      Filename.new(status),
      Separator.new(status, orient: :horizontal),
      Syntax.new(status, format: "(%s)"),
      Separator.new(status, orient: :horizontal, weight: 1),
      BufferPosition.new(status, format: 'Buf %d of %d'),
      Separator.new(status, orient: :horizontal),
      DiakonosPosition.new(status, format: 'L %3d/%3d C%2d'),
      Separator.new(status, orient: :horizontal),
    ]
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, buffer, options = {}) ⇒ Status

Returns a new instance of Status.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ver/status.rb', line 82

def initialize(parent, buffer, options = {})
  super(parent, options)
  self.buffer = buffer
  self.notify = Hash.new{|hash, key| hash[key] = Set.new }

  constructor = VER.options.statusline || LINES.fetch(VER.options.keymap.to_sym)
  @widgets = constructor.call(self)
  @widgets.each.with_index do |widget, index|
    row    = widget.row    || 0
    column = widget.column || index
    sticky = widget.sticky || :we
    weight = widget.weight || 0

    widget.grid_configure(row: row, column: column, sticky: sticky)
    grid_columnconfigure(widget, weight: weight)
  end

  grid_rowconfigure(0, weight: 1)
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



80
81
82
# File 'lib/ver/status.rb', line 80

def buffer
  @buffer
end

#notifyObject

Returns the value of attribute notify.



80
81
82
# File 'lib/ver/status.rb', line 80

def notify
  @notify
end

#widgetsObject

Returns the value of attribute widgets.



80
81
82
# File 'lib/ver/status.rb', line 80

def widgets
  @widgets
end

Instance Method Details

#event(*names) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/ver/status.rb', line 102

def event(*names)
  names.each do |name|
    notify[name].each do |widget|
      widget.update(name)
    end
  end
end

#hideObject



124
125
126
127
128
129
# File 'lib/ver/status.rb', line 124

def hide
  return unless winfo_ismapped
  @last_grid_info = grid_info
  grid_forget
  true
end

#register(widget, *events) ⇒ Object



110
111
112
# File 'lib/ver/status.rb', line 110

def register(widget, *events)
  events.each{|event| notify[event] << widget }
end

#showObject



118
119
120
121
122
# File 'lib/ver/status.rb', line 118

def show
  return if winfo_ismapped
  grid_configure(@last_grid_info)
  true
end

#style=(config) ⇒ Object



114
115
116
# File 'lib/ver/status.rb', line 114

def style=(config)
  Tk::After.idle{ @widgets.each{|widget| widget.style = config } }
end