feat: add small caption

This commit is contained in:
neoarz
2026-01-07 22:33:45 -05:00
parent ea96e73a33
commit ef666c53e5
2 changed files with 12 additions and 7 deletions

View File

@@ -1,16 +1,13 @@
use colored::Colorize; use colored::Colorize;
// title
pub fn title(user: &str, host: &str) -> String { pub fn title(user: &str, host: &str) -> String {
format!("{}@{}", user.cyan().bold(), host.cyan().bold()) format!("{}@{}", user.cyan().bold(), host.cyan().bold())
} }
// separator
pub fn separator(len: usize) -> String { pub fn separator(len: usize) -> String {
"-".repeat(len) "-".repeat(len)
} }
// percent (for colors based on usage level)
pub fn percent(value: f64) -> String { pub fn percent(value: f64) -> String {
let text = format!("{}%", value as u32); let text = format!("{}%", value as u32);
if value > 80.0 { if value > 80.0 {
@@ -34,12 +31,10 @@ pub fn battery_percent(value: u32) -> String {
} }
} }
// info
pub fn info(key: &str, value: &str) -> String { pub fn info(key: &str, value: &str) -> String {
format!("{}: {}", key.yellow().bold(), value) format!("{}: {}", key.yellow().bold(), value)
} }
// color blocks
pub fn color_blocks() -> String { pub fn color_blocks() -> String {
let normal = " ".on_black().to_string() let normal = " ".on_black().to_string()
+ &" ".on_red().to_string() + &" ".on_red().to_string()

View File

@@ -140,6 +140,7 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
let cols = ((width as f32 / char_w).ceil() as usize).max(1) + DEFAULT_GAP_COLUMNS; 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 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; let total_rows = rows + padding_top;
for _ in 0..total_rows { for _ in 0..total_rows {
@@ -159,6 +160,15 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
print!("{}", output); print!("{}", output);
std::io::stdout().flush().ok(); 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"); print!("\x1b[u");
if padding_top > 0 { 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(); 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. // Prints text at a horizontal offset for side-by-side layout with image.