Class: PWN::Plugins::REPL::PwnAIInput
- Inherits:
-
Object
- Object
- PWN::Plugins::REPL::PwnAIInput
- Defined in:
- lib/pwn/plugins/repl.rb
Overview
Custom input handler for pwn-ai to support multi-line submissions:
-
SHIFT+ENTER inserts a newline (continue editing)
-
plain ENTER submits the full prompt (possibly multi-line) to the AI
-
Multi-line pastes are supported (Reline handles n in buffer; submit with ENTER)
Instance Attribute Summary collapse
-
#line_buffer ⇒ Object
readonly
Returns the value of attribute line_buffer.
Instance Method Summary collapse
-
#initialize ⇒ PwnAIInput
constructor
A new instance of PwnAIInput.
- #readline(prompt) ⇒ Object
-
#tty? ⇒ Boolean
Compatibility with Pry input expectations (used by hooks for line_buffer, and possibly completer/tty checks).
- #winsize ⇒ Object
Constructor Details
#initialize ⇒ PwnAIInput
Returns a new instance of PwnAIInput.
23 24 25 |
# File 'lib/pwn/plugins/repl.rb', line 23 def initialize @line_buffer = '' end |
Instance Attribute Details
#line_buffer ⇒ Object (readonly)
Returns the value of attribute line_buffer.
21 22 23 |
# File 'lib/pwn/plugins/repl.rb', line 21 def line_buffer @line_buffer end |
Instance Method Details
#readline(prompt) ⇒ Object
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 |
# File 'lib/pwn/plugins/repl.rb', line 27 def readline(prompt) # Common escape sequences for SHIFT+ENTER across terminals (xterm, modern, etc.) shift_enter_seqs = [ # Only SHIFT+ENTER (user requirement). Plain ENTER = submit. [27, 91, 49, 51, 59, 50, 126], # \e[13;2~ [27, 91, 49, 59, 50, 126], # \e[1;2~ [27, 13], # \e\r [27, 10], # \e\n [27, 91, 49, 51, 59, 50, 117], # \e[13;2u [27, 91, 50, 55, 59, 50, 59, 49, 51, 126], # \e[27;2;13~ [27, 91, 50, 55, 59, 50, 59, 49, 51, 117], # \e[27;2;13u [27, 91, 49, 51, 59, 50, 117], [27, 91, 49, 59, 50, 126], [27, 91, 50, 55, 59, 50, 59, 49, 51, 126] ] shift_enter_seqs.each do |seq| Reline.config.add_oneshot_key_binding(seq.bytes, :key_newline) end begin # readmultiline with confirm block that *always* returns true: # => normal ENTER triggers finish/submit of the (multi-line) buffer # SHIFT+ENTER bytes trigger key_newline (insert \n, stay in edit) # Reline in multiline mode also handles multi-line pastes by splitting on \n in the buffer. @line_buffer = Reline.readmultiline(prompt, true) { |_buffer| true } || '' ensure Reline.config.reset_oneshot_key_bindings end @line_buffer end |
#tty? ⇒ Boolean
Compatibility with Pry input expectations (used by hooks for line_buffer, and possibly completer/tty checks)
59 60 61 |
# File 'lib/pwn/plugins/repl.rb', line 59 def tty? true end |
#winsize ⇒ Object
63 64 65 |
# File 'lib/pwn/plugins/repl.rb', line 63 def winsize [TTY::Screen.rows || 24, TTY::Screen.columns || 80] end |