diff --git a/Cargo.lock b/Cargo.lock index f4d5a19..f21044e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,12 +306,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.155" @@ -332,11 +326,10 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "microfetch" -version = "0.4.4" +version = "0.4.0" dependencies = [ "color-eyre", "criterion", - "lazy_static", "nix", ] diff --git a/Cargo.toml b/Cargo.toml index 2db7a6a..5c346cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "microfetch" -version = "0.4.4" +version = "0.4.0" edition = "2021" [lib] @@ -14,7 +14,6 @@ path = "src/main.rs" [dependencies] nix = { version = "0.29", features = ["fs", "hostname", "feature"] } color-eyre = { version = "0.6", default-features = false } -lazy_static = "1.5.0" [dev-dependencies] criterion = "0.5" diff --git a/README.md b/README.md index 28d6338..804fa36 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ of maintainability. Runs in a _fraction of a millisecond_ and displays _most_ of the nonsense you'd see posted on r/unixporn or other internet communities. Aims to replace [fastfetch](https://github.com/fastfetch-cli/fastfetch) on my personal system, but [probably not yours](#customizing). Though, you are more -than welcome to use it on your system: it's pretty [fast](#benchmarks)... +than welcome to use it on your system: it's pretty [fast...](#benchmarks)
You will need a Nerdfonts patched font installed, and for your terminal
> emulator to support said font. Microfetch uses nerdfonts glyphs by default.
-Microfetch is packaged in [nixpkgs](https://github.com/nixos/nixpkgs). It can be
-installed by adding `pkgs.microfetch` to your `environment.systemPackages`.
-Additionally, you can try out Microfetch in a Nix shell.
-
-```bash
-nix shell nixpkgs#microfetch
-```
-
-Or run it directly with `nix run`
-
-```bash
-nix run nixpkgs#microfetch
-```
+Microfetch is packaged in [nixpkgs](https://github.com/nixos/nixpkgs). You can
+get it through the unstable channel for the time being. The Nix flake can also
+be used for bleeding-edge builds.
Non-Nix users will have to build Microfetch with `cargo`. It is not published
anywhere but I imagine you can use `cargo install --git` to install it from
diff --git a/src/colors.rs b/src/colors.rs
index 061db15..a8aee60 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -1,57 +1,11 @@
-use std::env;
-
-pub struct Colors {
- pub reset: &'static str,
- pub blue: &'static str,
- pub cyan: &'static str,
- pub green: &'static str,
- pub yellow: &'static str,
- pub red: &'static str,
- pub magenta: &'static str,
-}
-
-impl Colors {
- const fn new(is_no_color: bool) -> Self {
- match is_no_color {
- true => Self {
- reset: "",
- blue: "",
- cyan: "",
- green: "",
- yellow: "",
- red: "",
- magenta: "",
- },
- false => Self {
- reset: "\x1b[0m",
- blue: "\x1b[34m",
- cyan: "\x1b[36m",
- green: "\x1b[32m",
- yellow: "\x1b[33m",
- red: "\x1b[31m",
- magenta: "\x1b[35m",
- },
- }
- }
-}
-
-lazy_static::lazy_static! {
- pub static ref COLORS: Colors = {
- // check for NO_COLOR once at startup
- let is_no_color = env::var("NO_COLOR").is_ok();
- Colors::new(is_no_color)
- };
-}
+pub const RESET: &str = "\x1b[0m";
+pub const BLUE: &str = "\x1b[34m";
+pub const CYAN: &str = "\x1b[36m";
+pub const GREEN: &str = "\x1b[32m";
+pub const YELLOW: &str = "\x1b[33m";
+pub const RED: &str = "\x1b[31m";
+pub const MAGENTA: &str = "\x1b[35m";
pub fn print_dots() -> String {
- format!(
- "{} {} {} {} {} {} {}",
- COLORS.blue,
- COLORS.cyan,
- COLORS.green,
- COLORS.yellow,
- COLORS.red,
- COLORS.magenta,
- COLORS.reset,
- )
+ format!("{BLUE} {CYAN} {GREEN} {YELLOW} {RED} {MAGENTA} {RESET}")
}
diff --git a/src/main.rs b/src/main.rs
index 0d70f89..5cb9904 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,13 +4,15 @@ mod release;
mod system;
mod uptime;
-use crate::colors::print_dots;
+use std::io::Write;
+
+use crate::colors::{print_dots, BLUE, CYAN, RESET};
use crate::desktop::get_desktop_info;
use crate::release::{get_os_pretty_name, get_system_info};
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
use crate::uptime::get_current;
+
use color_eyre::Report;
-use std::io::Write;
fn main() -> Result<(), Report> {
color_eyre::install()?;
@@ -54,8 +56,6 @@ struct Fields {
}
fn print_system_info(fields: &Fields) {
- use crate::colors::COLORS;
-
let Fields {
user_info,
os_name,
@@ -68,22 +68,16 @@ fn print_system_info(fields: &Fields) {
colors,
} = fields;
- let cyan = COLORS.cyan;
- let blue = COLORS.blue;
- let reset = COLORS.reset;
- let system_info = format!("
- {cyan} ▟█▖ {blue}▝█▙ ▗█▛ {user_info} ~{reset}
- {cyan} ▗▄▄▟██▄▄▄▄▄{blue}▝█▙█▛ {cyan}▖ {cyan} {blue}System{reset} {os_name}
- {cyan} ▀▀▀▀▀▀▀▀▀▀▀▘{blue}▝██ {cyan}▟█▖ {cyan} {blue}Kernel{reset} {kernel_version}
- {blue} ▟█▛ {blue}▝█▘{cyan}▟█▛ {cyan} {blue}Shell{reset} {shell}
- {blue}▟█████▛ {cyan}▟█████▛ {cyan} {blue}Uptime{reset} {uptime}
- {blue} ▟█▛{cyan}▗█▖ {cyan}▟█▛ {cyan} {blue}Desktop{reset} {desktop}
- {blue} ▝█▛ {cyan}██▖{blue}▗▄▄▄▄▄▄▄▄▄▄▄ {cyan} {blue}Memory{reset} {memory_usage}
- {blue} ▝ {cyan}▟█▜█▖{blue}▀▀▀▀▀██▛▀▀▘ {cyan} {blue}Storage (/){reset} {storage}
- {cyan} ▟█▘ ▜█▖ {blue}▝█▛ {cyan} {blue}Colors{reset} {colors}");
-
- std::io::stdout()
- .lock()
- .write_all(format!("{}\n", system_info).as_bytes())
- .expect("Failed to write to stdout");
+ let _ = std::io::stdout().write_all(format!(
+ "
+ {CYAN} ▟█▖ {BLUE}▝█▙ ▗█▛ {user_info} ~{RESET}
+ {CYAN} ▗▄▄▟██▄▄▄▄▄{BLUE}▝█▙█▛ {CYAN}▖ {CYAN} {BLUE}System{RESET} {os_name}
+ {CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
+ {BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET} {shell}
+ {BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
+ {BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}Desktop{RESET} {desktop}
+ {BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Memory{RESET} {memory_usage}
+ {BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘ {CYAN} {BLUE}Storage (/){RESET} {storage}
+ {CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛ {CYAN} {BLUE}Colors{RESET} {colors}
+").as_bytes());
}
diff --git a/src/release.rs b/src/release.rs
index c0036fb..3f38977 100644
--- a/src/release.rs
+++ b/src/release.rs
@@ -21,13 +21,7 @@ pub fn get_os_pretty_name() -> Result