diff --git a/Cargo.lock b/Cargo.lock index 07191b15..c338bf9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,6 +247,7 @@ dependencies = [ "tui", "tui-react 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation", + "wild", ] [[package]] @@ -295,6 +296,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "heck" version = "0.3.1" @@ -803,6 +810,15 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wild" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "035793abb854745033f01a07647a79831eba29ec0be377205f2a25b0aa830020" +dependencies = [ + "glob", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 9c90834e..dbe21600 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ crosstermion = { optional = true, version = "0.1.3", default-features = false } tui = { version = "0.9.1", optional = true, default-features = false } tui-react = { version = "0.4", optional = true } open = { version = "1.2.2", optional = true } +wild = "2.0.4" [[bin]] name="dua" diff --git a/src/aggregate.rs b/src/aggregate.rs index a754c987..8d16047e 100644 --- a/src/aggregate.rs +++ b/src/aggregate.rs @@ -135,13 +135,11 @@ fn output_colored_path( .to_string() .as_str() .green(), - options.color.display( - path.as_ref() - .display() - .to_string() - .as_str() - .color(path_color.unwrap_or(Color::White)) - ), + path.as_ref() + .display() + .to_string() + .as_str() + .color(path_color.unwrap_or(Color::White)), if num_errors == 0 { Cow::Borrowed("") } else { diff --git a/src/common.rs b/src/common.rs index d297c450..eb1bb03d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -112,38 +112,6 @@ pub enum TraversalSorting { AlphabeticalByFileName, } -/// Specify the kind of color to use -#[derive(Clone, Copy)] -pub enum Color { - /// Use no color - None, - /// Use terminal colors - Terminal, -} - -pub(crate) struct DisplayColor { - kind: Color, - color: C, -} - -impl Color { - pub(crate) fn display(self, color: C) -> DisplayColor { - DisplayColor { kind: self, color } - } -} - -impl fmt::Display for DisplayColor -where - C: fmt::Display, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - match self.kind { - Color::None => Ok(()), - Color::Terminal => self.color.fmt(f), - } - } -} - /// Configures a filesystem walk, including output and formatting options. #[derive(Clone)] pub struct WalkOptions { @@ -153,7 +121,6 @@ pub struct WalkOptions { pub byte_format: ByteFormat, pub count_hard_links: bool, pub apparent_size: bool, - pub color: Color, pub sorting: TraversalSorting, pub cross_filesystems: bool, } diff --git a/src/crossdev.rs b/src/crossdev.rs index 0f68a09b..20dbd957 100644 --- a/src/crossdev.rs +++ b/src/crossdev.rs @@ -15,11 +15,11 @@ pub fn is_same_device(device_id: u64, meta: &std::fs::Metadata) -> bool { } #[cfg(not(unix))] -pub fn is_same_device(device_id: u64, meta: &std::fs::Metadata) -> bool { +pub fn is_same_device(_device_id: u64, _meta: &std::fs::Metadata) -> bool { true } #[cfg(not(unix))] -pub fn init(path: &Path) -> io::Result { +pub fn init(_path: &Path) -> io::Result { Ok(0) } diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs index 3d1bbb59..a42f36b2 100644 --- a/src/interactive/app_test/utils.rs +++ b/src/interactive/app_test/utils.rs @@ -2,7 +2,7 @@ use crate::interactive::{app_test::FIXTURE_PATH, Interaction, TerminalApp}; use anyhow::{Context, Error, Result}; use dua::{ traverse::{EntryData, Tree, TreeIndex}, - ByteFormat, Color, TraversalSorting, WalkOptions, + ByteFormat, TraversalSorting, WalkOptions, }; use itertools::Itertools; use jwalk::{DirEntry, WalkDir}; @@ -175,7 +175,6 @@ pub fn initialized_app_and_terminal_with_closure>( byte_format: ByteFormat::Metric, apparent_size: true, count_hard_links: false, - color: Color::None, sorting: TraversalSorting::AlphabeticalByFileName, cross_filesystems: false, }, diff --git a/src/main.rs b/src/main.rs index a47fc225..4c0edc21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ #![forbid(unsafe_code)] #![allow(clippy::match_bool)] -use anyhow::Result; -use dua::{ByteFormat, Color, TraversalSorting}; +use anyhow::{anyhow, Result}; +use dua::{ByteFormat, TraversalSorting}; use std::{fs, io, io::Write, path::PathBuf, process}; use structopt::StructOpt; +use wild; #[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))] mod interactive; @@ -12,15 +13,10 @@ mod options; fn main() -> Result<()> { use options::Command::*; - let opt: options::Args = options::Args::from_args(); + let opt: options::Args = options::Args::from_iter(wild::args_os()); let walk_options = dua::WalkOptions { threads: opt.threads.unwrap_or(0), byte_format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric), - color: if atty::is(atty::Stream::Stdout) { - Color::Terminal - } else { - Color::None - }, apparent_size: opt.apparent_size, count_hard_links: opt.count_hard_links, sorting: TraversalSorting::None, @@ -32,10 +28,13 @@ fn main() -> Result<()> { use crate::interactive::{Interaction, TerminalApp}; use anyhow::Context; use crosstermion::terminal::{tui::new_terminal, AlternateRawScreen}; + let no_tty_msg = "Interactive mode requires a connected terminal"; + if atty::isnt(atty::Stream::Stdout) { + return Err(anyhow!(no_tty_msg)); + } let mut terminal = new_terminal( - AlternateRawScreen::try_from(io::stdout()) - .with_context(|| "Interactive mode requires a connected terminal")?, + AlternateRawScreen::try_from(io::stdout()).with_context(|| no_tty_msg)?, ) .with_context(|| "Could not instantiate terminal")?; let res = TerminalApp::initialize( diff --git a/tests/snapshots/failure-interactive-without-tty b/tests/snapshots/failure-interactive-without-tty index d5d704b2..741f6a09 100644 --- a/tests/snapshots/failure-interactive-without-tty +++ b/tests/snapshots/failure-interactive-without-tty @@ -1,4 +1 @@ -Error: Interactive mode requires a connected terminal - -Caused by: - Inappropriate ioctl for device (os error 25) \ No newline at end of file +Error: Interactive mode requires a connected terminal \ No newline at end of file