From d07bfc1d6838865722547aec91e3846b85fce0d7 Mon Sep 17 00:00:00 2001 From: VetheonGames <76892542+VetheonGames@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:29:08 -0600 Subject: [PATCH] Created InputHandler (markdown) --- InputHandler.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 InputHandler.md diff --git a/InputHandler.md b/InputHandler.md new file mode 100644 index 0000000..01dadee --- /dev/null +++ b/InputHandler.md @@ -0,0 +1,55 @@ +# InputHandler Class + +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. + +## Methods + +### .catch_input(echo) + +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. + +### initialize(echo) + +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. + +### catch_input + +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. + +### handle_key(chk) + +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`. + +### handle_left_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. + +### handle_right_key + +This private instance method handles the Right arrow key. It moves the cursor one position to the right by calling the `CursorMover.right` method. + +### handle_backspace_key + +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. + +### handle_enter_key + +This private instance method handles the Enter key. It breaks the loop in the `catch_input` method. + +### handle_default_key(chk) + +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. + +### redraw_input + +This private instance method redraws the input. It clears the line, prints the input string, and moves the cursor to the correct position. \ No newline at end of file