From 0bc222e6948553c890e76c6d4a1f2827aa9548a6 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 2 Aug 2024 16:02:05 +0800 Subject: [PATCH] Use `title_format` instead of `update_title` to customize the title bar --- yazi-config/preset/yazi.toml | 2 +- yazi-config/src/manager/manager.rs | 2 +- yazi-core/src/manager/commands/refresh.rs | 12 +++++++----- yazi-fm/src/term.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 7dc05fb5..865c3531 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -14,7 +14,7 @@ show_hidden = false show_symlink = true scrolloff = 5 mouse_events = [ "click", "scroll" ] -update_title = true +title_format = "Yazi: {cwd}" [preview] tab_size = 2 diff --git a/yazi-config/src/manager/manager.rs b/yazi-config/src/manager/manager.rs index 87736d93..8e48bbde 100644 --- a/yazi-config/src/manager/manager.rs +++ b/yazi-config/src/manager/manager.rs @@ -23,7 +23,7 @@ pub struct Manager { pub show_symlink: bool, pub scrolloff: u8, pub mouse_events: MouseEvents, - pub update_title: bool, + pub title_format: String, } impl FromStr for Manager { diff --git a/yazi-core/src/manager/commands/refresh.rs b/yazi-core/src/manager/commands/refresh.rs index ac750a7f..553e8cb7 100644 --- a/yazi-core/src/manager/commands/refresh.rs +++ b/yazi-core/src/manager/commands/refresh.rs @@ -9,18 +9,20 @@ use crate::{manager::Manager, tasks::Tasks}; impl Manager { fn title(&self) -> String { let home = dirs::home_dir().unwrap_or_default(); - if let Some(p) = self.cwd().strip_prefix(home) { - format!("Yazi: ~{}{}", MAIN_SEPARATOR, p.display()) + let cwd = if let Some(p) = self.cwd().strip_prefix(home) { + format!("~{}{}", MAIN_SEPARATOR, p.display()) } else { - format!("Yazi: {}", self.cwd().display()) - } + format!("{}", self.cwd().display()) + }; + + MANAGER.title_format.replace("{cwd}", &cwd) } pub fn refresh(&mut self, _: Cmd, tasks: &Tasks) { env::set_current_dir(self.cwd()).ok(); env::set_var("PWD", self.cwd()); - if MANAGER.update_title { + if !MANAGER.title_format.is_empty() { execute!(std::io::stderr(), SetTitle(self.title())).ok(); } diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index 987c290f..588bd0d6 100644 --- a/yazi-fm/src/term.rs +++ b/yazi-fm/src/term.rs @@ -73,7 +73,7 @@ impl Term { execute!(stderr(), PopKeyboardEnhancementFlags).ok(); } - if MANAGER.update_title { + if !MANAGER.title_format.is_empty() { execute!(stderr(), SetTitle("")).ok(); }