Sha256: 1349c71f66366033581bb3bb954ee7e5a4f47f96ce2aacee777441465062c7d3

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

module Ruco
  class StatusBar
    def initialize(editor, options)
      @editor = editor
      @options = options
    end

    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

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

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

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

    private

    # fill the line with left column and then overwrite the right section
    def spread(left, right)
      empty = [@options[:columns] - left.size, 0].max
      line = left + (" " * empty)
      line[(@options[:columns] - right.size - 1)..-1] = ' ' + right
      line
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruco-0.4.0 lib/ruco/status_bar.rb
ruco-0.3.0 lib/ruco/status_bar.rb
ruco-0.2.23 lib/ruco/status_bar.rb
ruco-0.2.22 lib/ruco/status_bar.rb
ruco-0.2.21 lib/ruco/status_bar.rb
ruco-0.2.20 lib/ruco/status_bar.rb
ruco-0.2.19 lib/ruco/status_bar.rb