yazi_core/manager/commands/
refresh.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::path::MAIN_SEPARATOR;

use crossterm::{execute, terminal::SetTitle};
use yazi_config::MANAGER;
use yazi_fs::CWD;
use yazi_shared::event::CmdCow;

use crate::{manager::Manager, tasks::Tasks};

impl Manager {
	pub fn refresh(&mut self, _: CmdCow, tasks: &Tasks) {
		if CWD.set(self.cwd()) && !MANAGER.title_format.is_empty() {
			execute!(std::io::stderr(), SetTitle(self.title())).ok();
		}

		self.active_mut().apply_files_attrs();

		if let Some(p) = self.parent() {
			self.watcher.trigger_dirs(&[self.current(), p]);
		} else {
			self.watcher.trigger_dirs(&[self.current()]);
		}

		self.hover(None);
		self.update_paged((), tasks);

		tasks.prework_sorted(&self.current().files);
	}

	fn title(&self) -> String {
		let home = dirs::home_dir().unwrap_or_default();
		let cwd = if let Ok(p) = self.cwd().strip_prefix(home) {
			format!("~{}{}", MAIN_SEPARATOR, p.display())
		} else {
			format!("{}", self.cwd().display())
		};

		MANAGER.title_format.replace("{cwd}", &cwd)
	}
}