Sha256: 1e508445cb1386b03b992af26e1584f442063f532f4af682eba25d67f82462d0

Contents?: true

Size: 1.09 KB

Versions: 58

Compression:

Stored size: 1.09 KB

Contents

module Ruco
  class Editor
    module LineNumbers
      LINE_NUMBERS_SPACE = 5

      def initialize(content, options)
        options[:columns] -= LINE_NUMBERS_SPACE if options[:line_numbers]
        super(content, options)
      end

      def view
        if @options[:line_numbers]
          number_room = LINE_NUMBERS_SPACE - 1

          super.naive_split("\n").map_with_index do |line,i|
            number = @window.top + i
            number = if lines[number]
              (number + 1).to_s
                     else
                       ''
                     end.rjust(number_room).slice(0,number_room)
            "#{number} #{line}"
          end * "\n"
        else
          super
        end
      end

      def style_map
        if @options[:line_numbers]
          map = super
          map.left_pad!(LINE_NUMBERS_SPACE)
          map
        else
          super
        end
      end

      def cursor
        if @options[:line_numbers]
          cursor = super
          cursor[1] += LINE_NUMBERS_SPACE
          cursor
        else
          super
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
ruco-0.4.0 lib/ruco/editor/line_numbers.rb
ruco-0.3.0 lib/ruco/editor/line_numbers.rb
ruco-0.2.23 lib/ruco/editor/line_numbers.rb
ruco-0.2.22 lib/ruco/editor/line_numbers.rb
ruco-0.2.21 lib/ruco/editor/line_numbers.rb
ruco-0.2.20 lib/ruco/editor/line_numbers.rb
ruco-0.2.19 lib/ruco/editor/line_numbers.rb
ruco-0.2.18 lib/ruco/editor/line_numbers.rb
ruco-0.2.17 lib/ruco/editor/line_numbers.rb
ruco-0.2.16 lib/ruco/editor/line_numbers.rb
ruco-0.2.15 lib/ruco/editor/line_numbers.rb
ruco-0.2.14 lib/ruco/editor/line_numbers.rb
ruco-0.2.13 lib/ruco/editor/line_numbers.rb
ruco-0.2.12 lib/ruco/editor/line_numbers.rb
ruco-0.2.11 lib/ruco/editor/line_numbers.rb
ruco-0.2.10 lib/ruco/editor/line_numbers.rb
ruco-0.2.9 lib/ruco/editor/line_numbers.rb
ruco-0.2.8 lib/ruco/editor/line_numbers.rb
ruco-0.2.7 lib/ruco/editor/line_numbers.rb
ruco-0.2.6 lib/ruco/editor/line_numbers.rb