diff --git a/Cargo.lock b/Cargo.lock index 1ab916f..9160111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,6 +186,7 @@ dependencies = [ "assert_cli 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "terminal_size 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -265,6 +266,14 @@ name = "libc" version = "0.2.66" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lscolors" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memoffset" version = "0.5.3" @@ -560,6 +569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3dbf0a8f61baee43a2918ff50ac6a2d3b2c105bc08ed53bc298779f1263409" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea3b3414b2d015c4fd689815f2551797f3c2296bb241dd709c7da233ec7cba4b" "checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" "checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" diff --git a/Cargo.toml b/Cargo.toml index 37d2227..24936c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ path = "src/main.rs" ansi_term = "=0.12" clap = "=2.33" jwalk = "0.4.0" +lscolors = "0.6.0" num_cpus = "1.12" terminal_size = "0.1.10" unicode-width = "0.1.7" diff --git a/README.md b/README.md index b6d227e..5894efb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Dust -du + rust = dust. Like du but more intuitive +du + rust = dust. Like du but more intuitive. # Why @@ -14,21 +14,21 @@ Because I want an easy way to see where my disk is being used. ## Install -#### Cargo Install +#### Cargo -* cargo install du-dust +* `cargo install du-dust` -#### Download Install +#### Download -* Download linux / mac binary from [Releases](https://github.com/bootandy/dust/releases) -* unzip file: tar -xvf _downloaded_file.tar.gz_ -* move file to executable path: sudo mv dust /usr/local/bin/ +* Download Linux/Mac binary from [Releases](https://github.com/bootandy/dust/releases) +* unzip file: `tar -xvf _downloaded_file.tar.gz` +* move file to executable path: `sudo mv dust /usr/local/bin/` ## Overview -Dust is meant to give you an instant overview of which directories are using disk space without requiring sort or head. Dust will print a maximum of 1 'Did not have permissions message'. +Dust is meant to give you an instant overview of which directories are using disk space without requiring sort or head. Dust will print a maximum of one 'Did not have permissions message'. -Dust will list a slightly-less-than-the-terminal-height number of the biggest sub directories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest sub directory will have its size shown in *red* +Dust will list a slightly-less-than-the-terminal-height number of the biggest subdirectories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest subdirectories will be colored. ## Usage @@ -38,12 +38,12 @@ Usage: dust Usage: dust Usage: dust -p (full-path - does not shorten the path of the subdirectories) Usage: dust -s (apparent-size - shows the length of the file as opposed to the amount of disk space it uses) -Usage: dust -n 30 (Shows 30 directories not the default) -Usage: dust -d 3 (Shows 3 levels of subdirectories) -Usage: dust -r (Reverse order of output, with root at the lowest) -Usage: dust -x (Only show directories on same filesystem) -Usage: dust -X ignore (Ignore all files and directories with the name 'ignore') -Usage: dust -b (Do not show percentages or draw the ASCII bars) +Usage: dust -n 30 (shows 30 directories instead of the default) +Usage: dust -d 3 (shows 3 levels of subdirectories) +Usage: dust -r (reverse order of output, with root at the lowest) +Usage: dust -x (only show directories on the same filesystem) +Usage: dust -X ignore (ignore all files and directories with the name 'ignore') +Usage: dust -b (do not show percentages or draw ASCII bars) ``` diff --git a/src/display.rs b/src/display.rs index 56d4606..4390491 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,8 +1,9 @@ extern crate ansi_term; -use self::ansi_term::Colour::Fixed; use crate::utils::Node; +use lscolors::{LsColors, Style}; + use terminal_size::{terminal_size, Height, Width}; use unicode_width::UnicodeWidthStr; @@ -287,7 +288,12 @@ pub fn format_string( }; let pretty_size = if is_biggest && display_data.colors_on { - format!("{}", Fixed(196).paint(pretty_size)) + let lscolors = LsColors::from_env().unwrap_or_default(); + let directory_color = lscolors.style_for_indicator(lscolors::Indicator::Directory); + let ansi_style = directory_color + .map(Style::to_ansi_term_style) + .unwrap_or_default(); + format!("{}", ansi_style.paint(pretty_size)) } else { pretty_size };