Module: DynamicCursesInput
- Defined in:
- lib/dynamic_curses_input.rb,
lib/dynamic_curses_input/version.rb,
lib/dynamic_curses_input/color_window.rb,
lib/dynamic_curses_input/input_handler.rb
Overview
The module entrypoint for our Gem
Defined Under Namespace
Classes: CharacterAdder, CharacterDeleter, ColorWindow, CursorMover, Error, InputHandler
Constant Summary collapse
- VERSION =
'1.2.2'
Class Method Summary collapse
-
.ask_question(color = 'white', question, x: 'center', input: true, echo: nil) ⇒ Object
rubocop:disable Naming/MethodParameterName.
-
.catch_input(echo) ⇒ Object
Whether or not to output the user entered text to STDOUT.
-
.print_color_window(color, text, y_value: nil, x: 'center', input: nil, echo: true) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ParameterLists, Naming/MethodParameterName.
- .setup_readline ⇒ Object
Class Method Details
.ask_question(color = 'white', question, x: 'center', input: true, echo: nil) ⇒ Object
rubocop:disable Naming/MethodParameterName
19 20 21 22 |
# File 'lib/dynamic_curses_input.rb', line 19 def self.ask_question(color = 'white', question, x: 'center', input: true, echo: nil) # rubocop:disable Naming/MethodParameterName Curses.clear ColorWindow.add_color_window(color, question, y:, x:, input:, echo:) end |
.catch_input(echo) ⇒ Object
Whether or not to output the user entered text to STDOUT
15 16 17 |
# File 'lib/dynamic_curses_input.rb', line 15 def self.catch_input(echo) InputHandler.catch_input(echo) end |
.print_color_window(color, text, y_value: nil, x: 'center', input: nil, echo: true) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ParameterLists, Naming/MethodParameterName
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dynamic_curses_input.rb', line 24 def self.print_color_window(color, text, y_value: nil, x: 'center', input: nil, echo: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ParameterLists, Naming/MethodParameterName case x when 'center' terminal_size = `stty size`.split.map(&:to_i) y_value = terminal_size[0] / 2 x_value = terminal_size[1] / 2 - text.length / 2 # Adjust x-coordinate to center the window x_value -= 12 if x_value > 1 # the above line shifts the X value of the cell coords back by 12 cells if we are trying to center the window # we have to do this because math gets kind of approximate when we convert pixel ratios to character cell coords when 'left' y_value = Curses.lines / 2 x_value = 0 when 'right' y_value = Curses.lines / 2 x_value = Curses.cols - text.length when 'left_center' y_value = Curses.lines / 4 x_value = 0 when 'right_center' y_value = Curses.lines / 4 x_value = Curses.cols - text.length else y_value, x_value = x.split('px').map(&:to_i) end # Initialize curses and get the terminal size Curses.init_screen Curses.start_color Curses.refresh # Set up Readline for proper terminal settings setup_readline ColorWindow.new(echo, x_value, y_value).add_color_window(color, text, x_value, y_value, input:, echo:) end |
.setup_readline ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/dynamic_curses_input.rb', line 79 def self.setup_readline # Set up Readline for proper terminal settings Readline.emacs_editing_mode # the above line sets Readline to emacs_editing_mode so that terminals behave like they're supposed to Readline.completion_append_character = ' ' # we remove Readlines thing where it adds a space to the end of tab completes because it breaks the Curses cursor Readline.completion_proc = proc { |_s| [] } # here we basically are disabling tab completion all together. That's because for some reason it breaks the cursor end |