mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add title_format manager config option (#1281)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
9b7821a161
commit
3533ac20f7
4 changed files with 18 additions and 6 deletions
|
|
@ -14,6 +14,7 @@ show_hidden = false
|
||||||
show_symlink = true
|
show_symlink = true
|
||||||
scrolloff = 5
|
scrolloff = 5
|
||||||
mouse_events = [ "click", "scroll" ]
|
mouse_events = [ "click", "scroll" ]
|
||||||
|
title_format = "Yazi: {cwd}"
|
||||||
|
|
||||||
[preview]
|
[preview]
|
||||||
tab_size = 2
|
tab_size = 2
|
||||||
|
|
|
||||||
|
|
@ -23,6 +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 title_format: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Manager {
|
impl FromStr for Manager {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{env, path::MAIN_SEPARATOR};
|
use std::{env, path::MAIN_SEPARATOR};
|
||||||
|
|
||||||
use crossterm::{execute, terminal::SetTitle};
|
use crossterm::{execute, terminal::SetTitle};
|
||||||
|
use yazi_config::MANAGER;
|
||||||
use yazi_shared::event::Cmd;
|
use yazi_shared::event::Cmd;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
@ -8,17 +9,22 @@ 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());
|
||||||
execute!(std::io::stderr(), SetTitle(self.title())).ok();
|
|
||||||
|
if !MANAGER.title_format.is_empty() {
|
||||||
|
execute!(std::io::stderr(), SetTitle(self.title())).ok();
|
||||||
|
}
|
||||||
|
|
||||||
self.active_mut().apply_files_attrs();
|
self.active_mut().apply_files_attrs();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crossterm::{event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnh
|
||||||
use cursor::RestoreCursor;
|
use cursor::RestoreCursor;
|
||||||
use ratatui::{backend::CrosstermBackend, buffer::Buffer, layout::Rect, CompletedFrame, Frame, Terminal};
|
use ratatui::{backend::CrosstermBackend, buffer::Buffer, layout::Rect, CompletedFrame, Frame, Terminal};
|
||||||
use yazi_adapter::Emulator;
|
use yazi_adapter::Emulator;
|
||||||
use yazi_config::INPUT;
|
use yazi_config::{INPUT, MANAGER};
|
||||||
|
|
||||||
static CSI_U: AtomicBool = AtomicBool::new(false);
|
static CSI_U: AtomicBool = AtomicBool::new(false);
|
||||||
static BLINK: AtomicBool = AtomicBool::new(false);
|
static BLINK: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
@ -85,6 +85,10 @@ impl Term {
|
||||||
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
|
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !MANAGER.title_format.is_empty() {
|
||||||
|
execute!(stderr(), SetTitle("")).ok();
|
||||||
|
}
|
||||||
|
|
||||||
execute!(
|
execute!(
|
||||||
stderr(),
|
stderr(),
|
||||||
mouse::SetMouse(false),
|
mouse::SetMouse(false),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue