mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Use title_format instead of update_title to customize the title bar
This commit is contained in:
parent
9611c4b1bb
commit
0bc222e694
4 changed files with 10 additions and 8 deletions
|
|
@ -14,7 +14,7 @@ show_hidden = false
|
||||||
show_symlink = true
|
show_symlink = true
|
||||||
scrolloff = 5
|
scrolloff = 5
|
||||||
mouse_events = [ "click", "scroll" ]
|
mouse_events = [ "click", "scroll" ]
|
||||||
update_title = true
|
title_format = "Yazi: {cwd}"
|
||||||
|
|
||||||
[preview]
|
[preview]
|
||||||
tab_size = 2
|
tab_size = 2
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub struct Manager {
|
||||||
pub show_symlink: bool,
|
pub show_symlink: bool,
|
||||||
pub scrolloff: u8,
|
pub scrolloff: u8,
|
||||||
pub mouse_events: MouseEvents,
|
pub mouse_events: MouseEvents,
|
||||||
pub update_title: bool,
|
pub title_format: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Manager {
|
impl FromStr for Manager {
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,20 @@ use crate::{manager::Manager, tasks::Tasks};
|
||||||
impl Manager {
|
impl Manager {
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
let home = dirs::home_dir().unwrap_or_default();
|
let home = dirs::home_dir().unwrap_or_default();
|
||||||
if let Some(p) = self.cwd().strip_prefix(home) {
|
let cwd = if let Some(p) = self.cwd().strip_prefix(home) {
|
||||||
format!("Yazi: ~{}{}", MAIN_SEPARATOR, p.display())
|
format!("~{}{}", MAIN_SEPARATOR, p.display())
|
||||||
} else {
|
} else {
|
||||||
format!("Yazi: {}", self.cwd().display())
|
format!("{}", self.cwd().display())
|
||||||
}
|
};
|
||||||
|
|
||||||
|
MANAGER.title_format.replace("{cwd}", &cwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh(&mut self, _: Cmd, tasks: &Tasks) {
|
pub fn refresh(&mut self, _: Cmd, tasks: &Tasks) {
|
||||||
env::set_current_dir(self.cwd()).ok();
|
env::set_current_dir(self.cwd()).ok();
|
||||||
env::set_var("PWD", self.cwd());
|
env::set_var("PWD", self.cwd());
|
||||||
|
|
||||||
if MANAGER.update_title {
|
if !MANAGER.title_format.is_empty() {
|
||||||
execute!(std::io::stderr(), SetTitle(self.title())).ok();
|
execute!(std::io::stderr(), SetTitle(self.title())).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl Term {
|
||||||
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
|
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
if MANAGER.update_title {
|
if !MANAGER.title_format.is_empty() {
|
||||||
execute!(stderr(), SetTitle("")).ok();
|
execute!(stderr(), SetTitle("")).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue