class Zashoku::Statusline::Statusline

Public Class Methods

new() click to toggle source
# File lib/core/statusline/statusline.rb, line 14
def initialize
  @widgets = Zashoku.modules.keys.zip(Zashoku.modules.map do |_k, m|
    m.widgets if m.respond_to?(:widgets)
  end).to_h.compact
  Zashoku.logger.info("loaded widgets for #{@widgets.keys.join(', ')}")
  refresh
end

Public Instance Methods

change_screen_size() click to toggle source
# File lib/core/statusline/statusline.rb, line 22
def change_screen_size
  refresh
  changed!
end
changed!() click to toggle source
# File lib/core/statusline/statusline.rb, line 27
def changed!
  changed
  notify_observers
end
draw() click to toggle source
# File lib/core/statusline/statusline.rb, line 52
def draw
  print "\e[#{Util::Term.rows - 1};1H\e[0m#{@cl}#{@items_formatted}\e[K"
end
event(event) click to toggle source
# File lib/core/statusline/statusline.rb, line 32
def event(event)
  case event['event']
  when 'refresh_widget'
    @widgets[event['sender']][event['widget']].refresh
    refresh
    changed!
  end
end
refresh() click to toggle source
# File lib/core/statusline/statusline.rb, line 41
def refresh
  @cl = Zashoku::conf.get(%w[color main])
  @attrs = @widgets.map do |_k, m|
    m.map { |j, w| w.attr }
  end.flatten.reduce(&:merge)

  format = Zashoku::conf.get(%w[format statusline])

  @items_formatted = Zashoku::Formatter.format_line(format, @attrs)
end