MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / read_user_input

Method read_user_input

crates/chat-cli/src/cli/chat/mod.rs:3563–3591  ·  view source on GitHub ↗

Helper function to read user input with a prompt and Ctrl+C handling

(&mut self, prompt: &str, exit_on_single_ctrl_c: bool)

Source from the content-addressed store, hash-verified

3561
3562 /// Helper function to read user input with a prompt and Ctrl+C handling
3563 fn read_user_input(&mut self, prompt: &str, exit_on_single_ctrl_c: bool) -> Option<String> {
3564 let mut ctrl_c = false;
3565 loop {
3566 match (self.input_source.read_line(Some(prompt)), ctrl_c) {
3567 (Ok(Some(line)), _) => {
3568 if line.trim().is_empty() {
3569 continue; // Reprompt if the input is empty
3570 }
3571 return Some(line);
3572 },
3573 (Ok(None), false) => {
3574 if exit_on_single_ctrl_c {
3575 return None;
3576 }
3577 execute!(
3578 self.stderr,
3579 style::Print(format!(
3580 "\n(To exit the CLI, press Ctrl+C or Ctrl+D again or type {})\n\n",
3581 "/quit".green()
3582 ))
3583 )
3584 .unwrap_or_default();
3585 ctrl_c = true;
3586 },
3587 (Ok(None), true) => return None, // Exit if Ctrl+C was pressed twice
3588 (Err(_), _) => return None,
3589 }
3590 }
3591 }
3592
3593 /// Helper function to generate a prompt based on the current context
3594 async fn generate_tool_trust_prompt(&mut self, os: &Os) -> String {

Callers 3

prompt_userMethod · 0.80
upgrade_to_proFunction · 0.80
executeMethod · 0.80

Calls 2

read_lineMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected