mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-26 16:56:47 +00:00
shell name & colors in output
This commit is contained in:
parent
81cdc0a281
commit
a44db5e5f3
3 changed files with 37 additions and 20 deletions
|
@ -4,3 +4,10 @@ pub const CYAN: &str = "\x1b[36m";
|
||||||
pub const GREEN: &str = "\x1b[32m";
|
pub const GREEN: &str = "\x1b[32m";
|
||||||
pub const YELLOW: &str = "\x1b[33m";
|
pub const YELLOW: &str = "\x1b[33m";
|
||||||
pub const RED: &str = "\x1b[31m";
|
pub const RED: &str = "\x1b[31m";
|
||||||
|
pub const MAGENTA: &str = "\x1b[35m";
|
||||||
|
|
||||||
|
pub fn print_dots() -> Result<String, std::io::Error> {
|
||||||
|
let colors = format!("{BLUE} {CYAN} {GREEN} {YELLOW} {RED} {MAGENTA} {RESET}");
|
||||||
|
|
||||||
|
Ok(colors)
|
||||||
|
}
|
||||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -4,13 +4,13 @@ mod release;
|
||||||
mod system;
|
mod system;
|
||||||
mod uptime;
|
mod uptime;
|
||||||
|
|
||||||
use nix::sys::sysinfo::sysinfo;
|
use crate::colors::{print_dots, BLUE, CYAN, RESET};
|
||||||
|
|
||||||
use crate::colors::{BLUE, CYAN, RESET};
|
|
||||||
use crate::desktop::get_desktop_info;
|
use crate::desktop::get_desktop_info;
|
||||||
use crate::release::{get_os_pretty_name, get_system_info};
|
use crate::release::{get_os_pretty_name, get_system_info};
|
||||||
use crate::system::{get_memory_usage, get_root_disk_usage, get_username_and_hostname};
|
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
|
||||||
use crate::uptime::get_current;
|
use crate::uptime::get_current;
|
||||||
|
use color_eyre::Report;
|
||||||
|
use nix::sys::sysinfo::sysinfo;
|
||||||
|
|
||||||
fn main() -> Result<(), Report> {
|
fn main() -> Result<(), Report> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
@ -18,51 +18,51 @@ fn main() -> Result<(), Report> {
|
||||||
let user_info = get_username_and_hostname()?;
|
let user_info = get_username_and_hostname()?;
|
||||||
let os_name = get_os_pretty_name()?;
|
let os_name = get_os_pretty_name()?;
|
||||||
let kernel_version = get_system_info()?;
|
let kernel_version = get_system_info()?;
|
||||||
|
let shell = get_shell()?;
|
||||||
let uptime = get_current()?;
|
let uptime = get_current()?;
|
||||||
let window_manager = get_desktop_info()?;
|
let window_manager = get_desktop_info()?;
|
||||||
let memory_usage = get_memory_usage()?;
|
let sys_info = sysinfo()?;
|
||||||
|
let memory_usage = get_memory_usage(sys_info);
|
||||||
let storage = get_root_disk_usage()?;
|
let storage = get_root_disk_usage()?;
|
||||||
|
let colors = print_dots()?;
|
||||||
|
|
||||||
print_system_info(
|
print_system_info(
|
||||||
&user_info,
|
&user_info,
|
||||||
&os_name,
|
&os_name,
|
||||||
&kernel_version,
|
&kernel_version,
|
||||||
|
&shell,
|
||||||
&uptime,
|
&uptime,
|
||||||
&window_manager,
|
&window_manager,
|
||||||
&memory_usage,
|
&memory_usage,
|
||||||
&storage,
|
&storage,
|
||||||
|
&colors,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_system_info(
|
fn print_system_info(
|
||||||
user_info: &str,
|
user_info: &str,
|
||||||
os_name: &str,
|
os_name: &str,
|
||||||
kernel_version: &str,
|
kernel_version: &str,
|
||||||
|
shell: &str,
|
||||||
uptime: &str,
|
uptime: &str,
|
||||||
window_manager: &str,
|
window_manager: &str,
|
||||||
memory_usage: &str,
|
memory_usage: &str,
|
||||||
storage: &str,
|
storage: &str,
|
||||||
|
colors: &str,
|
||||||
) {
|
) {
|
||||||
println!(
|
println!(
|
||||||
"
|
"
|
||||||
{CYAN} ▜▙▖ {BLUE}▝▜▙ ▟█▘ {user_info} ~{RESET}
|
|
||||||
{CYAN} ▗▟█████▙▖{BLUE}▜██▘ {CYAN}▟▙ {CYAN} {BLUE}System{RESET} {os_name}
|
|
||||||
{BLUE} ▄▖ ▜▛ {CYAN}▟▛▘ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
|
||||||
{BLUE}▟███▛ {CYAN}▖ {BLUE}▝ {CYAN}▟███▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
|
||||||
{BLUE} ▗▟▛ {CYAN}▟▙ ▝▀ {CYAN} {BLUE}WM{RESET} {window_manager}
|
|
||||||
{BLUE} ▜▛ {CYAN}▗██▙{BLUE}▝▜█████▛▘ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
|
||||||
{CYAN} ▗█▛ ▜▙▖ {BLUE}▝▜▙ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
|
||||||
|
|
||||||
|
|
||||||
{CYAN} ▟█▖ {BLUE}▝█▙ ▗█▛ {user_info} ~{RESET}
|
{CYAN} ▟█▖ {BLUE}▝█▙ ▗█▛ {user_info} ~{RESET}
|
||||||
{CYAN} ▗▄▄▟██▄▄▄▄▄{BLUE}▝█▙█▛ {CYAN}▖ {CYAN} {BLUE}System{RESET} {os_name}
|
{CYAN} ▗▄▄▟██▄▄▄▄▄{BLUE}▝█▙█▛ {CYAN}▖ {CYAN} {BLUE}System{RESET} {os_name}
|
||||||
{CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
{CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
||||||
{BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
{BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET} {shell}
|
||||||
{BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}WM{RESET} {window_manager}
|
{BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
||||||
{BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
{BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}WM{RESET} {window_manager}
|
||||||
{BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
{BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
||||||
{BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘
|
{BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
||||||
{CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛
|
{CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛ {CYAN} {BLUE}Colors{RESET} {colors}
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,16 @@ pub fn get_username_and_hostname() -> Result<String, io::Error> {
|
||||||
Ok(format!("{YELLOW}{username}{RED}@{GREEN}{hostname}"))
|
Ok(format!("{YELLOW}{username}{RED}@{GREEN}{hostname}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_shell() -> Result<String, io::Error> {
|
||||||
|
// In some setups, $SHELL is set to the store path
|
||||||
|
// of the actual shell program. While we can consider
|
||||||
|
// trimming by name, I will leave it to the user to handle
|
||||||
|
// what their SHELL variable is really set to.
|
||||||
|
let shell = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
|
||||||
|
|
||||||
|
Ok(shell)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
||||||
let vfs = statvfs("/")?;
|
let vfs = statvfs("/")?;
|
||||||
let block_size = vfs.block_size() as u64;
|
let block_size = vfs.block_size() as u64;
|
||||||
|
|
Loading…
Reference in a new issue