Class: DynamicCursesInput::CursorMover

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_curses_input/input_handler.rb

Overview

Class for moving the cursor

Class Method Summary collapse

Class Method Details

.down(_, length) ⇒ Object

Handle down arrow key



119
120
121
# File 'lib/dynamic_curses_input/input_handler.rb', line 119

def self.down(_, length)
  length # Move to the end of the line
end

.left(cursor_pos) ⇒ Object

Move cursor left



109
110
111
# File 'lib/dynamic_curses_input/input_handler.rb', line 109

def self.left(cursor_pos)
  cursor_pos.zero? ? cursor_pos : cursor_pos - 1
end

.right(cursor_pos, length) ⇒ Object

Move cursor right



114
115
116
# File 'lib/dynamic_curses_input/input_handler.rb', line 114

def self.right(cursor_pos, length)
  cursor_pos == length ? cursor_pos : cursor_pos + 1
end

.set_position(y, x) ⇒ Object

Set cursor position



129
130
131
# File 'lib/dynamic_curses_input/input_handler.rb', line 129

def self.set_position(y, x) # rubocop:disable Naming/MethodParameterName
  Curses.setpos(y, x)
end

.up(_, _length) ⇒ Object

Handle up arrow key



124
125
126
# File 'lib/dynamic_curses_input/input_handler.rb', line 124

def self.up(_, _length)
  0 # Move to the beginning of the line (position 0)
end