Add update_title manager config option

The `update_title` config option controls whether Yazi updates the
terminal title using ANSI escape sequences. For some users, this
behavior is undesirable since:

1. Yazi may be invoked within another process (like Vim). If Yazi
	 updates the terminal title, it overrides the title set by / for the
	 parent process.
2. Users may have their own mechanisms for setting the terminal title
	 and may not want it overridden.
This commit is contained in:
chriszarate 2024-07-10 18:18:54 -04:00
parent 54eb0cc663
commit 9611c4b1bb
No known key found for this signature in database
4 changed files with 12 additions and 3 deletions

View file

@ -14,6 +14,7 @@ show_hidden = false
show_symlink = true
scrolloff = 5
mouse_events = [ "click", "scroll" ]
update_title = true
[preview]
tab_size = 2

View file

@ -23,6 +23,7 @@ pub struct Manager {
pub show_symlink: bool,
pub scrolloff: u8,
pub mouse_events: MouseEvents,
pub update_title: bool,
}
impl FromStr for Manager {

View file

@ -1,6 +1,7 @@
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};
@ -18,7 +19,10 @@ impl Manager {
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.update_title {
execute!(std::io::stderr(), SetTitle(self.title())).ok();
}
self.active_mut().apply_files_attrs();

View file

@ -4,7 +4,7 @@ use anyhow::Result;
use crossterm::{cursor::{RestorePosition, SavePosition}, event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, SetTitle}};
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);
@ -73,9 +73,12 @@ impl Term {
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
}
if MANAGER.update_title {
execute!(stderr(), SetTitle("")).ok();
}
execute!(
stderr(),
SetTitle(""),
mouse::SetMouse(false),
DisableBracketedPaste,
LeaveAlternateScreen,