1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-17 17:57:28 +03:00

term: ignore first OSC title change sequence on Windows

ConPTY emits a sequence that sets the title to the name of the
program that is initially launched into it.

This commit tries to ignore that sequence in that circumstance,
so that the logic in b5d156c282
can more dynamically set the tab title.
This commit is contained in:
Wez Furlong 2021-12-25 00:58:25 -07:00
parent b5d156c282
commit a0cbea2703
6 changed files with 50 additions and 3 deletions

1
Cargo.lock generated
View File

@ -2945,6 +2945,7 @@ version = "0.7.0"
dependencies = [
"anyhow",
"bitflags",
"downcast-rs",
"filedescriptor",
"futures",
"lazy_static",

View File

@ -106,6 +106,18 @@ impl LocalDomain {
name: name.to_string(),
}
}
#[cfg(unix)]
fn is_conpty(&self) -> bool {
false
}
#[cfg(windows)]
fn is_conpty(&self) -> bool {
self.pty_system
.downcast_ref::<portable_pty::win::conpty::ConPtySystem>()
.is_some()
}
}
#[async_trait(?Send)]
@ -148,13 +160,16 @@ impl Domain for LocalDomain {
let writer = pair.master.try_clone_writer()?;
let mux = Mux::get().unwrap();
let terminal = wezterm_term::Terminal::new(
let mut terminal = wezterm_term::Terminal::new(
crate::pty_size_to_terminal_size(size),
std::sync::Arc::new(config::TermConfig::new()),
"WezTerm",
config::wezterm_version(),
Box::new(writer),
);
if self.is_conpty() {
terminal.set_supress_initial_title_change();
}
let pane: Rc<dyn Pane> = Rc::new(LocalPane::new(
pane_id,
@ -230,13 +245,16 @@ impl Domain for LocalDomain {
let writer = pair.master.try_clone_writer()?;
let terminal = wezterm_term::Terminal::new(
let mut terminal = wezterm_term::Terminal::new(
crate::pty_size_to_terminal_size(split_size.second),
std::sync::Arc::new(config::TermConfig::new()),
"WezTerm",
config::wezterm_version(),
Box::new(writer),
);
if self.is_conpty() {
terminal.set_supress_initial_title_change();
}
let pane: Rc<dyn Pane> = Rc::new(LocalPane::new(
pane_id,

View File

@ -10,6 +10,7 @@ documentation = "https://docs.rs/portable-pty"
[dependencies]
anyhow = "1.0"
downcast-rs = "1.0"
filedescriptor = { version="0.8", path = "../filedescriptor" }
log = "0.4"
libc = "0.2"

View File

@ -44,6 +44,7 @@
//! session with an implementation of `PtySystem`, allowing
//! you to use the same pty interface with remote ptys.
use anyhow::Error;
use downcast_rs::{impl_downcast, Downcast};
#[cfg(unix)]
use libc;
#[cfg(feature = "serde_support")]
@ -191,12 +192,13 @@ pub struct PtyPair {
/// The `PtySystem` trait allows an application to work with multiple
/// possible Pty implementations at runtime. This is important on
/// Windows systems which have a variety of implementations.
pub trait PtySystem {
pub trait PtySystem: Downcast {
/// Create a new Pty instance with the window size set to the specified
/// dimensions. Returns a (master, slave) Pty pair. The master side
/// is used to drive the slave side.
fn openpty(&self, size: PtySize) -> anyhow::Result<PtyPair>;
}
impl_downcast!(PtySystem);
impl Child for std::process::Child {
fn try_wait(&mut self) -> IoResult<Option<ExitStatus>> {

View File

@ -347,6 +347,12 @@ pub struct TerminalState {
/// The unicode version that is in effect
unicode_version: UnicodeVersion,
unicode_version_stack: Vec<UnicodeVersionStackEntry>,
/// On Windows, the ConPTY layer emits an OSC sequence to
/// set the title shortly after it starts up.
/// We don't want that, so we use this flag to remember
/// whether we want to skip it or not.
suppress_initial_title_change: bool,
}
#[derive(Debug)]
@ -484,9 +490,14 @@ impl TerminalState {
seqno: 0,
unicode_version,
unicode_version_stack: vec![],
suppress_initial_title_change: false,
}
}
pub fn set_supress_initial_title_change(&mut self) {
self.suppress_initial_title_change = true;
}
pub fn current_seqno(&self) -> SequenceNo {
self.seqno
}

View File

@ -178,6 +178,19 @@ impl<'a> Performer<'a> {
pub fn perform(&mut self, action: Action) {
debug!("perform {:?}", action);
if self.suppress_initial_title_change {
match &action {
Action::OperatingSystemCommand(osc) => match **osc {
OperatingSystemCommand::SetIconNameAndWindowTitle(_) => {
debug!("suppressed {:?}", osc);
self.suppress_initial_title_change = false;
return;
}
_ => {}
},
_ => {}
}
}
match action {
Action::Print(c) => self.print(c),
Action::Control(code) => self.control(code),
@ -516,6 +529,7 @@ impl<'a> Performer<'a> {
self.left_and_right_margins = 0..self.screen().physical_cols;
self.unicode_version = UnicodeVersion(self.config.unicode_version());
self.unicode_version_stack.clear();
self.suppress_initial_title_change = false;
self.screen.activate_primary_screen(seqno);
self.erase_in_display(EraseInDisplay::EraseScrollback);