adaptor/src/kitty.rs: optimize code readability

This commit is contained in:
Integral 2023-09-23 12:07:19 +08:00
parent 0d5c0eee8e
commit e75a6723df

View file

@ -1,4 +1,7 @@
use std::{io::{stdout, Write}, path::Path}; use std::{
io::{stdout, Write},
path::Path,
};
use anyhow::Result; use anyhow::Result;
use base64::{engine::general_purpose, Engine}; use base64::{engine::general_purpose, Engine};
@ -29,7 +32,7 @@ impl Kitty {
} }
async fn encode(img: DynamicImage) -> Result<Vec<u8>> { async fn encode(img: DynamicImage) -> Result<Vec<u8>> {
fn output(raw: &[u8], format: u8, size: (u32, u32)) -> Result<Vec<u8>> { fn output(raw: &[u8], format: u8, (width, height): (u32, u32)) -> Result<Vec<u8>> {
let b64 = general_purpose::STANDARD.encode(raw).chars().collect::<Vec<_>>(); let b64 = general_purpose::STANDARD.encode(raw).chars().collect::<Vec<_>>();
let mut it = b64.chunks(4096).peekable(); let mut it = b64.chunks(4096).peekable();
@ -40,8 +43,8 @@ impl Kitty {
"{}_Ga=T,f={},s={},v={},m={};{}{}\\{}", "{}_Ga=T,f={},s={},v={},m={};{}{}\\{}",
START, START,
format, format,
size.0, width,
size.1, height,
it.peek().is_some() as u8, it.peek().is_some() as u8,
first.iter().collect::<String>(), first.iter().collect::<String>(),
ESCAPE, ESCAPE,