Class: Aidp::CLI::EnhancedInput
- Inherits:
-
Object
- Object
- Aidp::CLI::EnhancedInput
- Defined in:
- lib/aidp/cli/enhanced_input.rb
Overview
Enhanced input handler with full readline-style key bindings using Reline
Instance Attribute Summary collapse
-
#show_hints ⇒ Object
readonly
Standard key bindings supported by Reline: - Ctrl-A: Move to beginning of line - Ctrl-E: Move to end of line - Ctrl-W: Delete word backward - Ctrl-K: Kill to end of line - Ctrl-U: Kill to beginning of line - Ctrl-D: Delete character forward - Ctrl-H/Backspace: Delete character backward - Left/Right arrows: Move cursor - Alt-F/Alt-B: Move forward/backward by word - Home/End: Jump to beginning/end - Ctrl-T: Transpose characters - And many more Emacs-style bindings.
-
#use_reline ⇒ Object
readonly
Standard key bindings supported by Reline: - Ctrl-A: Move to beginning of line - Ctrl-E: Move to end of line - Ctrl-W: Delete word backward - Ctrl-K: Kill to end of line - Ctrl-U: Kill to beginning of line - Ctrl-D: Delete character forward - Ctrl-H/Backspace: Delete character backward - Left/Right arrows: Move cursor - Alt-F/Alt-B: Move forward/backward by word - Home/End: Jump to beginning/end - Ctrl-T: Transpose characters - And many more Emacs-style bindings.
Instance Method Summary collapse
-
#ask(question, **options) ⇒ Object
Ask a question with full readline support Uses Reline for readline-style editing when use_reline is true.
-
#disable_reline! ⇒ Object
Disable Reline (fall back to TTY::Prompt).
-
#enable_hints! ⇒ Object
Enable hints for key bindings.
-
#enable_reline! ⇒ Object
Enable Reline.
-
#initialize(prompt: nil, input: nil, output: nil, use_reline: true) ⇒ EnhancedInput
constructor
A new instance of EnhancedInput.
-
#method_missing(method, *args, **kwargs, &block) ⇒ Object
Delegate other methods to underlying prompt.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(prompt: nil, input: nil, output: nil, use_reline: true) ⇒ EnhancedInput
Returns a new instance of EnhancedInput.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aidp/cli/enhanced_input.rb', line 26 def initialize(prompt: nil, input: nil, output: nil, use_reline: true) @use_reline = use_reline @input = input || $stdin @output = output || $stdout @prompt = prompt || TTY::Prompt.new( input: @input, output: @output, enable_color: true, interrupt: :exit ) @show_hints = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
Delegate other methods to underlying prompt
107 108 109 |
# File 'lib/aidp/cli/enhanced_input.rb', line 107 def method_missing(method, *args, **kwargs, &block) @prompt.send(method, *args, **kwargs, &block) end |
Instance Attribute Details
#show_hints ⇒ Object (readonly)
Standard key bindings supported by Reline:
-
Ctrl-A: Move to beginning of line
-
Ctrl-E: Move to end of line
-
Ctrl-W: Delete word backward
-
Ctrl-K: Kill to end of line
-
Ctrl-U: Kill to beginning of line
-
Ctrl-D: Delete character forward
-
Ctrl-H/Backspace: Delete character backward
-
Left/Right arrows: Move cursor
-
Alt-F/Alt-B: Move forward/backward by word
-
Home/End: Jump to beginning/end
-
Ctrl-T: Transpose characters
-
And many more Emacs-style bindings
24 25 26 |
# File 'lib/aidp/cli/enhanced_input.rb', line 24 def show_hints @show_hints end |
#use_reline ⇒ Object (readonly)
Standard key bindings supported by Reline:
-
Ctrl-A: Move to beginning of line
-
Ctrl-E: Move to end of line
-
Ctrl-W: Delete word backward
-
Ctrl-K: Kill to end of line
-
Ctrl-U: Kill to beginning of line
-
Ctrl-D: Delete character forward
-
Ctrl-H/Backspace: Delete character backward
-
Left/Right arrows: Move cursor
-
Alt-F/Alt-B: Move forward/backward by word
-
Home/End: Jump to beginning/end
-
Ctrl-T: Transpose characters
-
And many more Emacs-style bindings
24 25 26 |
# File 'lib/aidp/cli/enhanced_input.rb', line 24 def use_reline @use_reline end |
Instance Method Details
#ask(question, **options) ⇒ Object
Ask a question with full readline support Uses Reline for readline-style editing when use_reline is true
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/aidp/cli/enhanced_input.rb', line 41 def ask(question, **) # If reline is enabled and we're in a TTY, use reline for better editing if @use_reline && @input.tty? default = [:default] required = [:required] || false # Display helpful hint on first use if @show_hints @output.puts "💡 Hint: Use Ctrl-A (start), Ctrl-E (end), Ctrl-W (delete word), Ctrl-K (kill line)" @show_hints = false end # Use Reline for input with full key binding support loop do prompt_text = question.to_s prompt_text += " (#{default})" if default prompt_text += " " # Reline provides full readline editing capabilities Reline.output = @output Reline.input = @input Reline.completion_append_character = " " answer = Reline.readline(prompt_text, false) # Handle Ctrl-D (nil return) if answer.nil? @output.puts raise Interrupt end answer = answer.strip answer = default if answer.empty? && default if required && (answer.nil? || answer.empty?) @output.puts " Value required." next end return answer end else # Fall back to TTY::Prompt's ask @prompt.ask(question, **) end rescue Interrupt @output.puts raise end |
#disable_reline! ⇒ Object
Disable Reline (fall back to TTY::Prompt)
97 98 99 |
# File 'lib/aidp/cli/enhanced_input.rb', line 97 def disable_reline! @use_reline = false end |
#enable_hints! ⇒ Object
Enable hints for key bindings
92 93 94 |
# File 'lib/aidp/cli/enhanced_input.rb', line 92 def enable_hints! @show_hints = true end |
#enable_reline! ⇒ Object
Enable Reline
102 103 104 |
# File 'lib/aidp/cli/enhanced_input.rb', line 102 def enable_reline! @use_reline = true end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
111 112 113 |
# File 'lib/aidp/cli/enhanced_input.rb', line 111 def respond_to_missing?(method, include_private = false) @prompt.respond_to?(method, include_private) || super end |