(&mut self, os: &mut Os, mut user_input: String)
| 2117 | } |
| 2118 | |
| 2119 | async fn handle_input(&mut self, os: &mut Os, mut user_input: String) -> Result<ChatState, ChatError> { |
| 2120 | queue!(self.stderr, style::Print('\n'))?; |
| 2121 | user_input = sanitize_unicode_tags(&user_input); |
| 2122 | let input = user_input.trim(); |
| 2123 | |
| 2124 | // handle image path |
| 2125 | if let Some(chat_state) = does_input_reference_file(input) { |
| 2126 | return Ok(chat_state); |
| 2127 | } |
| 2128 | if let Some(mut args) = input.strip_prefix("/").and_then(shlex::split) { |
| 2129 | // Required for printing errors correctly. |
| 2130 | let orig_args = args.clone(); |
| 2131 | |
| 2132 | // We set the binary name as a dummy name "slash_command" which we |
| 2133 | // replace anytime we error out and print a usage statement. |
| 2134 | args.insert(0, "slash_command".to_owned()); |
| 2135 | |
| 2136 | match SlashCommand::try_parse_from(args) { |
| 2137 | Ok(command) => { |
| 2138 | let command_name = command.command_name().to_string(); |
| 2139 | let subcommand_name = command.subcommand_name().map(|s| s.to_string()); |
| 2140 | |
| 2141 | match command.execute(os, self).await { |
| 2142 | Ok(chat_state) => { |
| 2143 | let _ = self |
| 2144 | .send_slash_command_telemetry( |
| 2145 | os, |
| 2146 | command_name, |
| 2147 | subcommand_name, |
| 2148 | TelemetryResult::Succeeded, |
| 2149 | None, |
| 2150 | ) |
| 2151 | .await; |
| 2152 | |
| 2153 | if matches!(chat_state, ChatState::Exit) |
| 2154 | || matches!(chat_state, ChatState::HandleResponseStream(_)) |
| 2155 | || matches!(chat_state, ChatState::HandleInput { input: _ }) |
| 2156 | // TODO(bskiser): this is just a hotfix for handling state changes |
| 2157 | // from manually running /compact, without impacting behavior of |
| 2158 | // other slash commands. |
| 2159 | || matches!(chat_state, ChatState::CompactHistory { .. }) |
| 2160 | { |
| 2161 | return Ok(chat_state); |
| 2162 | } |
| 2163 | }, |
| 2164 | Err(err) => { |
| 2165 | queue!( |
| 2166 | self.stderr, |
| 2167 | StyledText::error_fg(), |
| 2168 | style::Print(format!("\nFailed to execute command: {}\n", err)), |
| 2169 | StyledText::reset(), |
| 2170 | )?; |
| 2171 | let _ = self |
| 2172 | .send_slash_command_telemetry( |
| 2173 | os, |
| 2174 | command_name, |
| 2175 | subcommand_name, |
| 2176 | TelemetryResult::Failed, |
nothing calls this directly
no test coverage detected