feat(display): implement header with username@hostname

Swadhin Biswas committed 7 months ago
4a32f46
1 parent 303b9bd
commit 4a32f46
1 file changed
+50 -0
Showing 1 changed file+50-0
▼src/display/mod.rs
+50-0
48
48
fn resolve_image_path(&self) -> Option<String> {
49
49
// Priority: custom_image > image_source path > None
50
50
if let Some(ref path) = self.config.custom_image {
51
+ if std::path::Path::new(path).exists() {
52
+ return Some(path.clone());
53
+ } else {
54
+ eprintln!("Warning: custom_image '{}' not found", path);
55
+ }
56
+ }
57
+ let src = &self.config.image_source;
58
+ if src != "auto" && src != "ascii" && src != "wallpaper" {
59
+ // Treat as a file path
60
+ if std::path::Path::new(src).exists() {
61
+ return Some(src.clone());
62
+ }
63
+ }
64
+ None
65
+ }
66
+
67
+ /// Render with an image on the left side.
68
+ fn render_with_image(&self, sys_info: &SystemInfo, backend: &Backend, image_path: &str) {
69
+ // Build color scheme for info text
70
+ let distro_id = if self.config.ascii_distro == "auto" {
71
+ &sys_info.distro_id
72
+ } else {
73
+ &self.config.ascii_distro
74
+ };
75
+ let scheme = self.build_color_scheme(distro_id);
76
+ let info_lines = self.build_info_lines(sys_info, &scheme);
77
+
78
+ // Determine size for the image
79
+ let max_cols = self.parse_image_size_cols().unwrap_or(35);
80
+ let max_rows = info_lines.len().max(20);
81
+
82
+ match backend {
83
+ Backend::Kitty => {
84
+ // Kitty: render image directly via escape codes, then print info beside it
85
+ match image_backend::display_kitty(image_path, max_cols, max_rows) {
86
+ Ok((img_cols, img_rows)) => {
87
+ let gap = self.config.gap;
88
+ let reset = if self.config.no_color { "" } else { RESET };
89
+ let total = img_rows.max(info_lines.len());
90
+ let term_w = terminal_width();
91
+ let right_avail = term_w.saturating_sub(img_cols + gap);
92
+
93
+ // Move cursor up by img_rows to start printing info beside image
94
+ print!("\x1b[{}A", img_rows);
95
+
96
+ for i in 0..total {
97
+ // Move to the right of the image
98
+ print!("\x1b[{}C", img_cols + gap);
99
+ if i < info_lines.len() {
100
+ let truncated = if right_avail > 0 {
51
101