diff options
| author | Anthony Rubick <68485672+AnthonyMichaelTDM@users.noreply.github.com> | 2023-07-09 20:07:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-10 11:07:09 +0800 |
| commit | 97fc7de6754c8b5c383d7d5e3f9e26b3bbfb08fb (patch) | |
| tree | c19390877425fa50049761e8ee6bc93f21c46f56 /src/repl/mod.rs | |
| parent | ec51b84290215d11d5045de8baa9b89f2447b1e9 (diff) | |
| download | aichat-97fc7de6754c8b5c383d7d5e3f9e26b3bbfb08fb.tar.gz | |
fix: minor code cleanup and pedantic lints (#134)
Diffstat (limited to 'src/repl/mod.rs')
| -rw-r--r-- | src/repl/mod.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 8f3d184..a728e2e 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -55,7 +55,7 @@ impl Repl { Ok(Signal::Success(line)) => { already_ctrlc = false; abort.reset(); - match self.handle_line(handler.clone(), line) { + match self.handle_line(&handler, &line) { Ok(quit) => { if quit { break; @@ -69,12 +69,11 @@ impl Repl { } Ok(Signal::CtrlC) => { abort.set_ctrlc(); - if !already_ctrlc { - already_ctrlc = true; - print_now!("(To exit, press Ctrl+C again or Ctrl+D or type .exit)\n\n"); - } else { + if already_ctrlc { break; } + already_ctrlc = true; + print_now!("(To exit, press Ctrl+C again or Ctrl+D or type .exit)\n\n"); } Ok(Signal::CtrlD) => { abort.set_ctrld(); @@ -86,9 +85,9 @@ impl Repl { Ok(()) } - fn handle_line(&mut self, handler: Arc<ReplCmdHandler>, line: String) -> Result<bool> { - let line = clean_multiline_symbols(&line); - match parse_command(&line) { + fn handle_line(&mut self, handler: &Arc<ReplCmdHandler>, line: &str) -> Result<bool> { + let line = clean_multiline_symbols(line); + match parse_command(line.as_ref()) { Some((cmd, args)) => match cmd { ".exit" => { return Ok(true); @@ -176,7 +175,7 @@ Press Ctrl+C to abort readline, Ctrl+D to exit the REPL fn clean_multiline_symbols(line: &str) -> Cow<str> { let trimed_line = line.trim(); match trimed_line.chars().next() { - Some('{') | Some('[') | Some('(') => trimed_line[1..trimed_line.len() - 1].into(), + Some('{' | '[' | '(') => trimed_line[1..trimed_line.len() - 1].into(), _ => Cow::Borrowed(line), } } |
