Implement Kitty graphics protocol for background image rendering
- Added `kitty_gfx` module to handle loading, scaling, and displaying background images using the Kitty graphics protocol. - Integrated background image handling into the main application loop, allowing dynamic updates based on configuration. - Enhanced terminal rendering to support transparent backgrounds when a Kitty image is active. - Updated IPC server to manage client connections and messages, including handling background image settings. - Modified `PtyTerminal` to accept additional environment variables during shell spawning. - Improved rendering logic to support popup dialogs and terminal background color customization.
This commit is contained in:
@@ -3,6 +3,16 @@ use std::fs;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Default)]
|
||||
pub struct Config {
|
||||
/// Sökväg till bakgrundsbild (Kitty graphics protocol)
|
||||
#[serde(default)]
|
||||
pub background_image: Option<String>,
|
||||
/// Bakgrundsfärg för virtuella terminaler. Om None → genomskinlig (Color::Reset).
|
||||
/// Stödjer: "#RRGGBB", "N" (indexed 0-255), färgnamn.
|
||||
#[serde(default)]
|
||||
pub terminal_bg_color: Option<String>,
|
||||
/// Standard-shell för nya terminaler. Om None → $SHELL eller /bin/bash.
|
||||
#[serde(default)]
|
||||
pub default_shell: Option<String>,
|
||||
#[serde(default, rename = "panel")]
|
||||
pub panels: Vec<PanelConfig>,
|
||||
#[serde(default, rename = "keybind")]
|
||||
@@ -134,6 +144,24 @@ fn default_keybinds() -> Vec<KeybindConfig> {
|
||||
]
|
||||
}
|
||||
|
||||
fn default_panels() -> Vec<PanelConfig> {
|
||||
vec![PanelConfig {
|
||||
position: PanelPosition::Top,
|
||||
items: vec![
|
||||
MenuItem {
|
||||
label: "Terminal".to_string(),
|
||||
action: MenuAction::SpawnTerminal { shell: Some("/bin/bash".to_string()) },
|
||||
},
|
||||
MenuItem {
|
||||
label: "Avsluta".to_string(),
|
||||
action: MenuAction::Exit,
|
||||
},
|
||||
],
|
||||
status_widgets: vec![],
|
||||
file: None,
|
||||
}]
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load(path: &str) -> anyhow::Result<Config> {
|
||||
let content = fs::read_to_string(path)?;
|
||||
@@ -157,12 +185,31 @@ impl Config {
|
||||
Err(e) => {
|
||||
eprintln!("Varning: kunde inte ladda {}: {}", path, e);
|
||||
Config {
|
||||
background_image: None,
|
||||
terminal_bg_color: None,
|
||||
default_shell: None,
|
||||
panels: default_panels(),
|
||||
keybinds: default_keybinds(),
|
||||
..Config::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Uppdatera background_image i config-filen (TOML)
|
||||
pub fn save_background(path: &str, image_path: Option<&str>) -> anyhow::Result<()> {
|
||||
let content = fs::read_to_string(path).unwrap_or_default();
|
||||
let mut doc: toml_edit::DocumentMut = content.parse().unwrap_or_default();
|
||||
match image_path {
|
||||
Some(p) => {
|
||||
doc["background_image"] = toml_edit::value(p);
|
||||
}
|
||||
None => {
|
||||
doc.remove("background_image");
|
||||
}
|
||||
}
|
||||
fs::write(path, doc.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user