Class: RuVim::CommandLine
- Inherits:
-
Object
- Object
- RuVim::CommandLine
- Defined in:
- lib/ruvim/command_line.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #backspace ⇒ Object
- #clear ⇒ Object
- #content ⇒ Object
-
#initialize ⇒ CommandLine
constructor
A new instance of CommandLine.
- #insert(str) ⇒ Object
- #move_left ⇒ Object
- #move_right ⇒ Object
- #replace_span(start_idx, end_idx, replacement, cursor_at: :end) ⇒ Object
- #replace_text(str) ⇒ Object
- #reset(prefix: ":") ⇒ Object
Constructor Details
#initialize ⇒ CommandLine
Returns a new instance of CommandLine.
7 8 9 |
# File 'lib/ruvim/command_line.rb', line 7 def initialize reset(prefix: ":") end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
5 6 7 |
# File 'lib/ruvim/command_line.rb', line 5 def cursor @cursor end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/ruvim/command_line.rb', line 5 def prefix @prefix end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/ruvim/command_line.rb', line 5 def text @text end |
Instance Method Details
#backspace ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ruvim/command_line.rb', line 46 def backspace return if @cursor.zero? @text.slice!(@cursor - 1) @cursor -= 1 end |
#clear ⇒ Object
17 18 19 20 |
# File 'lib/ruvim/command_line.rb', line 17 def clear @text.clear @cursor = 0 end |
#content ⇒ Object
61 62 63 |
# File 'lib/ruvim/command_line.rb', line 61 def content "#{@prefix}#{@text}" end |
#insert(str) ⇒ Object
41 42 43 44 |
# File 'lib/ruvim/command_line.rb', line 41 def insert(str) @text.insert(@cursor, str) @cursor += str.length end |
#move_left ⇒ Object
53 54 55 |
# File 'lib/ruvim/command_line.rb', line 53 def move_left @cursor -= 1 if @cursor.positive? end |
#move_right ⇒ Object
57 58 59 |
# File 'lib/ruvim/command_line.rb', line 57 def move_right @cursor += 1 if @cursor < @text.length end |
#replace_span(start_idx, end_idx, replacement, cursor_at: :end) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruvim/command_line.rb', line 27 def replace_span(start_idx, end_idx, replacement, cursor_at: :end) s = [[start_idx.to_i, 0].max, @text.length].min e = [[end_idx.to_i, s].max, @text.length].min rep = replacement.to_s @text = @text[0...s].to_s + rep + @text[e..].to_s @cursor = case cursor_at when :start then s when Integer then [[cursor_at, 0].max, @text.length].min else s + rep.length end end |
#replace_text(str) ⇒ Object
22 23 24 25 |
# File 'lib/ruvim/command_line.rb', line 22 def replace_text(str) @text = str.to_s.dup @cursor = @text.length end |
#reset(prefix: ":") ⇒ Object
11 12 13 14 15 |
# File 'lib/ruvim/command_line.rb', line 11 def reset(prefix: ":") @prefix = prefix @text = +"" @cursor = 0 end |