mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
teach the terminalstate about pixel sizes
This allows more accurate slicing of images when processing iterm2 image sequences
This commit is contained in:
parent
d97a84f984
commit
12e71a594a
@ -51,9 +51,12 @@ impl Tab for LocalTab {
|
||||
|
||||
fn resize(&self, size: PtySize) -> Result<(), Error> {
|
||||
self.pty.borrow_mut().resize(size)?;
|
||||
self.terminal
|
||||
.borrow_mut()
|
||||
.resize(size.rows as usize, size.cols as usize);
|
||||
self.terminal.borrow_mut().resize(
|
||||
size.rows as usize,
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,8 @@ impl Domain for LocalDomain {
|
||||
let mut terminal = term::Terminal::new(
|
||||
size.rows as usize,
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
self.config.scrollback_lines.unwrap_or(3500),
|
||||
self.config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
@ -265,6 +265,8 @@ impl Domain for RemoteSshDomain {
|
||||
let mut terminal = term::Terminal::new(
|
||||
size.rows as usize,
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
self.config.scrollback_lines.unwrap_or(3500),
|
||||
self.config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
@ -70,6 +70,8 @@ impl Terminal {
|
||||
pub fn new(
|
||||
physical_rows: usize,
|
||||
physical_cols: usize,
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
scrollback_size: usize,
|
||||
hyperlink_rules: Vec<HyperlinkRule>,
|
||||
) -> Terminal {
|
||||
@ -77,6 +79,8 @@ impl Terminal {
|
||||
state: TerminalState::new(
|
||||
physical_rows,
|
||||
physical_cols,
|
||||
pixel_height,
|
||||
pixel_width,
|
||||
scrollback_size,
|
||||
hyperlink_rules,
|
||||
),
|
||||
|
@ -209,6 +209,9 @@ pub struct TerminalState {
|
||||
/// The terminal title string
|
||||
title: String,
|
||||
palette: ColorPalette,
|
||||
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
}
|
||||
|
||||
fn is_double_click_word(s: &str) -> bool {
|
||||
@ -229,6 +232,8 @@ impl TerminalState {
|
||||
pub fn new(
|
||||
physical_rows: usize,
|
||||
physical_cols: usize,
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
scrollback_size: usize,
|
||||
hyperlink_rules: Vec<HyperlinkRule>,
|
||||
) -> TerminalState {
|
||||
@ -259,6 +264,8 @@ impl TerminalState {
|
||||
hyperlink_rules,
|
||||
title: "wezterm".to_string(),
|
||||
palette: ColorPalette::default(),
|
||||
pixel_height,
|
||||
pixel_width,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1023,9 +1030,17 @@ impl TerminalState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, physical_rows: usize, physical_cols: usize) {
|
||||
pub fn resize(
|
||||
&mut self,
|
||||
physical_rows: usize,
|
||||
physical_cols: usize,
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
) {
|
||||
self.screen.resize(physical_rows, physical_cols);
|
||||
self.scroll_region = 0..physical_rows as i64;
|
||||
self.pixel_height = pixel_height;
|
||||
self.pixel_width = pixel_width;
|
||||
self.tabs.resize(physical_cols);
|
||||
self.set_scroll_viewport(0);
|
||||
// Ensure that the cursor is within the new bounds of the screen
|
||||
@ -1282,17 +1297,13 @@ impl TerminalState {
|
||||
};
|
||||
|
||||
// Figure out the dimensions.
|
||||
// TODO: we need to understand pixels here, and we don't today,
|
||||
// so "guess" using the values that I see in my setup.
|
||||
let cell_pixel_width = 8 * 2;
|
||||
let cell_pixel_height = 15 * 2;
|
||||
let physical_cols = self.screen().physical_cols;
|
||||
let physical_rows = self.screen().physical_rows;
|
||||
let cell_pixel_width = self.pixel_width / physical_cols;
|
||||
let cell_pixel_height = self.pixel_height / physical_rows;
|
||||
|
||||
let width = image
|
||||
.width
|
||||
.to_pixels(cell_pixel_width, self.screen().physical_cols);
|
||||
let height = image
|
||||
.height
|
||||
.to_pixels(cell_pixel_height, self.screen().physical_rows);
|
||||
let width = image.width.to_pixels(cell_pixel_width, physical_cols);
|
||||
let height = image.height.to_pixels(cell_pixel_height, physical_rows);
|
||||
|
||||
// Compute any Automatic dimensions
|
||||
let (width, height) = match (width, height) {
|
||||
@ -1316,13 +1327,11 @@ impl TerminalState {
|
||||
let width_in_cells = width / cell_pixel_width;
|
||||
let height_in_cells = height / cell_pixel_height;
|
||||
|
||||
// TODO: defer this to the actual renderer
|
||||
/*
|
||||
let available_pixel_width = width_in_cells * cell_pixel_width;
|
||||
let available_pixel_height = height_in_cells * cell_pixel_height;
|
||||
*/
|
||||
|
||||
// TODO: defer this to the actual renderer
|
||||
/*
|
||||
let resized_image = if image.preserve_aspect_ratio {
|
||||
let resized = decoded_image.resize(
|
||||
available_pixel_width as u32,
|
||||
@ -1347,8 +1356,8 @@ impl TerminalState {
|
||||
|
||||
let mut ypos = NotNan::new(0.0).unwrap();
|
||||
let cursor_x = self.cursor.x;
|
||||
let x_delta = 1.0 / width_in_cells as f32;
|
||||
let y_delta = 1.0 / height_in_cells as f32;
|
||||
let x_delta = 1.0 / (width as f32 / (self.pixel_width as f32 / physical_cols as f32));
|
||||
let y_delta = 1.0 / (height as f32 / (self.pixel_height as f32 / physical_rows as f32));
|
||||
debug!(
|
||||
"image is {}x{} cells, {}x{} pixels",
|
||||
width_in_cells, height_in_cells, width, height
|
||||
|
Loading…
Reference in New Issue
Block a user