1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-28 01:06:37 +03:00

term: correct cursor position after imgcat

I've had a FIXME in here for a while to check the positioning,
but never got around to it.

The onefetch folks have an app that does care about this,
so it's time to resolve it!

This commit adjusts the cursor position for the iterm case
(not the sixel case), and results in both:

running in xterm:

```
onefetch --image ~/Downloads/squirrel.png
```

running in wezterm:

```
TERM_PROGRAM=iTerm.app onefetch --image ~/Downloads/squirrel.png --image-backend=iterm
```

```
onefetch --image ~/Downloads/squirrel.png --image-backend=sixel
```

showing consistent positioning.

refs: https://github.com/wez/wezterm/issues/317
refs: https://github.com/o2sh/onefetch/pull/305
This commit is contained in:
Wez Furlong 2020-11-02 17:59:29 -08:00
parent 500bf1b376
commit 7fb22d6968

View File

@ -1330,7 +1330,7 @@ impl TerminalState {
}
let image_data = self.raw_image_to_image_data(png_image_data);
self.assign_image_to_cells(width, height, image_data);
self.assign_image_to_cells(width, height, image_data, false);
}
/// cache recent images and avoid assigning a new id for repeated data!
@ -1349,7 +1349,13 @@ impl TerminalState {
}
}
fn assign_image_to_cells(&mut self, width: u32, height: u32, image_data: Arc<ImageData>) {
fn assign_image_to_cells(
&mut self,
width: u32,
height: u32,
image_data: Arc<ImageData>,
iterm_cursor_position: bool,
) {
let physical_cols = self.screen().physical_cols;
let physical_rows = self.screen().physical_rows;
let cell_pixel_width = self.pixel_width / physical_cols;
@ -1400,6 +1406,15 @@ impl TerminalState {
ypos += y_delta;
self.new_line(false);
}
// Sixel places the cursor under the left corner of the image,
// but iTerm places it after the bottom right corner.
if iterm_cursor_position {
self.set_cursor_pos(
&Position::Relative(width_in_cells as i64),
&Position::Relative(-1),
);
}
}
fn set_image(&mut self, image: ITermFileData) {
@ -1455,15 +1470,7 @@ impl TerminalState {
};
let image_data = self.raw_image_to_image_data(image.data);
self.assign_image_to_cells(width as u32, height as u32, image_data);
// FIXME: check cursor positioning in iterm
/*
self.set_cursor_pos(
&Position::Relative(width_in_cells as i64),
&Position::Relative(-(height_in_cells as i64)),
);
*/
self.assign_image_to_cells(width as u32, height as u32, image_data, true);
}
fn perform_device(&mut self, dev: Device) {