Class: Ruco::StatusBar

Inherits:
Object show all
Defined in:
lib/ruco/status_bar.rb

Instance Method Summary collapse

Constructor Details

#initialize(editor, options) ⇒ StatusBar

Returns a new instance of StatusBar.



3
4
5
6
# File 'lib/ruco/status_bar.rb', line 3

def initialize(editor, options)
  @editor = editor
  @options = options
end

Instance Method Details

#change_indicatorObject



29
30
31
# File 'lib/ruco/status_bar.rb', line 29

def change_indicator
  @editor.modified? ? '*' : ' '
end

#style_mapObject



25
26
27
# File 'lib/ruco/status_bar.rb', line 25

def style_map
  Dispel::StyleMap.single_line_reversed(@options[:columns])
end

#viewObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruco/status_bar.rb', line 8

def view
  columns = @options[:columns]

  version = "Ruco #{Ruco::VERSION} -- "
  position = " #{@editor.position.line + 1}:#{@editor.position.column + 1}"
  indicators = "#{change_indicator}#{writable_indicator}"
  essential = version + position + indicators
  space_left = [columns - essential.size, 0].max

  # fit file name into remaining space
  file = @editor.file
  file = file.ellipsize(:max => space_left)
  space_left -= file.size

  "#{version}#{file}#{indicators}#{' ' * space_left}#{position}"[0, columns]
end

#writable_indicatorObject



33
34
35
36
37
38
# File 'lib/ruco/status_bar.rb', line 33

def writable_indicator
  @writable ||= begin
    writable = (not File.exist?(@editor.file) or system("test -w #{@editor.file}"))
    writable ? ' ' : '!'
  end
end