Module: Ruco::Editor::LineNumbers
- Included in:
- Ruco::EditorArea
- Defined in:
- lib/ruco/editor/line_numbers.rb
Constant Summary collapse
- LINE_NUMBERS_SPACE =
5
Instance Method Summary collapse
Instance Method Details
#cursor ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruco/editor/line_numbers.rb', line 39 def cursor if @options[:line_numbers] cursor = super cursor[1] += LINE_NUMBERS_SPACE cursor else super end end |
#initialize(content, options) ⇒ Object
6 7 8 9 |
# File 'lib/ruco/editor/line_numbers.rb', line 6 def initialize(content, ) [:columns] -= LINE_NUMBERS_SPACE if [:line_numbers] super(content, ) end |
#style_map ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/ruco/editor/line_numbers.rb', line 29 def style_map if @options[:line_numbers] map = super map.left_pad!(LINE_NUMBERS_SPACE) map else super end end |
#view ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruco/editor/line_numbers.rb', line 11 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 |