Sha256: 06ef037401486d3e15ace687062659782b0e8504d0db2606e0f6a050b7b2e685

Contents?: true

Size: 881 Bytes

Versions: 5

Compression:

Stored size: 881 Bytes

Contents

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

    def view
      position = @editor.position
      spread "Ruco #{Ruco::VERSION} -- #{@editor.file}#{change_indicator}#{writable_indicator}", "#{position.line + 1}:#{position.column + 1}"
    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

5 entries across 5 versions & 1 rubygems

Version Path
ruco-0.1.9 lib/ruco/status_bar.rb
ruco-0.1.8 lib/ruco/status_bar.rb
ruco-0.1.7 lib/ruco/status_bar.rb
ruco-0.1.6 lib/ruco/status_bar.rb
ruco-0.1.5 lib/ruco/status_bar.rb