summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Cargo.lock25
-rw-r--r--Cargo.toml2
-rw-r--r--src/aggregate.rs56
-rw-r--r--src/options.rs2
4 files changed, 30 insertions, 55 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 05cf00f..ad6e71a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -101,17 +101,6 @@ dependencies = [
]
[[package]]
-name = "colored"
-version = "2.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
-dependencies = [
- "atty",
- "lazy_static",
- "winapi",
-]
-
-[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -247,13 +236,13 @@ dependencies = [
"atty",
"byte-unit",
"clap",
- "colored",
"crosstermion",
"filesize",
"itertools",
"jwalk",
"num_cpus",
"open",
+ "owo-colors",
"petgraph",
"pretty_assertions",
"sysinfo",
@@ -363,12 +352,6 @@ dependencies = [
]
[[package]]
-name = "lazy_static"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
-
-[[package]]
name = "libc"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -495,6 +478,12 @@ dependencies = [
]
[[package]]
+name = "owo-colors"
+version = "3.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
+
+[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8ba4bed..d0c31d3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,6 @@ itertools = "0.10.0"
num_cpus = "1.10.0"
filesize = "0.2.0"
anyhow = "1.0.31"
-colored = "2.0.0"
trash = { version = "2.1.5", optional = true, default-features = false, features = ["coinit_apartmentthreaded"] }
# 'tui' related
@@ -37,6 +36,7 @@ tui = { version = "0.19.0", optional = true, default-features = false }
tui-react = { version = "0.19.0", optional = true }
open = { version = "3.0", optional = true }
wild = "2.0.4"
+owo-colors = "3.5.0"
[target.'cfg(all(target_os = "macos", target_arch = "aarch64"))'.dependencies]
sysinfo = { version = "0.23.2", default-features = false }
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,