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

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),
    ]
  },
  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(buffer, options = {}) ⇒ Status

Returns a new instance of Status.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ver/status.rb', line 53

def initialize(buffer, options = {})
  super
  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.



51
52
53
# File 'lib/ver/status.rb', line 51

def buffer
  @buffer
end

#notifyObject

Returns the value of attribute notify.



51
52
53
# File 'lib/ver/status.rb', line 51

def notify
  @notify
end

#widgetsObject

Returns the value of attribute widgets.



51
52
53
# File 'lib/ver/status.rb', line 51

def widgets
  @widgets
end

Instance Method Details

#event(*names) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/ver/status.rb', line 73

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

#register(widget, *events) ⇒ Object



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

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

#style=(config) ⇒ Object



89
90
91
# File 'lib/ver/status.rb', line 89

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

#textObject



85
86
87
# File 'lib/ver/status.rb', line 85

def text
  buffer.text
end