From 25295e8c74f00979193af9fbd497b30e50354b2c Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Sun, 20 Sep 2026 02:43:03 +0800 Subject: [PATCH 1/3] Standardize path formatting --- src/format.rs | 12 ++++++++++++ src/run.rs | 2 +- src/state.rs | 9 +++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/format.rs b/src/format.rs index c0f37d0..ed780f7 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,4 +1,16 @@ use colored::{ColoredString, Colorize, control::SHOULD_COLORIZE}; +use std::path::Path; + +// This trait formats a filesystem path for human-facing diagnostic output. +pub trait CodePath { + fn code_path(&self) -> ColoredString; +} + +impl CodePath for Path { + fn code_path(&self) -> ColoredString { + self.to_string_lossy().code_str() + } +} // This trait has a function for formatting "code-like" text, such as a file path. The reason it's // implemented as a trait and not just a function is so we can use it with method syntax, as in diff --git a/src/run.rs b/src/run.rs index ab47bd4..31fbaf1 100644 --- a/src/run.rs +++ b/src/run.rs @@ -366,7 +366,7 @@ fn get_disk_by_file<'a>(disks: &'a [Disk], path: &Path) -> io::Result<&'a Disk> .ok_or_else(|| { io::Error::other(format!( "Unable to find disk for path {}.", - path.to_string_lossy().code_str(), + path.code_path(), )) }) } diff --git a/src/state.rs b/src/state.rs index ef30d9e..8e61857 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,4 @@ -use crate::format::CodeStr; +use crate::format::CodePath; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, @@ -57,7 +57,7 @@ pub fn load() -> io::Result { // Log what we are trying to do in case an error occurs. trace!( "Attempting to load the state from {}\u{2026}", - path.to_string_lossy().code_str(), + path.code_path(), ); // Read the YAML from disk. @@ -76,10 +76,7 @@ pub fn save(state: &State) -> io::Result<()> { // Check if we have a path. if let Some(path) = path() { // Log what we're trying to do in case an error occurs. - trace!( - "Persisting the state to {}\u{2026}", - path.to_string_lossy().code_str(), - ); + trace!("Persisting the state to {}\u{2026}", path.code_path()); // The `unwrap` is safe due to [ref:state_path_has_parent]. let parent = path.parent().unwrap().to_owned(); From 46c6753ada1080bbf22b4d4ec96271b55cc62ad6 Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Sun, 20 Sep 2026 02:45:51 +0800 Subject: [PATCH 2/3] Import path formatter on Linux --- src/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.rs b/src/run.rs index 31fbaf1..dfa2bb5 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,6 +1,6 @@ use crate::{ Settings, Threshold, - format::CodeStr, + format::{CodePath, CodeStr}, state::{self, State}, }; use byte_unit::{Byte, UnitType}; From a958a1e9360bbe611214cc15910eafd73500bbe6 Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Sun, 20 Sep 2026 02:48:23 +0800 Subject: [PATCH 3/3] Scope path formatter import to Linux --- src/run.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/run.rs b/src/run.rs index dfa2bb5..5cf17ce 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,8 +1,11 @@ use crate::{ Settings, Threshold, - format::{CodePath, CodeStr}, + format::CodeStr, state::{self, State}, }; + +#[cfg(target_os = "linux")] +use crate::format::CodePath; use byte_unit::{Byte, UnitType}; use chrono::{DateTime, Utc}; use regex::RegexSet;