Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 73 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ image.workspace = true
[target.'cfg(not(windows))'.dependencies]
color_quant = "1.1.0"
base64 = "0.22.1"
libc = "0.2.177"
rustix = { version = "1.1.2", features = ["termios", "event"] }
16 changes: 3 additions & 13 deletions image/src/iterm.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
use crate::get_dimensions;
use anyhow::Result;
use base64::{engine, Engine};
use image::{imageops::FilterType, DynamicImage};
use rustix::termios::tcgetwinsize;
use std::env;
use std::io::Cursor;

pub struct ITermBackend {}
pub struct ITermBackend;

impl ITermBackend {
pub fn new() -> Self {
ITermBackend {}
}

pub fn supported() -> bool {
let term_program = env::var("TERM_PROGRAM").unwrap_or_else(|_| "".to_string());
term_program == "iTerm.app"
}
}

impl Default for ITermBackend {
fn default() -> Self {
Self::new()
}
}

impl super::ImageBackend for ITermBackend {
fn add_image(
&self,
lines: Vec<String>,
image: &DynamicImage,
_colors: usize,
) -> Result<String> {
let tty_size = unsafe { get_dimensions() };
let tty_size = tcgetwinsize(std::io::stdin())?;
let width_ratio = f64::from(tty_size.ws_col) / f64::from(tty_size.ws_xpixel);
let height_ratio = f64::from(tty_size.ws_row) / f64::from(tty_size.ws_ypixel);

Expand Down
Loading