feat(cache): add terminal capability detection and wallpaper functions
Swadhin Biswas committed 7 months ago
1ea69a9
1 parent c6471f0
commit 1ea69a9
1 file changed
+63 -0
Showing 1 changed file+63-0
▼src/image_cache.rs
+63-0
| @@ -248,3 +248,66 @@ pub fn detect_terminal_capabilities() -> TerminalCapabilities { | ||
248 | 248 | backend: "kitty".to_string(), |
249 | 249 | }; |
250 | 250 | } |
251 | + | |
252 | + // Check for iTerm2 | |
253 | + if std::env::var("ITERM_SESSION_ID").is_ok() { | |
254 | + return TerminalCapabilities { | |
255 | + supports_graphics: true, | |
256 | + backend: "iterm2".to_string(), | |
257 | + }; | |
258 | + } | |
259 | + | |
260 | + // Check for sixel support | |
261 | + if term.contains("xterm-kitty") || colorterm.contains("truecolor") { | |
262 | + if check_sixel_support() { | |
263 | + return TerminalCapabilities { | |
264 | + supports_graphics: true, | |
265 | + backend: "sixel".to_string(), | |
266 | + }; | |
267 | + } | |
268 | + } | |
269 | + | |
270 | + // Check for w3m (X11) | |
271 | + if std::env::var("DISPLAY").is_ok() { | |
272 | + return TerminalCapabilities { | |
273 | + supports_graphics: true, | |
274 | + backend: "w3m".to_string(), | |
275 | + }; | |
276 | + } | |
277 | + | |
278 | + // Fallback: no graphics support, use ASCII | |
279 | + TerminalCapabilities { | |
280 | + supports_graphics: false, | |
281 | + backend: "ascii".to_string(), | |
282 | + } | |
283 | +} | |
284 | + | |
285 | +pub struct TerminalCapabilities { | |
286 | + #[allow(dead_code)] | |
287 | + pub supports_graphics: bool, | |
288 | + pub backend: String, | |
289 | +} | |
290 | + | |
291 | +/// Check if terminal supports sixel (heuristic) | |
292 | +fn check_sixel_support() -> bool { | |
293 | + std::env::var("TERM") | |
294 | + .map(|t| t.contains("256color") || t.contains("truecolor")) | |
295 | + .unwrap_or(false) | |
296 | +} | |
297 | + | |
298 | +#[cfg(test)] | |
299 | +mod tests { | |
300 | + use super::*; | |
301 | + | |
302 | + #[test] | |
303 | + fn test_cache_dir_exists() { | |
304 | + let dir = cache_dir(); | |
305 | + assert!(dir.to_string_lossy().contains("cache")); | |
306 | + } | |
307 | + | |
308 | + #[test] | |
309 | + fn test_should_download_returns_bool() { | |
310 | + let result = should_download(); | |
311 | + assert!(result || !result); // Just verify it returns a bool | |
312 | + } | |
313 | +} | |
251 | 314 | |