adaptor/src/iterm2.rs: optimize code readability

This commit is contained in:
Integral 2023-09-23 12:00:29 +08:00
parent df0cb36d41
commit 0d5c0eee8e

View file

@ -1,4 +1,7 @@
use std::{io::{stdout, BufWriter, Write}, path::Path}; use std::{
io::{stdout, BufWriter, Write},
path::Path,
};
use anyhow::Result; use anyhow::Result;
use base64::{engine::general_purpose, Engine}; use base64::{engine::general_purpose, Engine};
@ -33,8 +36,6 @@ impl Iterm2 {
async fn encode(img: DynamicImage) -> Result<Vec<u8>> { async fn encode(img: DynamicImage) -> Result<Vec<u8>> {
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let size = (img.width(), img.height());
let mut jpg = vec![]; let mut jpg = vec![];
JpegEncoder::new_with_quality(&mut jpg, 75).encode_image(&img)?; JpegEncoder::new_with_quality(&mut jpg, 75).encode_image(&img)?;
@ -44,8 +45,8 @@ impl Iterm2 {
"{}]1337;File=inline=1;size={};width={}px;height={}px;doNotMoveCursor=1:{}\x07{}", "{}]1337;File=inline=1;size={};width={}px;height={}px;doNotMoveCursor=1:{}\x07{}",
START, START,
jpg.len(), jpg.len(),
size.0, img.width(),
size.1, img.height(),
general_purpose::STANDARD.encode(&jpg), general_purpose::STANDARD.encode(&jpg),
CLOSE CLOSE
)?; )?;