Sha256: 8636b267314cb3e955c3dba007bdb1edb41bb9b7747465e8e89e51c52fd97e3b

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 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 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

3 entries across 3 versions & 1 rubygems

Version Path
ruco-0.1.12 lib/ruco/status_bar.rb
ruco-0.1.11 lib/ruco/status_bar.rb
ruco-0.1.10 lib/ruco/status_bar.rb