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
82 changes: 42 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ strip-ansi-escapes = "0.2.1"
starship-battery = "0.10.2"
supports-unicode = "3.0.0"
csscolorparser = "0.7.2"
serde_json = "1.0.140"
serde_json = "1.0.142"
sys-locale = "0.3.2"
sysinfo = "0.36.0"
sysinfo = "0.36.1"
bitcode = "0.6.6"
minreq = "2.14.0"
socket2 = "0.6.0"
rayon = "1.10.0"
which = "8.0.0"
dirs = "6.0.0"
Expand Down
33 changes: 33 additions & 0 deletions src/config/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct InfoConfig<'a> {
disks: Option<DisksInfoConfig<'a>>,
#[serde(default, borrow)]
networks: Option<NetworksInfoConfig<'a>>,
#[serde(default, borrow)]
public_ip: Option<PublicIpInfoConfig<'a>>,
}

#[derive(Debug, Deserialize)]
Expand All @@ -47,6 +49,22 @@ struct NetworksInfoConfig<'a> {
ignore_loopback: Option<bool>,
}

#[derive(Debug, Deserialize)]
struct PublicIpInfoConfig<'a> {
#[serde(default, borrow)]
ipv4_domain: Option<&'a str>,
#[serde(default)]
ipv4_port: Option<u16>,
#[serde(default, borrow)]
ipv4_path: Option<&'a str>,
#[serde(default, borrow)]
ipv6_domain: Option<&'a str>,
#[serde(default)]
ipv6_port: Option<u16>,
#[serde(default, borrow)]
ipv6_path: Option<&'a str>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
enum ColorBlockStyle<'a> {
Expand Down Expand Up @@ -243,6 +261,21 @@ impl<'de: 'static> serde::Deserialize<'de> for super::Config {
ignore_loopback: networks.ignore_loopback.unwrap_or(true),
})
.unwrap_or_default(),
public_ip: info
.public_ip
.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),
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_default(),
})
.unwrap_or_default(),
})
Expand Down
30 changes: 30 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const FALLBACK_COLOR: Option<ColorWrapper> = Some(ColorWrapper::Rgb {
g: 255,
b: 255,
});
const DEFAULT_IPV4_DOMAIN: &str = "ipinfo.io";
const DEFAULT_IPV4_PORT: u16 = 80;
const DEFAULT_IPV4_PATH: &str = "/ip";
const DEFAULT_IPV6_DOMAIN: &str = "v6.ipinfo.io";
const DEFAULT_IPV6_PORT: u16 = 80;
const DEFAULT_IPV6_PATH: &str = "/ip";

#[derive(Debug, Decode, Encode)]
pub struct Config {
Expand All @@ -32,6 +38,7 @@ pub struct Config {
pub struct InfoConfig<'a> {
pub disks: DisksInfoConfig<'a>,
pub networks: NetworksInfoConfig<'a>,
pub public_ip: PublicIpInfoConfig<'a>,
}

#[derive(Debug, Decode, Encode)]
Expand All @@ -49,6 +56,16 @@ pub struct NetworksInfoConfig<'a> {
pub ignore_loopback: bool,
}

#[derive(Debug, Decode, Encode)]
pub struct PublicIpInfoConfig<'a> {
pub ipv4_domain: &'a str,
pub ipv4_port: u16,
pub ipv4_path: &'a str,
pub ipv6_domain: &'a str,
pub ipv6_port: u16,
pub ipv6_path: &'a str,
}

impl<'a> Default for DisksInfoConfig<'a> {
fn default() -> Self {
Self {
Expand All @@ -72,6 +89,19 @@ impl<'a> Default for NetworksInfoConfig<'a> {
}
}

impl<'a> Default for PublicIpInfoConfig<'a> {
fn default() -> Self {
Self {
ipv4_domain: DEFAULT_IPV4_DOMAIN,
ipv4_port: DEFAULT_IPV4_PORT,
ipv4_path: DEFAULT_IPV4_PATH,
ipv6_domain: DEFAULT_IPV6_DOMAIN,
ipv6_port: DEFAULT_IPV6_PORT,
ipv6_path: DEFAULT_IPV6_PATH,
}
}
}

#[derive(Debug, Decode, Encode)]
pub struct ColorOption {
pub header: Option<ColorWrapper>,
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use afetch::system::memory::get_memory;
use afetch::system::motherboard::get_motherboard;
use afetch::system::networks::get_networks;
use afetch::system::product::get_product;
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;
Expand Down Expand Up @@ -47,6 +48,7 @@ fn main() -> Result<(), FetchInfoError> {
InfoKind::Motherboard => get_motherboard(language_func, fields, &config),
InfoKind::Networks => get_networks(language_func, fields, &config),
InfoKind::Product => get_product(language_func, fields, &config),
InfoKind::PublicIp => get_public_ip(language_func, fields, &config),
InfoKind::Uptime => get_uptime(language_func, fields, &config),
},
)
Expand Down
3 changes: 1 addition & 2 deletions src/system/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::config::Config;
use crate::error::FetchInfoError;
use crate::filtered_values;
use crate::system::{InfoField, InfoGroup, InfoResult, InfoValue};
use crate::util::ToOptionString;
use crate::util::format_time;
use crate::util::{ToOptionString, format_time};
use starship_battery::units::time::second;

pub fn get_battery(
Expand Down
3 changes: 1 addition & 2 deletions src/system/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::error::FetchInfoError;
use crate::filtered_values;
use crate::system::disks::ignore_disk;
use crate::system::{InfoField, InfoGroup, InfoResult, InfoValue};
use crate::util::ToOptionString;
use crate::util::convert_to_readable_unity;
use crate::util::{ToOptionString, convert_to_readable_unity};
use sysinfo::Disks;

pub fn get_disk(
Expand Down
Loading
Loading