Skip to content

Commit 37e6fa3

Browse files
authored
Merge pull request #270 from yoichi/fix-layout-with-sixel
Fix layout with sixel image backend
2 parents 2ee7b54 + ce36353 commit 37e6fa3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/onefetch/image_backends/sixel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ impl super::ImageBackend for SixelBackend {
7777
ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size);
7878
tty_size
7979
};
80-
let width_ratio = tty_size.ws_col as f64 / tty_size.ws_xpixel as f64;
81-
let height_ratio = tty_size.ws_row as f64 / tty_size.ws_ypixel as f64;
80+
let cw = tty_size.ws_xpixel / tty_size.ws_col;
81+
let lh = tty_size.ws_ypixel / tty_size.ws_row;
82+
let width_ratio = 1.0 / cw as f64;
83+
let height_ratio = 1.0 / lh as f64;
8284

8385
// resize image to fit the text height with the Lanczos3 algorithm
8486
let image = image.resize(
@@ -152,7 +154,7 @@ impl super::ImageBackend for SixelBackend {
152154
}
153155
image_data.extend(b"\x1B\\");
154156

155-
image_data.extend(format!("\x1B[{}A", image_rows as u32 + 2).as_bytes()); // move cursor to top-left corner
157+
image_data.extend(format!("\x1B[{}A", image_rows as u32).as_bytes()); // move cursor to top-left corner
156158
image_data.extend(format!("\x1B[{}C", image_columns as u32 + 1).as_bytes()); // move cursor to top-right corner of image
157159
let mut i = 0;
158160
for line in &lines {

0 commit comments

Comments
 (0)