Skip to content

Commit e337368

Browse files
authored
feat: replace colored with owo-colors (#13)
1 parent cfee20d commit e337368

8 files changed

Lines changed: 159 additions & 162 deletions

File tree

Cargo.lock

Lines changed: 85 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "afetch"
33
version = "0.0.7"
44
authors = ["Asthowen<contact@asthowen.fr>", "Squitch1<clement.foure@proton.me>"]
55
edition = "2024"
6-
rust-version = "1.85.0"
6+
rust-version = "1.88.0"
77
description = "A CLI system information tool written in Rust."
88
repository = "https://github.com/Asthowen/AFetch"
99
readme = "README.md"
@@ -23,7 +23,6 @@ opt-level = 3
2323
strip = true
2424

2525
[dependencies]
26-
colored = { version = "3.0.0", git = "https://github.com/colored-rs/colored", branch = "master" }
2726
whoami = { version = "1.5.2", default-features = false }
2827
serde = { version = "1.0.219", features = ["derive"] }
2928
image = { version = "0.25.6", optional = true }
@@ -33,12 +32,13 @@ strip-ansi-escapes = "0.2.1"
3332
starship-battery = "0.10.2"
3433
supports-unicode = "3.0.0"
3534
csscolorparser = "0.7.2"
36-
serde_json = "1.0.142"
35+
serde_json = "1.0.143"
3736
sys-locale = "0.3.2"
38-
sysinfo = "0.36.1"
39-
bitcode = "0.6.6"
37+
owo-colors = "4.2.2"
38+
sysinfo = "0.37.0"
39+
bitcode = "0.6.7"
4040
socket2 = "0.6.0"
41-
rayon = "1.10.0"
41+
rayon = "1.11.0"
4242
which = "8.0.0"
4343
dirs = "6.0.0"
4444

src/config/deserialize.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
config::SeparatorSizing, logos::get_logo, system::InfoKind, translations::get_language,
3-
util::colored::ColorWrapper,
43
};
4+
use owo_colors::DynColors;
55
use serde::Deserialize;
66

77
#[derive(Debug, Deserialize)]
@@ -124,6 +124,27 @@ enum ColorRepr<'a> {
124124
Text(&'a str),
125125
}
126126

127+
#[derive(Debug, Clone, Copy, bitcode::Decode, bitcode::Encode)]
128+
pub enum ColorWrapper {
129+
Rgb { r: u8, g: u8, b: u8 },
130+
Ansi(u8),
131+
}
132+
133+
impl From<ColorWrapper> for DynColors {
134+
fn from(value: ColorWrapper) -> Self {
135+
match value {
136+
ColorWrapper::Ansi(color) => Self::Xterm(color.into()),
137+
ColorWrapper::Rgb { r, g, b } => Self::Rgb(r, g, b),
138+
}
139+
}
140+
}
141+
142+
impl Default for ColorWrapper {
143+
fn default() -> Self {
144+
Self::Ansi(6)
145+
}
146+
}
147+
127148
#[inline]
128149
fn color_repr_to_wrapper(
129150
color: Option<ColorRepr>,

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
pub mod deserialize;
44

55
use crate::{
6+
config::deserialize::ColorWrapper,
67
error::FetchInfoError,
78
system::{InfoField, InfoKind},
89
translations::get_language,
9-
util::colored::ColorWrapper,
1010
};
1111
use bitcode::{Decode, Encode};
1212
use serde::Deserialize;

src/main.rs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use afetch::config::deserialize::ColorWrapper;
12
use afetch::config::{Config, Entry, LogoStyle, SeparatorSizing, load_config};
23
use afetch::error::{ErrorType, FetchInfoError};
34
use afetch::logos::get_logo;
@@ -16,11 +17,10 @@ use afetch::system::public_ip::get_public_ip;
1617
use afetch::system::uptime::get_uptime;
1718
use afetch::system::{InfoGroup, InfoKind, InfoResult};
1819
use afetch::translations::get_language;
19-
use afetch::util::colored::{ColorWrapper, ColorizeExt};
2020
use afetch::util::count_str_length;
2121
#[cfg(feature = "image")]
2222
use afetch::util::print_picture;
23-
use colored::Colorize;
23+
use owo_colors::{DynColors, OwoColorize, XtermColors};
2424
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
2525
use std::collections::HashMap;
2626
use std::fmt::Write;
@@ -70,25 +70,38 @@ fn main() -> Result<(), FetchInfoError> {
7070
None
7171
};
7272

73-
let header_color = match config.colors.header {
74-
Some(color) => color,
73+
let header_color: DynColors = match config.colors.header {
74+
Some(color) => color.into(),
7575
None => match logo.as_ref() {
76-
Some(color) => ColorWrapper::Ansi(color.1),
77-
None => ColorWrapper::Ansi(6),
76+
Some(color) => DynColors::Xterm(color.1.into()),
77+
None => DynColors::Xterm(XtermColors::Cyan),
7878
},
7979
};
80-
let header_separator_color = config.colors.header_separator.unwrap_or(match &logo {
81-
Some(color) => ColorWrapper::Ansi(color.1),
82-
None => ColorWrapper::Ansi(6),
83-
});
84-
let info_color = config.colors.info.unwrap_or(match &logo {
85-
Some(color) => ColorWrapper::Ansi(color.1),
86-
None => ColorWrapper::Ansi(6),
87-
});
88-
let separator_color = config.colors.separator.unwrap_or(match &logo {
89-
Some(color) => ColorWrapper::Ansi(color.1),
90-
None => ColorWrapper::Ansi(6),
91-
});
80+
let header_separator_color: DynColors = config
81+
.colors
82+
.header_separator
83+
.map(ColorWrapper::into)
84+
.unwrap_or(match &logo {
85+
Some(color) => DynColors::Xterm(color.1.into()),
86+
None => DynColors::Xterm(XtermColors::Cyan),
87+
});
88+
let info_color: DynColors = config
89+
.colors
90+
.info
91+
.map(ColorWrapper::into)
92+
.unwrap_or(match &logo {
93+
Some(color) => DynColors::Xterm(color.1.into()),
94+
None => DynColors::Xterm(XtermColors::Cyan),
95+
});
96+
let separator_color: DynColors =
97+
config
98+
.colors
99+
.separator
100+
.map(ColorWrapper::into)
101+
.unwrap_or(match &logo {
102+
Some(color) => DynColors::Xterm(color.1.into()),
103+
None => DynColors::Xterm(XtermColors::Cyan),
104+
});
92105

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

154167
formatted_info = format!(
155168
"{}{}{}",
156-
formatted_header.custom_color_wrapper(header_color).bold(),
157-
separator.custom_color_wrapper(header_separator_color),
158-
formatted_info.custom_color_wrapper(info_color)
169+
formatted_header.color(header_color).bold(),
170+
separator.color(header_separator_color),
171+
formatted_info.color(info_color)
159172
);
160173

161174
write_entry(formatted_info);
@@ -174,11 +187,7 @@ fn main() -> Result<(), FetchInfoError> {
174187
}
175188
};
176189

177-
write_entry(
178-
formatted_separator
179-
.custom_color_wrapper(separator_color)
180-
.to_string(),
181-
);
190+
write_entry(formatted_separator.color(separator_color).to_string());
182191
}
183192
Entry::ColorBlocks { content, display } => {
184193
if display.show_normal() {
@@ -199,11 +208,11 @@ fn main() -> Result<(), FetchInfoError> {
199208
}
200209
}
201210

202-
if let Some((_, _, lines)) = &logo {
203-
if i < lines.len() {
204-
for logo_line in &lines[i..] {
205-
writeln!(output, " {}{}", logo_line, "".white()).ok();
206-
}
211+
if let Some((_, _, lines)) = &logo
212+
&& i < lines.len()
213+
{
214+
for logo_line in &lines[i..] {
215+
writeln!(output, " {}{}", logo_line, "".white()).ok();
207216
}
208217
}
209218

src/system/networks.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ pub fn get_networks(
4848
.map(|ip| ip.addr);
4949
let first_ipv6 = network.ip_networks().iter().find(|ip| ip.addr.is_ipv6());
5050

51-
if config.parameters.networks.private_only {
52-
if let Some(IpAddr::V4(ip)) = first_ipv4 {
53-
if !ip.is_private() {
54-
continue;
55-
}
56-
}
51+
if config.parameters.networks.private_only
52+
&& let Some(IpAddr::V4(ip)) = first_ipv4
53+
&& !ip.is_private()
54+
{
55+
continue;
5756
}
5857

5958
networks_info.push(InfoGroup {

src/util/colored.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/util/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod colored;
21
mod filtered_values;
32

43
pub use filtered_values::ToOptionString;

0 commit comments

Comments
 (0)