Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 85 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "afetch"
version = "0.0.7"
authors = ["Asthowen<contact@asthowen.fr>", "Squitch1<clement.foure@proton.me>"]
edition = "2024"
rust-version = "1.85.0"
rust-version = "1.88.0"
description = "A CLI system information tool written in Rust."
repository = "https://github.com/Asthowen/AFetch"
readme = "README.md"
Expand All @@ -23,7 +23,6 @@ opt-level = 3
strip = true

[dependencies]
colored = { version = "3.0.0", git = "https://github.com/colored-rs/colored", branch = "master" }
whoami = { version = "1.5.2", default-features = false }
serde = { version = "1.0.219", features = ["derive"] }
image = { version = "0.25.6", optional = true }
Expand All @@ -33,12 +32,13 @@ strip-ansi-escapes = "0.2.1"
starship-battery = "0.10.2"
supports-unicode = "3.0.0"
csscolorparser = "0.7.2"
serde_json = "1.0.142"
serde_json = "1.0.143"
sys-locale = "0.3.2"
sysinfo = "0.36.1"
bitcode = "0.6.6"
owo-colors = "4.2.2"
sysinfo = "0.37.0"
bitcode = "0.6.7"
socket2 = "0.6.0"
rayon = "1.10.0"
rayon = "1.11.0"
which = "8.0.0"
dirs = "6.0.0"

Expand Down
23 changes: 22 additions & 1 deletion src/config/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
config::SeparatorSizing, logos::get_logo, system::InfoKind, translations::get_language,
util::colored::ColorWrapper,
};
use owo_colors::DynColors;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -124,6 +124,27 @@ enum ColorRepr<'a> {
Text(&'a str),
}

#[derive(Debug, Clone, Copy, bitcode::Decode, bitcode::Encode)]
pub enum ColorWrapper {
Rgb { r: u8, g: u8, b: u8 },
Ansi(u8),
}

impl From<ColorWrapper> for DynColors {
fn from(value: ColorWrapper) -> Self {
match value {
ColorWrapper::Ansi(color) => Self::Xterm(color.into()),
ColorWrapper::Rgb { r, g, b } => Self::Rgb(r, g, b),
}
}
}

impl Default for ColorWrapper {
fn default() -> Self {
Self::Ansi(6)
}
}

#[inline]
fn color_repr_to_wrapper(
color: Option<ColorRepr>,
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
pub mod deserialize;

use crate::{
config::deserialize::ColorWrapper,
error::FetchInfoError,
system::{InfoField, InfoKind},
translations::get_language,
util::colored::ColorWrapper,
};
use bitcode::{Decode, Encode};
use serde::Deserialize;
Expand Down
71 changes: 40 additions & 31 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use afetch::config::deserialize::ColorWrapper;
use afetch::config::{Config, Entry, LogoStyle, SeparatorSizing, load_config};
use afetch::error::{ErrorType, FetchInfoError};
use afetch::logos::get_logo;
Expand All @@ -16,11 +17,10 @@ use afetch::system::public_ip::get_public_ip;
use afetch::system::uptime::get_uptime;
use afetch::system::{InfoGroup, InfoKind, InfoResult};
use afetch::translations::get_language;
use afetch::util::colored::{ColorWrapper, ColorizeExt};
use afetch::util::count_str_length;
#[cfg(feature = "image")]
use afetch::util::print_picture;
use colored::Colorize;
use owo_colors::{DynColors, OwoColorize, XtermColors};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::collections::HashMap;
use std::fmt::Write;
Expand Down Expand Up @@ -70,25 +70,38 @@ fn main() -> Result<(), FetchInfoError> {
None
};

let header_color = match config.colors.header {
Some(color) => color,
let header_color: DynColors = match config.colors.header {
Some(color) => color.into(),
None => match logo.as_ref() {
Some(color) => ColorWrapper::Ansi(color.1),
None => ColorWrapper::Ansi(6),
Some(color) => DynColors::Xterm(color.1.into()),
None => DynColors::Xterm(XtermColors::Cyan),
},
};
let header_separator_color = config.colors.header_separator.unwrap_or(match &logo {
Some(color) => ColorWrapper::Ansi(color.1),
None => ColorWrapper::Ansi(6),
});
let info_color = config.colors.info.unwrap_or(match &logo {
Some(color) => ColorWrapper::Ansi(color.1),
None => ColorWrapper::Ansi(6),
});
let separator_color = config.colors.separator.unwrap_or(match &logo {
Some(color) => ColorWrapper::Ansi(color.1),
None => ColorWrapper::Ansi(6),
});
let header_separator_color: DynColors = config
.colors
.header_separator
.map(ColorWrapper::into)
.unwrap_or(match &logo {
Some(color) => DynColors::Xterm(color.1.into()),
None => DynColors::Xterm(XtermColors::Cyan),
});
let info_color: DynColors = config
.colors
.info
.map(ColorWrapper::into)
.unwrap_or(match &logo {
Some(color) => DynColors::Xterm(color.1.into()),
None => DynColors::Xterm(XtermColors::Cyan),
});
let separator_color: DynColors =
config
.colors
.separator
.map(ColorWrapper::into)
.unwrap_or(match &logo {
Some(color) => DynColors::Xterm(color.1.into()),
None => DynColors::Xterm(XtermColors::Cyan),
});

let mut output: String = String::default();
let mut last_info_len = 0;
Expand Down Expand Up @@ -153,9 +166,9 @@ fn main() -> Result<(), FetchInfoError> {

formatted_info = format!(
"{}{}{}",
formatted_header.custom_color_wrapper(header_color).bold(),
separator.custom_color_wrapper(header_separator_color),
formatted_info.custom_color_wrapper(info_color)
formatted_header.color(header_color).bold(),
separator.color(header_separator_color),
formatted_info.color(info_color)
);

write_entry(formatted_info);
Expand All @@ -174,11 +187,7 @@ fn main() -> Result<(), FetchInfoError> {
}
};

write_entry(
formatted_separator
.custom_color_wrapper(separator_color)
.to_string(),
);
write_entry(formatted_separator.color(separator_color).to_string());
}
Entry::ColorBlocks { content, display } => {
if display.show_normal() {
Expand All @@ -199,11 +208,11 @@ fn main() -> Result<(), FetchInfoError> {
}
}

if let Some((_, _, lines)) = &logo {
if i < lines.len() {
for logo_line in &lines[i..] {
writeln!(output, " {}{}", logo_line, "".white()).ok();
}
if let Some((_, _, lines)) = &logo
&& i < lines.len()
{
for logo_line in &lines[i..] {
writeln!(output, " {}{}", logo_line, "".white()).ok();
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/system/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ pub fn get_networks(
.map(|ip| ip.addr);
let first_ipv6 = network.ip_networks().iter().find(|ip| ip.addr.is_ipv6());

if config.parameters.networks.private_only {
if let Some(IpAddr::V4(ip)) = first_ipv4 {
if !ip.is_private() {
continue;
}
}
if config.parameters.networks.private_only
&& let Some(IpAddr::V4(ip)) = first_ipv4
&& !ip.is_private()
{
continue;
}

networks_info.push(InfoGroup {
Expand Down
27 changes: 0 additions & 27 deletions src/util/colored.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod colored;
mod filtered_values;

pub use filtered_values::ToOptionString;
Expand Down
Loading