use super::terminal_detect::TerminalType;
#[derive(Debug, Clone)]
pub struct HintsConfig {
pub enabled: bool,
pub shown_hints_file: Option<std::path::PathBuf>,
}
impl Default for HintsConfig {
fn default() -> Self {
Self {
enabled: true,
shown_hints_file: dirs::config_dir().map(|p| p.join("eazygit").join(".shown_hints")),
}
}
}
pub fn get_background_hint(terminal: TerminalType) -> Option<String> {
match terminal {
TerminalType::ITerm2 => Some(
"💡 Pro Tip: For smooth high-resolution backgrounds in iTerm2:\n\
1. Go to Preferences > Profiles > Window > Background Image\n\
2. Choose your image and set blending to 20-30%\n\
3. Disable 'background_image_path' in eazygit config\n\
\n\
This gives you full-resolution backgrounds instead of cell-based rendering."
.to_string()
),
TerminalType::Kitty => Some(
"💡 Pro Tip: For smooth high-resolution backgrounds in Kitty:\n\
1. Add to ~/.config/kitty/kitty.conf:\n\
background_image /path/to/your/image.jpg\n\
background_opacity 0.3\n\
2. Disable 'background_image_path' in eazygit config\n\
3. Restart Kitty\n\
\n\
This gives you full-resolution backgrounds instead of cell-based rendering."
.to_string()
),
TerminalType::Wezterm => Some(
"💡 Pro Tip: For smooth high-resolution backgrounds in WezTerm:\n\
1. Add to ~/.wezterm.lua:\n\
config.window_background_opacity = 0.9\n\
config.window_background_image = '/path/to/image.jpg'\n\
2. Disable 'background_image_path' in eazygit config\n\
\n\
This gives you full-resolution backgrounds instead of cell-based rendering."
.to_string()
),
TerminalType::Generic => None,
}
}
pub fn has_shown_hint(hint_id: &str, config: &HintsConfig) -> bool {
if !config.enabled {
return true; }
let Some(path) = &config.shown_hints_file else {
return false;
};
if !path.exists() {
return false;
}
std::fs::read_to_string(path)
.ok()
.map(|content| content.lines().any(|line| line == hint_id))
.unwrap_or(false)
}
pub fn mark_hint_shown(hint_id: &str, config: &HintsConfig) -> std::io::Result<()> {
if !config.enabled {
return Ok(());
}
let Some(path) = &config.shown_hints_file else {
return Ok(());
};
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
use std::io::Write;
let mut file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(path)?;
writeln!(file, "{}", hint_id)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_iterm2_hint_exists() {
let hint = get_background_hint(TerminalType::ITerm2);
assert!(hint.is_some());
assert!(hint.unwrap().contains("iTerm2"));
}
#[test]
fn test_generic_has_no_hint() {
let hint = get_background_hint(TerminalType::Generic);
assert!(hint.is_none());
}
}