Class: BruteCLI::REPL::UserInput
- Inherits:
-
Object
- Object
- BruteCLI::REPL::UserInput
- Defined in:
- lib/brute_cli/repl/user_input.rb
Instance Method Summary collapse
-
#initialize(terminal) ⇒ UserInput
constructor
A new instance of UserInput.
-
#read_prompt(status) ⇒ Object
Read one prompt from the user.
-
#refresh_model_line(status) ⇒ Object
Re-render the model/status line in-place (one line above prompt).
Constructor Details
#initialize(terminal) ⇒ UserInput
Returns a new instance of UserInput.
27 28 29 30 31 32 33 |
# File 'lib/brute_cli/repl/user_input.rb', line 27 def initialize(terminal) @terminal = terminal @last_completion_target = nil @pending_intent = nil setup_reline end |
Instance Method Details
#read_prompt(status) ⇒ Object
Read one prompt from the user.
status is a PromptStatus with the current display info. Returns an intent hash (see class doc) or nil on EOF.
39 40 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 |
# File 'lib/brute_cli/repl/user_input.rb', line 39 def read_prompt(status) # If a Tab/Shift-Tab cycle was triggered during the last Reline # session, return that intent immediately so the REPL can update # the agent and re-render. if @pending_intent intent = @pending_intent @pending_intent = nil return intent end print_model_line(status) input = Reline.readmultiline(current_prompt.colorize(ACCENT_BOLD) + " ", true) do |t| !t.rstrip.end_with?("\\") end # A cycle intent was triggered during input — return it instead # of the (empty) text the user entered. if @pending_intent intent = @pending_intent @pending_intent = nil return intent end return nil if input.nil? { type: :input, text: input.gsub(/\\\n/, "\n").strip } end |
#refresh_model_line(status) ⇒ Object
Re-render the model/status line in-place (one line above prompt). Called by the REPL after handling a :cycle_agent intent.
70 71 72 73 74 75 76 77 78 |
# File 'lib/brute_cli/repl/user_input.rb', line 70 def refresh_model_line(status) line = BufferOutput::ModelLine.new( provider_name: status.provider_name, model_short: status.model_short, current_agent: status.current_agent, ).to_s @terminal.buffer.print "\e[s\e[A\r\e[2K#{line}\e[u" @terminal.buffer.flush end |