mirror of
https://github.com/mfontanini/presenterm.git
synced 2026-09-01 23:33:21 -06:00
feat!: enable sixel by default
This commit is contained in:
parent
74acf11855
commit
9b1f3086cf
2
.github/workflows/merge.yaml
vendored
2
.github/workflows/merge.yaml
vendored
@ -20,7 +20,7 @@ jobs:
|
||||
components: clippy
|
||||
|
||||
- name: Run cargo check
|
||||
run: cargo check --features sixel
|
||||
run: cargo check
|
||||
|
||||
- name: Run cargo test
|
||||
run: cargo test
|
||||
|
||||
@ -19,7 +19,7 @@ hex = "0.4"
|
||||
fastrand = "2.3"
|
||||
flate2 = "1.0"
|
||||
image = { version = "0.25", features = ["gif", "jpeg", "png"], default-features = false }
|
||||
icy_sixel = { version = "0.5", optional = true }
|
||||
icy_sixel = "0.5"
|
||||
merge-struct = "0.1.0"
|
||||
itertools = "0.14"
|
||||
once_cell = "1.19"
|
||||
@ -46,7 +46,6 @@ rstest = { version = "0.26", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
sixel = ["icy_sixel"]
|
||||
json-schema = ["dep:schemars"]
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@ -276,7 +276,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Use the sixel protocol. Note that this requires compiling presenterm using the --features sixel flag.",
|
||||
"description": "Use the sixel protocol.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"sixel"
|
||||
|
||||
@ -11,16 +11,6 @@ the terminals where at least one of these is supported are:
|
||||
* [ghostty](https://ghostty.org/)
|
||||
* [foot](https://codeberg.org/dnkl/foot)
|
||||
|
||||
Sixel support is experimental so it needs to be explicitly enabled via the `sixel` configuration flag:
|
||||
|
||||
```bash
|
||||
cargo build --release --features sixel
|
||||
```
|
||||
|
||||
> [!note]
|
||||
> This feature flag is only needed if your terminal emulator _only_ supports sixel. Many terminals support the kitty or
|
||||
> iterm2 protocols so using this flag is often not required to get images to render successfully.
|
||||
|
||||
---
|
||||
|
||||
Things you should know when using image tags in your presentation's markdown are:
|
||||
|
||||
@ -415,21 +415,16 @@ pub enum ImageProtocol {
|
||||
/// different hosts and therefore can only communicate via terminal escape codes.
|
||||
KittyRemote,
|
||||
|
||||
/// Use the sixel protocol. Note that this requires compiling presenterm using the --features
|
||||
/// sixel flag.
|
||||
/// Use the sixel protocol.
|
||||
Sixel,
|
||||
|
||||
/// The default image protocol to use when no other is specified.
|
||||
AsciiBlocks,
|
||||
}
|
||||
|
||||
pub struct SixelUnsupported;
|
||||
|
||||
impl TryFrom<&ImageProtocol> for GraphicsMode {
|
||||
type Error = SixelUnsupported;
|
||||
|
||||
fn try_from(protocol: &ImageProtocol) -> Result<Self, Self::Error> {
|
||||
let mode = match protocol {
|
||||
impl From<&ImageProtocol> for GraphicsMode {
|
||||
fn from(protocol: &ImageProtocol) -> Self {
|
||||
match protocol {
|
||||
ImageProtocol::Auto => {
|
||||
let emulator = TerminalEmulator::detect();
|
||||
emulator.preferred_protocol()
|
||||
@ -439,12 +434,8 @@ impl TryFrom<&ImageProtocol> for GraphicsMode {
|
||||
ImageProtocol::KittyLocal => GraphicsMode::Kitty { mode: KittyMode::Local },
|
||||
ImageProtocol::KittyRemote => GraphicsMode::Kitty { mode: KittyMode::Remote },
|
||||
ImageProtocol::AsciiBlocks => GraphicsMode::AsciiBlocks,
|
||||
#[cfg(feature = "sixel")]
|
||||
ImageProtocol::Sixel => GraphicsMode::Sixel,
|
||||
#[cfg(not(feature = "sixel"))]
|
||||
ImageProtocol::Sixel => return Err(SixelUnsupported),
|
||||
};
|
||||
Ok(mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -308,13 +308,7 @@ impl CoreComponents {
|
||||
if cli.export_pdf | cli.export_html {
|
||||
GraphicsMode::Raw
|
||||
} else {
|
||||
let protocol = cli.image_protocol.as_ref().unwrap_or(&config.defaults.image_protocol);
|
||||
match GraphicsMode::try_from(protocol) {
|
||||
Ok(mode) => mode,
|
||||
Err(_) => Cli::command()
|
||||
.error(ErrorKind::InvalidValue, "sixel support was not enabled during compilation")
|
||||
.exit(),
|
||||
}
|
||||
cli.image_protocol.as_ref().unwrap_or(&config.defaults.image_protocol).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,6 @@ impl TerminalEmulator {
|
||||
GraphicsMode::Iterm2Multipart,
|
||||
GraphicsMode::Kitty { mode: KittyMode::Local },
|
||||
GraphicsMode::Kitty { mode: KittyMode::Remote },
|
||||
#[cfg(feature = "sixel")]
|
||||
GraphicsMode::Sixel,
|
||||
GraphicsMode::AsciiBlocks,
|
||||
];
|
||||
@ -103,9 +102,7 @@ impl TerminalEmulator {
|
||||
(GraphicsMode::Iterm2Multipart, Self::Iterm2) => true,
|
||||
// All terminals support ascii protocol
|
||||
(GraphicsMode::AsciiBlocks, _) => true,
|
||||
#[cfg(feature = "sixel")]
|
||||
(GraphicsMode::Sixel, Self::Foot | Self::Yaft | Self::Mlterm) => true,
|
||||
#[cfg(feature = "sixel")]
|
||||
(GraphicsMode::Sixel, Self::St | Self::Xterm | Self::Unknown) => capabilities.sixel,
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@ -43,7 +43,6 @@ impl Image {
|
||||
TerminalImage::Kitty(image) => DynamicImage::from(image.as_rgba8()).into(),
|
||||
TerminalImage::Iterm(image) => DynamicImage::from(image.as_rgba8()).into(),
|
||||
TerminalImage::Raw(_) => unreachable!("raw is only used for exports"),
|
||||
#[cfg(feature = "sixel")]
|
||||
TerminalImage::Sixel(image) => DynamicImage::from(image.as_rgba8()).into(),
|
||||
};
|
||||
*ascii_image = Some(image.clone());
|
||||
|
||||
@ -12,7 +12,10 @@ use crate::{
|
||||
terminal::{
|
||||
GraphicsMode,
|
||||
emulator::TerminalEmulator,
|
||||
image::protocols::iterm::ItermMode,
|
||||
image::protocols::{
|
||||
iterm::ItermMode,
|
||||
sixel::{SixelImage, SixelPrinter},
|
||||
},
|
||||
printer::{TerminalError, TerminalIo},
|
||||
},
|
||||
};
|
||||
@ -58,8 +61,7 @@ pub(crate) enum TerminalImage {
|
||||
Iterm(ItermImage),
|
||||
Ascii(AsciiImage),
|
||||
Raw(RawImage),
|
||||
#[cfg(feature = "sixel")]
|
||||
Sixel(super::protocols::sixel::SixelImage),
|
||||
Sixel(SixelImage),
|
||||
}
|
||||
|
||||
impl fmt::Debug for TerminalImage {
|
||||
@ -69,7 +71,6 @@ impl fmt::Debug for TerminalImage {
|
||||
Self::Iterm(_) => f.debug_tuple("Iterm").finish(),
|
||||
Self::Ascii(_) => f.debug_tuple("Ascii").finish(),
|
||||
Self::Raw(_) => f.debug_tuple("Raw").finish(),
|
||||
#[cfg(feature = "sixel")]
|
||||
Self::Sixel(_) => f.debug_tuple("Sixel").finish(),
|
||||
}
|
||||
}
|
||||
@ -82,7 +83,6 @@ impl ImageProperties for TerminalImage {
|
||||
Self::Iterm(image) => image.dimensions(),
|
||||
Self::Ascii(image) => image.dimensions(),
|
||||
Self::Raw(image) => image.dimensions(),
|
||||
#[cfg(feature = "sixel")]
|
||||
Self::Sixel(image) => image.dimensions(),
|
||||
}
|
||||
}
|
||||
@ -94,8 +94,7 @@ pub enum ImagePrinter {
|
||||
Ascii(AsciiPrinter),
|
||||
Raw(RawPrinter),
|
||||
Null,
|
||||
#[cfg(feature = "sixel")]
|
||||
Sixel(super::protocols::sixel::SixelPrinter),
|
||||
Sixel(SixelPrinter),
|
||||
}
|
||||
|
||||
impl Default for ImagePrinter {
|
||||
@ -113,8 +112,7 @@ impl ImagePrinter {
|
||||
GraphicsMode::Iterm2Multipart => Self::Iterm(ItermPrinter::new(ItermMode::Multipart, capabilities.tmux)),
|
||||
GraphicsMode::AsciiBlocks => Self::Ascii(AsciiPrinter),
|
||||
GraphicsMode::Raw => Self::Raw(RawPrinter),
|
||||
#[cfg(feature = "sixel")]
|
||||
GraphicsMode::Sixel => Self::Sixel(super::protocols::sixel::SixelPrinter::new()?),
|
||||
GraphicsMode::Sixel => Self::Sixel(SixelPrinter::new()?),
|
||||
};
|
||||
Ok(printer)
|
||||
}
|
||||
@ -130,7 +128,6 @@ impl PrintImage for ImagePrinter {
|
||||
Self::Ascii(printer) => TerminalImage::Ascii(printer.register(spec)?),
|
||||
Self::Null => return Err(RegisterImageError::Unsupported),
|
||||
Self::Raw(printer) => TerminalImage::Raw(printer.register(spec)?),
|
||||
#[cfg(feature = "sixel")]
|
||||
Self::Sixel(printer) => TerminalImage::Sixel(printer.register(spec)?),
|
||||
};
|
||||
Ok(image)
|
||||
@ -146,7 +143,6 @@ impl PrintImage for ImagePrinter {
|
||||
(Self::Ascii(printer), TerminalImage::Ascii(image)) => printer.print(image, options, terminal),
|
||||
(Self::Null, _) => Ok(()),
|
||||
(Self::Raw(printer), TerminalImage::Raw(image)) => printer.print(image, options, terminal),
|
||||
#[cfg(feature = "sixel")]
|
||||
(Self::Sixel(printer), TerminalImage::Sixel(image)) => printer.print(image, options, terminal),
|
||||
_ => Err(PrintImageError::Unsupported),
|
||||
}
|
||||
@ -173,7 +169,6 @@ impl fmt::Debug for ImageRegistry {
|
||||
ImagePrinter::Ascii(_) => "Ascii",
|
||||
ImagePrinter::Null => "Null",
|
||||
ImagePrinter::Raw(_) => "Raw",
|
||||
#[cfg(feature = "sixel")]
|
||||
ImagePrinter::Sixel(_) => "Sixel",
|
||||
};
|
||||
write!(f, "ImageRegistry<{inner}>")
|
||||
|
||||
@ -2,5 +2,4 @@ pub(crate) mod ascii;
|
||||
pub(crate) mod iterm;
|
||||
pub(crate) mod kitty;
|
||||
pub(crate) mod raw;
|
||||
#[cfg(feature = "sixel")]
|
||||
pub(crate) mod sixel;
|
||||
|
||||
@ -11,11 +11,8 @@ pub(crate) use printer::{Terminal, TerminalWrite, should_hide_cursor};
|
||||
pub enum GraphicsMode {
|
||||
Iterm2,
|
||||
Iterm2Multipart,
|
||||
Kitty {
|
||||
mode: image::protocols::kitty::KittyMode,
|
||||
},
|
||||
Kitty { mode: image::protocols::kitty::KittyMode },
|
||||
AsciiBlocks,
|
||||
Raw,
|
||||
#[cfg(feature = "sixel")]
|
||||
Sixel,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user