feat(config): add terminal image mode setting
This commit is contained in:
1 parent
b5d98e5e8a
commit
b372571648
3 files changed
+35
-1
No files matched your search
@@ -14,6 +14,8 @@ memory_min = "512M"
|
||||
memory_max = "2G"
|
||||
|
||||
[ui]
|
||||
# image protocol for content icons and screenshots: halfblocks, quadrants, kitty, or iterm2
|
||||
image_protocol = "kitty"
|
||||
# error popup timing (in ms)
|
||||
error_auto_dismiss_ms = 5000
|
||||
error_slide_start_ms = 3500
|
||||
|
||||
@@ -5,6 +5,16 @@ use std::path::PathBuf;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Default, Clone, Copy, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ImageProtocol {
|
||||
Halfblocks,
|
||||
Quadrants,
|
||||
#[default]
|
||||
Kitty,
|
||||
Iterm2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct General {}
|
||||
|
||||
@@ -102,6 +112,8 @@ impl Default for Defaults {
|
||||
// timing knobs for the error toast animation: show for 5s, start sliding at 3.5s,
|
||||
// fly off screen over 300ms. tweak these if the toasts feel too fast or slow.
|
||||
pub struct Ui {
|
||||
#[serde(default)]
|
||||
pub image_protocol: ImageProtocol,
|
||||
#[serde(default = "default_error_auto_dismiss_ms")]
|
||||
pub error_auto_dismiss_ms: u64,
|
||||
#[serde(default = "default_error_slide_start_ms")]
|
||||
@@ -128,6 +140,7 @@ fn default_max_error_events() -> usize {
|
||||
impl Default for Ui {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
image_protocol: ImageProtocol::default(),
|
||||
error_auto_dismiss_ms: default_error_auto_dismiss_ms(),
|
||||
error_slide_start_ms: default_error_slide_start_ms(),
|
||||
error_fly_out_ms: default_error_fly_out_ms(),
|
||||
|
||||
+20
-1
@@ -37,8 +37,27 @@ pub async fn show() -> color_eyre::Result<()> {
|
||||
|
||||
// figure out the terminal's font cell size for rendering images.
|
||||
// falls back to halfblock characters if the terminal doesn't respond
|
||||
let picker = ratatui_image::picker::Picker::from_query_stdio()
|
||||
let mut picker = ratatui_image::picker::Picker::from_query_stdio()
|
||||
.unwrap_or_else(|_| ratatui_image::picker::Picker::halfblocks());
|
||||
let detected_protocol = picker.protocol_type();
|
||||
let requested_protocol = match crate::config::SETTINGS.ui.image_protocol {
|
||||
crate::config::settings::ImageProtocol::Halfblocks
|
||||
| crate::config::settings::ImageProtocol::Quadrants => {
|
||||
ratatui_image::picker::ProtocolType::Halfblocks
|
||||
}
|
||||
crate::config::settings::ImageProtocol::Kitty
|
||||
if detected_protocol == ratatui_image::picker::ProtocolType::Kitty =>
|
||||
{
|
||||
ratatui_image::picker::ProtocolType::Kitty
|
||||
}
|
||||
crate::config::settings::ImageProtocol::Iterm2
|
||||
if detected_protocol == ratatui_image::picker::ProtocolType::Iterm2 =>
|
||||
{
|
||||
ratatui_image::picker::ProtocolType::Iterm2
|
||||
}
|
||||
_ => ratatui_image::picker::ProtocolType::Halfblocks,
|
||||
};
|
||||
picker.set_protocol_type(requested_protocol);
|
||||
|
||||
let result = app::App::new(picker).run(&mut terminal).await;
|
||||
|
||||
|
||||
Reference in new issue
Block a user