You've already forked neo64fetch
mirror of
https://github.com/neoarz/neo64fetch.git
synced 2026-02-08 22:33:26 +01:00
fix: remove caption
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
// https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/memory/memory_apple.c
|
// https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/memory/memory_apple.c
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
use libc::{
|
use libc::{
|
||||||
HOST_VM_INFO64, HOST_VM_INFO64_COUNT, host_statistics64, mach_host_self, vm_statistics64_data_t,
|
HOST_VM_INFO64, HOST_VM_INFO64_COUNT, host_statistics64, mach_host_self, vm_statistics64_data_t,
|
||||||
};
|
};
|
||||||
@@ -39,6 +40,7 @@ pub fn get_memory_info() -> String {
|
|||||||
let mut vmstat: vm_statistics64_data_t = mem::zeroed(); // this this is unsafe we have to manually zero it
|
let mut vmstat: vm_statistics64_data_t = mem::zeroed(); // this this is unsafe we have to manually zero it
|
||||||
|
|
||||||
if host_statistics64(
|
if host_statistics64(
|
||||||
|
#[allow(deprecated)]
|
||||||
mach_host_self(),
|
mach_host_self(),
|
||||||
HOST_VM_INFO64,
|
HOST_VM_INFO64,
|
||||||
&mut vmstat as *mut _ as *mut _,
|
&mut vmstat as *mut _ as *mut _,
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@@ -8,6 +8,7 @@ mod output;
|
|||||||
|
|
||||||
use output::{colors, image};
|
use output::{colors, image};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
struct Stats {
|
struct Stats {
|
||||||
// Neoarz[at]Mac
|
// Neoarz[at]Mac
|
||||||
username: String,
|
username: String,
|
||||||
@@ -132,10 +133,24 @@ fn print_stats(stats: &Stats, offset: usize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LOGO_BYTES: &[u8] = include_bytes!("../assets/logo.png");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let stats = get_system_stats();
|
let stats = get_system_stats();
|
||||||
let (offset, img_rows) = image::print_image_and_setup("assets/logo.png", 700);
|
|
||||||
// ^^^ size of the image change it here
|
// Try to find the logo in the user's config directory
|
||||||
|
// Shouldve made it automake the directory, and tell user to add image there
|
||||||
|
// but oh well no one is using this anyways
|
||||||
|
let logo_path = std::env::var("HOME").map(|home| format!("{}/.config/neo64fetch/logo.png", home));
|
||||||
|
|
||||||
|
let (offset, img_rows) = if let Ok(path) = logo_path
|
||||||
|
&& std::path::Path::new(&path).exists()
|
||||||
|
{
|
||||||
|
image::print_image_and_setup(&path, 700)
|
||||||
|
} else {
|
||||||
|
image::print_image_from_memory(LOGO_BYTES, 700)
|
||||||
|
};
|
||||||
|
|
||||||
print_stats(&stats, offset);
|
print_stats(&stats, offset);
|
||||||
image::finish_printing(offset, 24, img_rows);
|
image::finish_printing(offset, 24, img_rows);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,25 +97,14 @@ fn terminal_cell_metrics() -> (f32, f32) {
|
|||||||
//
|
//
|
||||||
// Returns (column_offset, total_rows) for side-by-side text printing.
|
// Returns (column_offset, total_rows) for side-by-side text printing.
|
||||||
// Returns (0, 0) on failure; unsupported terminal or image load error (skill issue)
|
// Returns (0, 0) on failure; unsupported terminal or image load error (skill issue)
|
||||||
pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
|
fn process_and_print_image(img: image::DynamicImage, target_height: u32) -> (usize, usize) {
|
||||||
if !terminal_supports_kitty() {
|
let ratio = target_height as f32 / img.height() as f32;
|
||||||
return (0, 0);
|
let w = ((img.width() as f32 * ratio).round().max(1.0)) as u32;
|
||||||
}
|
let image = img.resize_exact(w, target_height, image::imageops::FilterType::Lanczos3);
|
||||||
|
|
||||||
// Load and proportionally resize to target height
|
|
||||||
let image = match image::open(Path::new(path)) {
|
|
||||||
Ok(img) => {
|
|
||||||
let ratio = target_height as f32 / img.height() as f32;
|
|
||||||
let w = ((img.width() as f32 * ratio).round().max(1.0)) as u32;
|
|
||||||
img.resize_exact(w, target_height, image::imageops::FilterType::Lanczos3)
|
|
||||||
}
|
|
||||||
Err(_) => return (0, 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
let (width, height) = image.dimensions();
|
let (width, height) = image.dimensions();
|
||||||
|
|
||||||
// Kitty protocol requires PNG format, even for JPEG/WebP sources
|
// Kitty protocol requires PNG format, even for JPEG/WebP sources
|
||||||
// See: https://github.com/Ly-sec/swiftfetch/blob/main/src/display.rs#L495-L501
|
|
||||||
let mut png_bytes = Vec::new();
|
let mut png_bytes = Vec::new();
|
||||||
if image
|
if image
|
||||||
.write_to(&mut Cursor::new(&mut png_bytes), ImageFormat::Png)
|
.write_to(&mut Cursor::new(&mut png_bytes), ImageFormat::Png)
|
||||||
@@ -149,12 +138,10 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert pixel dimensions to terminal columns/rows
|
// Convert pixel dimensions to terminal columns/rows
|
||||||
// See: https://github.com/Ly-sec/swiftfetch/blob/main/src/display.rs#L503-L511
|
|
||||||
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 {
|
||||||
@@ -162,8 +149,6 @@ pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use cursor positioning to place image
|
// use cursor positioning to place image
|
||||||
// swiftfetch uses a different approach with save/restore but lowk didnt work for me
|
|
||||||
// https://github.com/Ly-sec/swiftfetch/blob/main/src/display.rs#L225-L253
|
|
||||||
print!("\x1b[{}A", total_rows);
|
print!("\x1b[{}A", total_rows);
|
||||||
|
|
||||||
if padding_top > 0 {
|
if padding_top > 0 {
|
||||||
@@ -174,18 +159,6 @@ 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");
|
||||||
|
|
||||||
@@ -194,7 +167,29 @@ 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 + caption_rows)
|
(cols, total_rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_image_and_setup(path: &str, target_height: u32) -> (usize, usize) {
|
||||||
|
if !terminal_supports_kitty() {
|
||||||
|
return (0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
match image::open(Path::new(path)) {
|
||||||
|
Ok(img) => process_and_print_image(img, target_height),
|
||||||
|
Err(_) => (0, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_image_from_memory(bytes: &[u8], target_height: u32) -> (usize, usize) {
|
||||||
|
if !terminal_supports_kitty() {
|
||||||
|
return (0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
match image::load_from_memory(bytes) {
|
||||||
|
Ok(img) => process_and_print_image(img, target_height),
|
||||||
|
Err(_) => (0, 0),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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