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

Method read_line

crates/chat-cli/src/cli/chat/input_source.rs:107–128  ·  view source on GitHub ↗
(&mut self, prompt: Option<&str>)

Source from the content-addressed store, hash-verified

105 }
106
107 pub fn read_line(&mut self, prompt: Option<&str>) -> Result<Option<String>, ReadlineError> {
108 match &mut self.inner {
109 inner::Inner::Readline(rl) => {
110 let prompt = prompt.unwrap_or_default();
111 let curr_line = rl.readline(prompt);
112 match curr_line {
113 Ok(line) => {
114 if Self::should_append_history(&line) {
115 let _ = rl.add_history_entry(line.as_str());
116 }
117 Ok(Some(line))
118 },
119 Err(ReadlineError::Interrupted | ReadlineError::Eof) => Ok(None),
120 Err(err) => Err(err),
121 }
122 },
123 inner::Inner::Mock { index, lines } => {
124 *index += 1;
125 Ok(lines.get(*index - 1).cloned())
126 },
127 }
128 }
129
130 fn should_append_history(line: &str) -> bool {
131 let trimmed = line.trim().to_lowercase();

Callers 3

read_user_inputMethod · 0.80
get_user_confirmationFunction · 0.80
handle_clearMethod · 0.80

Calls 2

as_strMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected