diff --git a/crates/agent/src/terminal_codegen.rs b/crates/agent/src/terminal_codegen.rs index 925187c7cf89bf07a20ad4e15a49b221c4cba138..42084024175657c21d010ae06260a1167a356ed3 100644 --- a/crates/agent/src/terminal_codegen.rs +++ b/crates/agent/src/terminal_codegen.rs @@ -193,7 +193,8 @@ impl TerminalTransaction { }); } - fn sanitize_input(input: String) -> String { - input.replace(['\r', '\n'], "") + fn sanitize_input(mut input: String) -> String { + input.retain(|c| c != '\r' && c != '\n'); + input } } diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index 7a96aba4e50eaa117dc933d1753a9ae004dfba76..b49c5e29dc3d3ffd56c44ecb2a21f20b36c211ea 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -264,7 +264,7 @@ impl Project { }, ) } - None => (None, settings.shell.clone()), + None => (None, settings.shell), } } TerminalKind::Task(spawn_task) => { diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 507fd4df1004d22fccfce2cce31821c9c958e476..21100f42c129b3d0649ff994d5a560ea853f96fa 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -49,6 +49,7 @@ use theme::{ActiveTheme, Theme}; use util::{paths::home_dir, truncate_and_trailoff}; use std::{ + borrow::Cow, cmp::{self, min}, fmt::Display, ops::{Deref, Index, RangeInclusive}, @@ -516,7 +517,7 @@ impl TerminalBuilder { while let Some(event) = self.events_rx.next().await { terminal.update(cx, |terminal, cx| { //Process the first event immediately for lowered latency - terminal.process_event(&event, cx); + terminal.process_event(event, cx); })?; 'outer: loop { @@ -554,11 +555,11 @@ impl TerminalBuilder { terminal.update(cx, |this, cx| { if wakeup { - this.process_event(&AlacTermEvent::Wakeup, cx); + this.process_event(AlacTermEvent::Wakeup, cx); } for event in events { - this.process_event(&event, cx); + this.process_event(event, cx); } })?; smol::future::yield_now().await; @@ -704,10 +705,10 @@ impl TaskStatus { } impl Terminal { - fn process_event(&mut self, event: &AlacTermEvent, cx: &mut Context) { + fn process_event(&mut self, event: AlacTermEvent, cx: &mut Context) { match event { AlacTermEvent::Title(title) => { - self.breadcrumb_text = title.to_string(); + self.breadcrumb_text = title; cx.emit(Event::BreadcrumbsChanged); } AlacTermEvent::ResetTitle => { @@ -715,7 +716,7 @@ impl Terminal { cx.emit(Event::BreadcrumbsChanged); } AlacTermEvent::ClipboardStore(_, data) => { - cx.write_to_clipboard(ClipboardItem::new_string(data.to_string())) + cx.write_to_clipboard(ClipboardItem::new_string(data)) } AlacTermEvent::ClipboardLoad(_, format) => { self.write_to_pty( @@ -726,7 +727,7 @@ impl Terminal { }, ) } - AlacTermEvent::PtyWrite(out) => self.write_to_pty(out.clone()), + AlacTermEvent::PtyWrite(out) => self.write_to_pty(out), AlacTermEvent::TextAreaSizeRequest(format) => { self.write_to_pty(format(self.last_content.terminal_bounds.into())) } @@ -758,13 +759,12 @@ impl Terminal { // Instead of locking, we could store the colors in `self.last_content`. But then // we might respond with out of date value if a "set color" sequence is immediately // followed by a color request sequence. - let color = self.term.lock().colors()[*index].unwrap_or_else(|| { - to_alac_rgb(get_color_at_index(*index, cx.theme().as_ref())) - }); + let color = self.term.lock().colors()[index] + .unwrap_or_else(|| to_alac_rgb(get_color_at_index(index, cx.theme().as_ref()))); self.write_to_pty(format(color)); } AlacTermEvent::ChildExit(error_code) => { - self.register_task_finished(Some(*error_code), cx); + self.register_task_finished(Some(error_code), cx); } } } @@ -1087,7 +1087,7 @@ impl Terminal { } self.last_content.last_hovered_word = Some(HoveredWord { - word: word.clone(), + word, word_match, id: self.next_link_id(), }); @@ -1248,12 +1248,13 @@ impl Terminal { return; } - let mut key = keystroke.key.clone(); - if keystroke.modifiers.shift { - key = key.to_uppercase(); - } + let key: Cow<'_, str> = if keystroke.modifiers.shift { + Cow::Owned(keystroke.key.to_uppercase()) + } else { + Cow::Borrowed(keystroke.key.as_str()) + }; - let motion: Option = match key.as_str() { + let motion: Option = match key.as_ref() { "h" | "left" => Some(ViMotion::Left), "j" | "down" => Some(ViMotion::Down), "k" | "up" => Some(ViMotion::Up), @@ -1283,7 +1284,7 @@ impl Terminal { return; } - let scroll_motion = match key.as_str() { + let scroll_motion = match key.as_ref() { "g" => Some(AlacScroll::Top), "G" => Some(AlacScroll::Bottom), "b" if keystroke.modifiers.control => Some(AlacScroll::PageUp), @@ -1304,7 +1305,7 @@ impl Terminal { return; } - match key.as_str() { + match key.as_ref() { "v" => { let point = self.last_content.cursor.point; let selection_type = SelectionType::Simple;