simplify passing the TerminalSize to the terminal

Following on from 8649056ac0,
this commit should make it harder to make a similar mistake
in the future, by introducing a new TerminalSize struct for
that purpose.
This commit is contained in:
Wez Furlong committed 2020-12-29 09:06:26 -08:00
1 parent ba62f4fed0
commit 80411d7db9
6 files changed
+30 -40

No files matched your search

+2 -8
View File
@@ -139,10 +139,7 @@ impl Domain for LocalDomain {
let writer = pair.master.try_clone_writer()?;
let terminal = wezterm_term::Terminal::new(
size.rows as usize,
size.cols as usize,
size.pixel_width as usize,
size.pixel_height as usize,
crate::pty_size_to_terminal_size(size),
std::sync::Arc::new(config::TermConfig {}),
"WezTerm",
config::wezterm_version(),
@@ -221,10 +218,7 @@ impl Domain for LocalDomain {
let writer = pair.master.try_clone_writer()?;
let terminal = wezterm_term::Terminal::new(
split_size.second.rows as usize,
split_size.second.cols as usize,
split_size.second.pixel_width as usize,
split_size.second.pixel_height as usize,
crate::pty_size_to_terminal_size(split_size.second),
std::sync::Arc::new(config::TermConfig {}),
"WezTerm",
config::wezterm_version(),
+9
View File
@@ -549,3 +549,12 @@ pub enum SessionTerminated {
#[error("Window Closed")]
WindowClosed,
}
pub(crate) fn pty_size_to_terminal_size(size: portable_pty::PtySize) -> wezterm_term::TerminalSize {
wezterm_term::TerminalSize {
physical_rows: size.rows as usize,
physical_cols: size.cols as usize,
pixel_width: size.pixel_width as usize,
pixel_height: size.pixel_height as usize,
}
}
+1 -4
View File
@@ -256,10 +256,7 @@ impl Domain for RemoteSshDomain {
let writer = pair.master.try_clone_writer()?;
let terminal = wezterm_term::Terminal::new(
size.rows as usize,
size.cols as usize,
size.pixel_width as usize,
size.pixel_height as usize,
crate::pty_size_to_terminal_size(size),
std::sync::Arc::new(config::TermConfig {}),
"WezTerm",
config::wezterm_version(),
+1 -4
View File
@@ -110,10 +110,7 @@ impl TermWizTerminalPane {
let pane_id = alloc_pane_id();
let terminal = RefCell::new(wezterm_term::Terminal::new(
size.rows as usize,
size.cols as usize,
size.pixel_width as usize,
size.pixel_height as usize,
crate::pty_size_to_terminal_size(size),
std::sync::Arc::new(config::TermConfig {}),
"WezTerm",
config::wezterm_version(),
+10 -14
View File
@@ -43,6 +43,14 @@ impl DerefMut for Terminal {
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct TerminalSize {
pub physical_rows: usize,
pub physical_cols: usize,
pub pixel_width: usize,
pub pixel_height: usize,
}
impl Terminal {
/// Construct a new Terminal.
/// `physical_rows` and `physical_cols` describe the dimensions
@@ -61,10 +69,7 @@ impl Terminal {
/// and mouse input is encoded and written to that stream, as
/// are answerback responses to a number of escape sequences.
pub fn new(
physical_rows: usize,
physical_cols: usize,
pixel_width: usize,
pixel_height: usize,
size: TerminalSize,
config: Arc<dyn TerminalConfiguration>,
term_program: &str,
term_version: &str,
@@ -72,16 +77,7 @@ impl Terminal {
writer: Box<dyn std::io::Write>,
) -> Terminal {
Terminal {
state: TerminalState::new(
physical_rows,
physical_cols,
pixel_width,
pixel_height,
config,
term_program,
term_version,
writer,
),
state: TerminalState::new(size, config, term_program, term_version, writer),
parser: Parser::new(),
}
}
+7 -10
View File
@@ -334,16 +334,13 @@ impl TerminalState {
/// You generally want the `Terminal` struct rather than this one;
/// Terminal contains and dereferences to `TerminalState`.
pub fn new(
physical_rows: usize,
physical_cols: usize,
pixel_width: usize,
pixel_height: usize,
size: TerminalSize,
config: Arc<dyn TerminalConfiguration>,
term_program: &str,
term_version: &str,
writer: Box<dyn std::io::Write>,
) -> TerminalState {
let screen = ScreenOrAlt::new(physical_rows, physical_cols, &config);
let screen = ScreenOrAlt::new(size.physical_rows, size.physical_cols, &config);
let color_map = default_color_map();
@@ -352,8 +349,8 @@ impl TerminalState {
screen,
pen: CellAttributes::default(),
cursor: CursorPosition::default(),
top_and_bottom_margins: 0..physical_rows as VisibleRowIndex,
left_and_right_margins: 0..physical_cols,
top_and_bottom_margins: 0..size.physical_rows as VisibleRowIndex,
left_and_right_margins: 0..size.physical_cols,
left_and_right_margin_mode: false,
wrap_next: false,
// We default auto wrap to true even though the default for
@@ -377,12 +374,12 @@ impl TerminalState {
cursor_visible: true,
dec_line_drawing_mode: false,
current_mouse_button: MouseButton::None,
tabs: TabStop::new(physical_cols, 8),
tabs: TabStop::new(size.physical_cols, 8),
title: "wezterm".to_string(),
icon_title: None,
palette: None,
pixel_height,
pixel_width,
pixel_height: size.pixel_height,
pixel_width: size.pixel_width,
clipboard: None,
device_control_handler: None,
current_dir: None,