summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-09-19 08:58:45 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-09-19 08:58:45 +0800
commit946806e7390799807361562b038fb12eeb2ddf11 (patch)
treea084de5aae63f56ddb28ee8d61d63f438466205f /src
parent7fe68ead0222467092f67d49855655faf6d61ee4 (diff)
parenta734efb7e332de6a3bb4911e72463e4f6fc342e1 (diff)
chore: replace `colored` dependency with `owo-colors`.
The latter provide zero-allocation coloring in the terminal and may improve compile times a little.
Diffstat (limited to 'src')
-rw-r--r--src/aggregate.rs56
-rw-r--r--src/options.rs2
2 files changed, 22 insertions, 36 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index 9a2c518..2a4fb01 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -1,8 +1,8 @@
use crate::{crossdev, InodeFilter, WalkOptions, WalkResult};
use anyhow::Result;
-use colored::{Color, Colorize};
use filesize::PathExt;
-use std::{borrow::Cow, io, path::Path};
+use owo_colors::{AnsiColors as Color, OwoColorize};
+use std::{io, path::Path};
use std::{
sync::{
atomic::{AtomicBool, Ordering},
@@ -186,11 +186,7 @@ pub fn aggregate(
}
fn path_color_of(path: impl AsRef<Path>) -> Option<Color> {
- if path.as_ref().is_file() {
- None
- } else {
- Some(Color::Cyan)
- }
+ (!path.as_ref().is_file()).then(|| Color::Cyan)
}
fn output_colored_path(
@@ -199,35 +195,25 @@ fn output_colored_path(
path: impl AsRef<Path>,
num_bytes: u128,
num_errors: u64,
- path_color: Option<colored::Color>,
+ path_color: Option<Color>,
) -> std::result::Result<(), io::Error> {
- writeln!(
- out,
- "{:>byte_column_width$} {}{}",
- options
- .byte_format
- .display(num_bytes)
- .to_string()
- .as_str()
- .green(),
- {
- let path = path.as_ref().display().to_string();
- match path_color {
- Some(color) => path.color(color),
- None => path.normal(),
- }
- },
- if num_errors == 0 {
- Cow::Borrowed("")
- } else {
- Cow::Owned(format!(
- " <{} IO Error{}>",
- num_errors,
- if num_errors > 1 { "s" } else { "" }
- ))
- },
- byte_column_width = options.byte_format.width()
- )
+ let size = options.byte_format.display(num_bytes).to_string();
+ let size = size.green();
+ let size_width = options.byte_format.width();
+ let path = path.as_ref().display();
+
+ let errors = (num_errors != 0)
+ .then(|| {
+ let plural_s = if num_errors > 1 { "s" } else { "" };
+ format!(" <{num_errors} IO Error{plural_s}>")
+ })
+ .unwrap_or_default();
+
+ if let Some(color) = path_color {
+ writeln!(out, "{size:>size_width$} {}{errors}", path.color(color))
+ } else {
+ writeln!(out, "{size:>size_width$} {path}{errors}")
+ }
}
/// Statistics obtained during a filesystem walk
diff --git a/src/options.rs b/src/options.rs
index 2e594a1..727b52a 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,7 +1,7 @@
use dua::ByteFormat as LibraryByteFormat;
use std::path::PathBuf;
-#[derive(PartialEq, Debug, Clone, Copy, clap::ArgEnum)]
+#[derive(PartialEq, Eq, Debug, Clone, Copy, clap::ArgEnum)]
pub enum ByteFormat {
Metric,
Binary,