Skip to content

Commit

Permalink
feat: add title_format manager config option (#1281)
Browse files Browse the repository at this point in the history
Co-authored-by: sxyazi <sxyazi@gmail.com>
  • Loading branch information
chriszarate and sxyazi authored Aug 2, 2024
1 parent 9b7821a commit 3533ac2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ show_hidden = false
show_symlink = true
scrolloff = 5
mouse_events = [ "click", "scroll" ]
title_format = "Yazi: {cwd}"

[preview]
tab_size = 2
Expand Down
1 change: 1 addition & 0 deletions yazi-config/src/manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Manager {
pub show_symlink: bool,
pub scrolloff: u8,
pub mouse_events: MouseEvents,
pub title_format: String,
}

impl FromStr for Manager {
Expand Down
16 changes: 11 additions & 5 deletions yazi-core/src/manager/commands/refresh.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
use std::{env, path::MAIN_SEPARATOR};

use crossterm::{execute, terminal::SetTitle};
use yazi_config::MANAGER;
use yazi_shared::event::Cmd;

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());
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();

Expand Down
6 changes: 5 additions & 1 deletion yazi-fm/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crossterm::{event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnh
use cursor::RestoreCursor;
use ratatui::{backend::CrosstermBackend, buffer::Buffer, layout::Rect, CompletedFrame, Frame, Terminal};
use yazi_adapter::Emulator;
use yazi_config::INPUT;
use yazi_config::{INPUT, MANAGER};

static CSI_U: AtomicBool = AtomicBool::new(false);
static BLINK: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -85,6 +85,10 @@ impl Term {
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
}

if !MANAGER.title_format.is_empty() {
execute!(stderr(), SetTitle("")).ok();
}

execute!(
stderr(),
mouse::SetMouse(false),
Expand Down

0 comments on commit 3533ac2

Please sign in to comment.