mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 22:01:47 +03:00
term: restore original resize behavior on Windows
This reverts to the original resize behavior of padding out the display when resizing taller, but only for Windows systems. More explanation in the comments in the code. refs: #138
This commit is contained in:
parent
b239801085
commit
9614e117e0
@ -40,4 +40,32 @@ pub trait TerminalConfiguration: std::fmt::Debug {
|
|||||||
/// color palette for a terminal instance at runtime, but this method
|
/// color palette for a terminal instance at runtime, but this method
|
||||||
/// defines the initial palette.
|
/// defines the initial palette.
|
||||||
fn color_palette(&self) -> ColorPalette;
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,12 +195,34 @@ impl Screen {
|
|||||||
self.lines.push_back(Line::with_width(physical_cols));
|
self.lines.push_back(Line::with_width(physical_cols));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let new_cursor_y;
|
||||||
|
|
||||||
|
if self.config.resize_preserves_scrollback() {
|
||||||
|
new_cursor_y = cursor
|
||||||
|
.y
|
||||||
|
.saturating_add(cursor_y as i64)
|
||||||
|
.saturating_sub(cursor_phys as i64)
|
||||||
|
.max(0);
|
||||||
|
|
||||||
|
// We need to ensure that the bottom of the screen has sufficient lines;
|
||||||
|
// we use simple subtraction of physical_rows from the bottom of the lines
|
||||||
|
// array to define the visible region. Our resize operation may have
|
||||||
|
// temporarily violated that, which can result in the cursor unintentionally
|
||||||
|
// moving up into the scrollback and damaging the output
|
||||||
|
let required_num_rows_after_cursor =
|
||||||
|
physical_rows.saturating_sub(new_cursor_y as usize);
|
||||||
|
let actual_num_rows_after_cursor = self.lines.len().saturating_sub(cursor_y);
|
||||||
|
for _ in actual_num_rows_after_cursor..required_num_rows_after_cursor {
|
||||||
|
self.lines.push_back(Line::with_width(physical_cols));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// Compute the new cursor location; this is logically the inverse
|
// Compute the new cursor location; this is logically the inverse
|
||||||
// of the phys_row() function, but given the revised cursor_y
|
// of the phys_row() function, but given the revised cursor_y
|
||||||
// (the rewrap adjusted physical row of the cursor). This
|
// (the rewrap adjusted physical row of the cursor). This
|
||||||
// computes its new VisibleRowIndex given the new viewport size.
|
// computes its new VisibleRowIndex given the new viewport size.
|
||||||
let new_cursor_y = cursor_y as VisibleRowIndex
|
new_cursor_y = cursor_y as VisibleRowIndex
|
||||||
- (self.lines.len() as VisibleRowIndex - physical_rows as VisibleRowIndex);
|
- (self.lines.len() as VisibleRowIndex - physical_rows as VisibleRowIndex);
|
||||||
|
}
|
||||||
|
|
||||||
self.physical_rows = physical_rows;
|
self.physical_rows = physical_rows;
|
||||||
self.physical_cols = physical_cols;
|
self.physical_cols = physical_cols;
|
||||||
|
Loading…
Reference in New Issue
Block a user