diff --git a/locales/en.yml b/locales/en.yml index 156b1cd..a95b9ac 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -111,6 +111,7 @@ zombie_reason: "This transfer was interrupted because the application exited. Th software_builtin: "Built-in" retry: "Retry" right_click_copy_paste: "Right-click Copy/Paste" +keyword_highlight: "Terminal Keyword Highlighting" copy_paste_hint: "Regardless of this switch, you can always use %{key} + C/V to copy/paste." edit_file: "Edit File" edit_file_tooltip: "Download to temporary directory, open in default editor, and auto upload on save." diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index d2ec0c8..bbe7e3f 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -112,6 +112,7 @@ zombie_reason: "此传输任务因程序退出而中断,传输进程已不存 software_builtin: "软件内置" retry: "重试" right_click_copy_paste: "右键复制/粘贴" +keyword_highlight: "终端关键词高亮" copy_paste_hint: "不管是否开启此开关,都可以使用 %{key} + C/V 快捷键进行复制和粘贴。" edit_file: "编辑文件" edit_file_tooltip: "下载到临时目录,使用默认编辑器打开,并在保存后自动上传。" diff --git a/src/app/dialogs.rs b/src/app/dialogs.rs index 8fd5c3f..60ec5eb 100644 --- a/src/app/dialogs.rs +++ b/src/app/dialogs.rs @@ -1544,6 +1544,25 @@ impl Ashell { }) ).description(t!("copy_paste_hint", key = if cfg!(target_os = "macos") { "Command" } else { "Ctrl" }).to_string()) ) + .item( + SettingItem::new( + t!("keyword_highlight").to_string(), + SettingField::render({ + let view = view_clone_for_general.clone(); + move |_, window, cx| { + Switch::new("keyword-highlight") + .small() + .checked(view.read(cx).config.keyword_highlight()) + .on_click(window.listener_for(&view, |this, checked, _, cx| { + this.config.set_keyword_highlight(*checked); + let _ = this.config.save(); + cx.notify(); + })) + .into_any_element() + } + }) + ) + ) .item( SettingItem::new( t!("monitoring_position").to_string(), diff --git a/src/session/config.rs b/src/session/config.rs index f635241..fa238aa 100644 --- a/src/session/config.rs +++ b/src/session/config.rs @@ -146,6 +146,8 @@ pub struct ConfigFile { pub ui_font_size: f32, #[serde(default)] pub right_click_copy_paste: bool, + #[serde(default)] + pub keyword_highlight: bool, #[serde(default = "default_ui_font_family")] pub ui_font_family: String, #[serde(default = "default_terminal_font_family")] @@ -534,6 +536,14 @@ impl ConfigStore { self.cache.right_click_copy_paste = val; } + pub fn keyword_highlight(&self) -> bool { + self.cache.keyword_highlight + } + + pub fn set_keyword_highlight(&mut self, val: bool) { + self.cache.keyword_highlight = val; + } + pub fn terminal_font_family(&self) -> &str { if self.cache.terminal_font_family.is_empty() { "Maple Mono NF CN" diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index bf9b84f..4a7d0d5 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -332,8 +332,12 @@ impl TerminalTab { }); } - // Get highlights from cache or recompute - let highlights = { + // Get highlights from cache or recompute, only if keyword_highlight is enabled. + let is_enabled = crate::session::config::ConfigStore::load() + .map(|c| c.keyword_highlight()) + .unwrap_or(false); + + let highlights = if is_enabled { let mut cache = self.highlight_cache.borrow_mut(); let cache_valid = cache.as_ref().map_or(false, |(cached_cells, _)| { cached_cells == &cells @@ -345,6 +349,8 @@ impl TerminalTab { *cache = Some((cells.clone(), computed.clone())); computed } + } else { + std::collections::HashMap::new() }; RenderSnapshot {