Class: Escort::Formatter::CursorPosition

Inherits:
Object
  • Object
show all
Defined in:
lib/escort/formatter/cursor_position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_line_width) ⇒ CursorPosition

Returns a new instance of CursorPosition


6
7
8
9
# File 'lib/escort/formatter/cursor_position.rb', line 6

def initialize(max_line_width)
  @max_line_width = max_line_width
  reset
end

Instance Attribute Details

#max_line_widthObject (readonly)

Returns the value of attribute max_line_width


4
5
6
# File 'lib/escort/formatter/cursor_position.rb', line 4

def max_line_width
  @max_line_width
end

#positionObject (readonly)

Returns the value of attribute position


4
5
6
# File 'lib/escort/formatter/cursor_position.rb', line 4

def position
  @position
end

Instance Method Details

#chars_to_end_of_lineObject


24
25
26
# File 'lib/escort/formatter/cursor_position.rb', line 24

def chars_to_end_of_line
  max_line_width - position
end

#newline?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/escort/formatter/cursor_position.rb', line 16

def newline?
  @position == 0
end

#resetObject


20
21
22
# File 'lib/escort/formatter/cursor_position.rb', line 20

def reset
  @position = 0
end

#update_for(string) ⇒ Object


11
12
13
14
# File 'lib/escort/formatter/cursor_position.rb', line 11

def update_for(string)
  @position += string.length
  raise Escort::InternalError.new("Cursor position for help output is out of bounds") if position > max_line_width
end