-
Notifications
You must be signed in to change notification settings - Fork 0
InputHandler
The InputHandler
class is the main class for handling user input in the DynamicCursesInput gem. It is responsible for capturing user keystrokes and managing the input string and cursor position accordingly.
This is a class method that creates a new instance of InputHandler
and calls the catch_input
instance method on it. It takes one parameter:
-
echo
: a boolean value that determines whether the input should be echoed back to the user.
This is the constructor for the InputHandler
class. It initializes the instance variables and sets up Curses. It takes one parameter:
-
echo
: a boolean value that determines whether the input should be echoed back to the user.
This instance method captures user keystrokes until the Enter key is pressed. It handles each keystroke by calling the handle_key
method and then redraws the input by calling the redraw_input
method. It returns the input string when the Enter key is pressed.
This private instance method handles a single keystroke. It takes one parameter:
-
chk
: the keystroke to handle.
Depending on the value of chk
, it calls one of the following methods: handle_left_key
, handle_right_key
, handle_backspace_key
, handle_enter_key
, or handle_default_key
.
This private instance method handles the Left arrow key. It moves the cursor one position to the left by calling the CursorMover.left
method.
This private instance method handles the Right arrow key. It moves the cursor one position to the right by calling the CursorMover.right
method.
This private instance method handles the Backspace key. It deletes the character at the cursor position and moves the cursor one position to the left by calling the CharacterDeleter.delete
method.
This private instance method handles the Enter key. It breaks the loop in the catch_input
method.
This private instance method handles any other keystroke. It adds the character at the cursor position and moves the cursor one position to the right by calling the CharacterAdder.add
method. It takes one parameter:
-
chk
: the keystroke to handle.
This private instance method redraws the input. It clears the line, prints the input string, and moves the cursor to the correct position.