diff --git a/mux/src/domain.rs b/mux/src/domain.rs index b24231b8a..ea9f2ab69 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -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(), diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 8d9dcd50c..38dac1229 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -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, + } +} diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index 55b134653..757ebe040 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -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(), diff --git a/mux/src/termwiztermtab.rs b/mux/src/termwiztermtab.rs index ff9ad244e..c7cedad91 100644 --- a/mux/src/termwiztermtab.rs +++ b/mux/src/termwiztermtab.rs @@ -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(), diff --git a/term/src/terminal.rs b/term/src/terminal.rs index 1dcc902b6..64bac5be0 100644 --- a/term/src/terminal.rs +++ b/term/src/terminal.rs @@ -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, term_program: &str, term_version: &str, @@ -72,16 +77,7 @@ impl Terminal { writer: Box, ) -> 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(), } } diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 785b8fcec..e8848580f 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -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, term_program: &str, term_version: &str, writer: Box, ) -> 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,