From ef666c53e58fbd4afe053002b73309704623de49 Mon Sep 17 00:00:00 2001 From: neoarz Date: Wed, 7 Jan 2026 22:33:45 -0500 Subject: [PATCH] feat: add small caption --- src/output/colors.rs | 5 ----- src/output/image.rs | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/output/colors.rs b/src/output/colors.rs index d70ab77..8535448 100644 --- a/src/output/colors.rs +++ b/src/output/colors.rs @@ -1,16 +1,13 @@ use colored::Colorize; -// title pub fn title(user: &str, host: &str) -> String { format!("{}@{}", user.cyan().bold(), host.cyan().bold()) } -// separator pub fn separator(len: usize) -> String { "-".repeat(len) } -// percent (for colors based on usage level) pub fn percent(value: f64) -> String { let text = format!("{}%", value as u32); if value > 80.0 { @@ -34,12 +31,10 @@ pub fn battery_percent(value: u32) -> String { } } -// info pub fn info(key: &str, value: &str) -> String { format!("{}: {}", key.yellow().bold(), value) } -// color blocks pub fn color_blocks() -> String { let normal = " ".on_black().to_string() + &" ".on_red().to_string() diff --git a/src/output/image.rs b/src/output/image.rs index fe409c3..d099e81 100644 --- a/src/output/image.rs +++ b/src/output/image.rs @@ -139,7 +139,8 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) { let (char_w, char_h) = terminal_cell_metrics(); let cols = ((width as f32 / char_w).ceil() as usize).max(1) + DEFAULT_GAP_COLUMNS; let rows = ((height as f32 / char_h).ceil() as usize).max(1); - let padding_top = 0; + let padding_top = 0; + let caption_rows = 1; let total_rows = rows + padding_top; for _ in 0..total_rows { @@ -159,6 +160,15 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) { print!("{}", output); std::io::stdout().flush().ok(); + // just a silly caption lolol + let image_width_cols = cols - DEFAULT_GAP_COLUMNS; + + let text = "a creeper made this"; + let text_len = 16; + let pad = if image_width_cols > text_len { (image_width_cols - text_len) / 2 } else { 0 }; + print!("\x1b[{}B", rows); + print!("\r\x1b[{}C{}", pad, text); + print!("\x1b[u"); if padding_top > 0 { @@ -166,7 +176,7 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) { } std::io::stdout().flush().ok(); - (cols, total_rows) + (cols, total_rows + caption_rows) } // Prints text at a horizontal offset for side-by-side layout with image.