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
760 changes: 452 additions & 308 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@ opt-level = 3
strip = true

[dependencies]
whoami = { version = "2.0.0", default-features = false, features = ["std"] }
bitcode = "0.6.9"
csscolorparser = "0.8.3"
dirs = "6.0.0"
image = { version = "0.25.10", optional = true }
owo-colors = "4.2.3"
rayon = "1.11.0"
serde = { version = "1.0.228", features = ["derive"] }
image = { version = "0.25.9", optional = true }
viuer = { version = "0.11.0", optional = true }
unicode-segmentation = "1.12.0"
serde_json = "1.0.149"
socket2 = "0.6.3"
starship-battery = "0.11.0"
strip-ansi-escapes = "0.2.1"
starship-battery = "0.10.3"
strum = { version = "0.28.0", features = ["derive"] }
supports-unicode = "3.0.0"
csscolorparser = "0.8.1"
serde_json = "1.0.148"
sysinfo = "0.38.4"
sys-locale = "0.3.2"
owo-colors = "4.2.3"
sysinfo = "0.37.2"
bitcode = "0.6.9"
socket2 = "0.6.1"
rayon = "1.11.0"
which = "8.0.0"
dirs = "6.0.0"
unicode-segmentation = "1.13.2"
viuer = { version = "0.11.0", optional = true }
which = "8.0.2"
whoami = { version = "2.1.1", default-features = false, features = ["std"] }

[features]
default = []
Expand Down
15 changes: 15 additions & 0 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::deserialize::ColorWrapper;

pub const DEFAULT_COLOR: ColorWrapper = ColorWrapper::Rgb {
r: 255,
g: 255,
b: 255,
};
pub const DEFAULT_COLOR_OPTION: Option<ColorWrapper> = Some(DEFAULT_COLOR);

pub const DEFAULT_IPV4_DOMAIN: &str = "ipinfo.io";
pub const DEFAULT_IPV4_PORT: u16 = 80;
pub const DEFAULT_IPV4_PATH: &str = "/ip";
pub const DEFAULT_IPV6_DOMAIN: &str = "v6.ipinfo.io";
pub const DEFAULT_IPV6_PORT: u16 = 80;
pub const DEFAULT_IPV6_PATH: &str = "/ip";
63 changes: 36 additions & 27 deletions src/config/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::{
config::SeparatorSizing, logos::get_logo, system::InfoKind, translations::get_language,
};
use bitcode::{Decode, Encode};
use owo_colors::DynColors;
use serde::Deserialize;

use super::{SeparatorSizing, constants};
use crate::config::constants::DEFAULT_COLOR;
use crate::logos::system_logo;
use crate::system::InfoKind;
use crate::translations::get_language;

#[derive(Debug, Deserialize)]
struct ConfigWrapper<'a> {
#[serde(default)]
Expand Down Expand Up @@ -124,12 +128,18 @@ enum ColorRepr<'a> {
Text(&'a str),
}

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

impl Default for ColorWrapper {
fn default() -> Self {
DEFAULT_COLOR
}
}

impl From<ColorWrapper> for DynColors {
fn from(value: ColorWrapper) -> Self {
match value {
Expand All @@ -139,12 +149,6 @@ impl From<ColorWrapper> for DynColors {
}
}

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

#[inline]
fn color_repr_to_wrapper(
color: Option<ColorRepr>,
Expand All @@ -168,18 +172,19 @@ fn color_repr_to_wrapper(
}

impl<'de> serde::Deserialize<'de> for super::Config<'de> {
#[allow(clippy::too_many_lines)]
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let config = ConfigWrapper::deserialize(deserializer)?;
let language_func = get_language(config.language.into());
let logo_color = if let super::LogoStyle::Braille { logo: Some(logo) } = config.logo {
Some(ColorWrapper::Ansi(get_logo(Some(logo.to_owned())).1))
Some(ColorWrapper::Ansi(system_logo(Some(logo.to_owned())).1))
} else {
None
};

let entries = config
.info
.map(|info| {
let entries = config.info.map_or_else(
|| super::default_entries(config.language),
|info| {
info.into_iter()
.map(|info| match info {
Entry::Info {
Expand All @@ -195,10 +200,10 @@ impl<'de> serde::Deserialize<'de> for super::Config<'de> {
super::Entry::Info {
kind,
fields: kind
.get_fields()
.fields()
.iter()
.filter(|field| {
let field_str = field.as_str();
let field_str: &'static str = (*field).into();
header.contains(field_str) || format.contains(field_str)
})
.copied()
Expand Down Expand Up @@ -240,8 +245,8 @@ impl<'de> serde::Deserialize<'de> for super::Config<'de> {
},
})
.collect::<Vec<_>>()
})
.unwrap_or_else(|| super::default_entries(config.language));
},
);

Ok(Self {
info: super::group_fields_by_kind(&entries),
Expand All @@ -251,13 +256,17 @@ impl<'de> serde::Deserialize<'de> for super::Config<'de> {
header: color_repr_to_wrapper(config.colors.header, logo_color, logo_color),
header_separator: color_repr_to_wrapper(
config.colors.header_separator,
super::FALLBACK_COLOR,
constants::DEFAULT_COLOR_OPTION,
logo_color,
),
info: color_repr_to_wrapper(
config.colors.info,
constants::DEFAULT_COLOR_OPTION,
logo_color,
),
info: color_repr_to_wrapper(config.colors.info, super::FALLBACK_COLOR, logo_color),
separator: color_repr_to_wrapper(
config.colors.separator,
super::FALLBACK_COLOR,
constants::DEFAULT_COLOR_OPTION,
logo_color,
),
},
Expand Down Expand Up @@ -287,14 +296,14 @@ impl<'de> serde::Deserialize<'de> for super::Config<'de> {
.map(|public_ip| super::PublicIpInfoConfig {
ipv4_domain: public_ip
.ipv4_domain
.unwrap_or(super::DEFAULT_IPV4_DOMAIN),
ipv4_port: public_ip.ipv4_port.unwrap_or(super::DEFAULT_IPV4_PORT),
ipv4_path: public_ip.ipv4_path.unwrap_or(super::DEFAULT_IPV4_PATH),
.unwrap_or(constants::DEFAULT_IPV4_DOMAIN),
ipv4_port: public_ip.ipv4_port.unwrap_or(constants::DEFAULT_IPV4_PORT),
ipv4_path: public_ip.ipv4_path.unwrap_or(constants::DEFAULT_IPV4_PATH),
ipv6_domain: public_ip
.ipv6_domain
.unwrap_or(super::DEFAULT_IPV6_DOMAIN),
ipv6_port: public_ip.ipv6_port.unwrap_or(super::DEFAULT_IPV6_PORT),
ipv6_path: public_ip.ipv6_path.unwrap_or(super::DEFAULT_IPV6_PATH),
.unwrap_or(constants::DEFAULT_IPV6_DOMAIN),
ipv6_port: public_ip.ipv6_port.unwrap_or(constants::DEFAULT_IPV6_PORT),
ipv6_path: public_ip.ipv6_path.unwrap_or(constants::DEFAULT_IPV6_PATH),
})
.unwrap_or_default(),
})
Expand Down
Loading
Loading