You've already forked neo64fetch
mirror of
https://github.com/neoarz/neo64fetch.git
synced 2026-02-08 22:33:26 +01:00
feat: add small caption
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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 (char_w, char_h) = terminal_cell_metrics();
|
||||||
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user