Class: DynamicCursesInput::InputHandler
- Inherits:
-
Object
- Object
- DynamicCursesInput::InputHandler
- Defined in:
- lib/dynamic_curses_input/input_handler.rb
Overview
our main class for handling input
Class Method Summary collapse
-
.catch_input(echo) ⇒ Object
Class method that initializes a new instance of InputHandler and calls the instance method catch_input.
Instance Method Summary collapse
-
#catch_input ⇒ Object
Main method that catches user input.
-
#initialize(echo) ⇒ InputHandler
constructor
Initialize instance variables and setup curses.
Constructor Details
#initialize(echo) ⇒ InputHandler
Initialize instance variables and setup curses
16 17 18 19 20 21 22 23 |
# File 'lib/dynamic_curses_input/input_handler.rb', line 16 def initialize(echo) @echo = echo # Determines whether input should be echoed to the screen @input = '' # Stores the input string @cursor_pos = 0 # Stores the current cursor position @initial_y = Curses.stdscr.cury # Stores the initial y-coordinate of the cursor @initial_x = Curses.stdscr.curx # Stores the initial x-coordinate of the cursor setup_curses # Setup curses end |
Class Method Details
.catch_input(echo) ⇒ Object
Class method that initializes a new instance of InputHandler and calls the instance method catch_input
11 12 13 |
# File 'lib/dynamic_curses_input/input_handler.rb', line 11 def self.catch_input(echo) new(echo).catch_input end |
Instance Method Details
#catch_input ⇒ Object
Main method that catches user input
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dynamic_curses_input/input_handler.rb', line 26 def catch_input # Loop until the user hits the enter key (represented by :break) while (chk = Curses.getch) break if handle_key(chk) == :break redraw_input # Redraw the input string end Curses.echo if @echo # Echo the input if @echo is true @input # Return the input string end |