Skip to content

Commit

Permalink
Merge pull request #557 from BaerLKR/main
Browse files Browse the repository at this point in the history
added sixel encoding
  • Loading branch information
kaikalii authored Sep 28, 2024
2 parents 8671b29 + 1c12d94 commit f0ae7cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ uiua-nokhwa = {version = "0.10.5", optional = true, features = ["input-native"]}
js-sys = {version = "0.3", optional = true}
wasm-bindgen = {version = "0.2.92", optional = true}
web-sys = {version = "0.3.60", optional = true}
icy_sixel = {version = "0.1.2", optional = true}

[features]
audio = ["hodaun", "lockfree", "audio_encode"]
Expand Down Expand Up @@ -143,7 +144,7 @@ opt = [] # Enables some optimizations but increases binary size
profile = ["serde_yaml"]
raw_mode = ["rawrrr", "native_sys"]
stand = ["native_sys"]
terminal_image = ["viuer", "image"]
terminal_image = ["viuer", "image", "icy_sixel"]
tls = ["httparse", "rustls", "webpki-roots", "rustls-pemfile"]
web = ["wasm-bindgen", "js-sys", "web-sys"]
webcam = ["image", "uiua-nokhwa"]
Expand Down
44 changes: 32 additions & 12 deletions src/sys_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,38 @@ impl SysBackend for NativeSys {
} else {
(None, None)
};
viuer::print(
&image,
&viuer::Config {
width,
height,
absolute_offset: false,
transparent: true,
..Default::default()
},
)
.map(drop)
.map_err(|e| format!("Failed to show image: {e}"))
if std::env::var("TERM")
.unwrap_or("".to_owned())
.contains("sixel")
{
let img_rgba8 = image.to_rgba8();
let sixel = icy_sixel::sixel_string(
image.to_rgba8().as_raw(),
img_rgba8.width() as i32,
img_rgba8.height() as i32,
icy_sixel::PixelFormat::RGBA8888,
icy_sixel::DiffusionMethod::Stucki,
icy_sixel::MethodForLargest::Auto,
icy_sixel::MethodForRep::Auto,
icy_sixel::Quality::HIGH,
);
let s = sixel.map_err(|e| e.to_string())?;
print!("{s}");
Ok(())
} else {
viuer::print(
&image,
&viuer::Config {
width,
height,
absolute_offset: false,
transparent: true,
..Default::default()
},
)
.map(drop)
.map_err(|e| format!("Failed to show image: {e}"))
}
}
#[cfg(all(feature = "gif", feature = "invoke"))]
fn show_gif(&self, gif_bytes: Vec<u8>, _: Option<&str>) -> Result<(), String> {
Expand Down

0 comments on commit f0ae7cc

Please sign in to comment.