1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 03:09:06 +03:00

term: scope the conpty resize quirks better to conpty on windows

Previously, we'd just default the resize quirk on for all programs on
Windows.

That pessimizes the otherwise fine behavior of `wezterm ssh` or mux
connections to unixy platforms.

This commit moves the quirk out of the config trait and makes it
a runtime property of the terminal, and then arranges for it
to be set when we know that we set up a conpty for the terminal.

refs: #1265
This commit is contained in:
Wez Furlong 2022-03-30 08:06:45 -07:00
parent 808d7df8d4
commit 53c47143fd
4 changed files with 37 additions and 37 deletions

View File

@ -284,7 +284,7 @@ impl Domain for LocalDomain {
Box::new(writer),
);
if self.is_conpty() {
terminal.set_supress_initial_title_change();
terminal.enable_conpty_quirks();
}
let pane: Rc<dyn Pane> = Rc::new(LocalPane::new(

View File

@ -158,34 +158,6 @@ pub trait TerminalConfiguration: std::fmt::Debug {
/// defines the initial palette.
fn color_palette(&self) -> ColorPalette;
/// Return true if a resize operation should consider rows that have
/// made it to scrollback as being immutable.
/// When immutable, the resize operation will pad out the screen height
/// with additional blank rows and due to implementation details means
/// that the user will need to scroll back the scrollbar post-resize
/// than they would otherwise.
///
/// When mutable, resizing the window taller won't add extra rows;
/// instead the resize will tend to have "bottom gravity" meaning that
/// making the window taller will reveal more history than in the other
/// mode.
///
/// mutable is generally speaking a nicer experience.
///
/// On Windows, the PTY layer doesn't play well with a mutable scrollback,
/// frequently moving the cursor up to high and erasing portions of the
/// screen.
///
/// This behavior only happens with the windows pty layer; it doesn't
/// manifest when using eg: ssh directly to a remote unix system.
///
/// Ideally we'd have this return `true` only for the native windows
/// pty layer, but for the sake of simplicity, we make this conditional
/// on being a windows build.
fn resize_preserves_scrollback(&self) -> bool {
cfg!(windows)
}
fn canonicalize_pasted_newlines(&self) -> NewlineCanon {
NewlineCanon::default()
}

View File

@ -166,6 +166,7 @@ impl Screen {
physical_cols: usize,
cursor: CursorPosition,
seqno: SequenceNo,
is_conpty: bool,
) -> CursorPosition {
let physical_rows = physical_rows.max(1);
let physical_cols = physical_cols.max(1);
@ -227,7 +228,29 @@ impl Screen {
let new_cursor_y;
if self.config.resize_preserves_scrollback() {
// true if a resize operation should consider rows that have
// made it to scrollback as being immutable.
// When immutable, the resize operation will pad out the screen height
// with additional blank rows and due to implementation details means
// that the user will need to scroll back the scrollbar post-resize
// than they would otherwise.
//
// When mutable, resizing the window taller won't add extra rows;
// instead the resize will tend to have "bottom gravity" meaning that
// making the window taller will reveal more history than in the other
// mode.
//
// mutable is generally speaking a nicer experience.
//
// On Windows, the PTY layer doesn't play well with a mutable scrollback,
// frequently moving the cursor up to high and erasing portions of the
// screen.
//
// This behavior only happens with the windows pty layer; it doesn't
// manifest when using eg: ssh directly to a remote unix system.
let resize_preserves_scrollback = is_conpty;
if resize_preserves_scrollback {
new_cursor_y = cursor
.y
.saturating_add(cursor_y as i64)

View File

@ -201,13 +201,14 @@ impl ScreenOrAlt {
cursor_main: CursorPosition,
cursor_alt: CursorPosition,
seqno: SequenceNo,
is_conpty: bool,
) -> (CursorPosition, CursorPosition) {
let cursor_main = self
.screen
.resize(physical_rows, physical_cols, cursor_main, seqno);
let cursor_alt = self
.alt_screen
.resize(physical_rows, physical_cols, cursor_alt, seqno);
let cursor_main =
self.screen
.resize(physical_rows, physical_cols, cursor_main, seqno, is_conpty);
let cursor_alt =
self.alt_screen
.resize(physical_rows, physical_cols, cursor_alt, seqno, is_conpty);
(cursor_main, cursor_alt)
}
@ -368,6 +369,7 @@ pub struct TerminalState {
unicode_version: UnicodeVersion,
unicode_version_stack: Vec<UnicodeVersionStackEntry>,
enable_conpty_quirks: bool,
/// 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
@ -556,6 +558,7 @@ impl TerminalState {
unicode_version,
unicode_version_stack: vec![],
suppress_initial_title_change: false,
enable_conpty_quirks: false,
accumulating_title: None,
lost_focus_seqno: seqno,
focused: true,
@ -564,7 +567,8 @@ impl TerminalState {
}
}
pub fn set_supress_initial_title_change(&mut self) {
pub fn enable_conpty_quirks(&mut self) {
self.enable_conpty_quirks = true;
self.suppress_initial_title_change = true;
}
@ -819,6 +823,7 @@ impl TerminalState {
cursor_main,
cursor_alt,
self.seqno,
self.enable_conpty_quirks,
);
self.top_and_bottom_margins = 0..physical_rows as i64;
self.left_and_right_margins = 0..physical_cols;