Skip to content

Commit

Permalink
Merge branch 'rivy-fix.win'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 7, 2020
2 parents becae48 + 82d005b commit edd0d74
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 58 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 5 additions & 7 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 0 additions & 33 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> {
kind: Color,
color: C,
}

impl Color {
pub(crate) fn display<C>(self, color: C) -> DisplayColor<C> {
DisplayColor { kind: self, color }
}
}

impl<C> fmt::Display for DisplayColor<C>
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 {
Expand All @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions src/crossdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
pub fn init(_path: &Path) -> io::Result<u64> {
Ok(0)
}
3 changes: 1 addition & 2 deletions src/interactive/app_test/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -175,7 +175,6 @@ pub fn initialized_app_and_terminal_with_closure<P: AsRef<Path>>(
byte_format: ByteFormat::Metric,
apparent_size: true,
count_hard_links: false,
color: Color::None,
sorting: TraversalSorting::AlphabeticalByFileName,
cross_filesystems: false,
},
Expand Down
19 changes: 9 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions tests/snapshots/failure-interactive-without-tty
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
Error: Interactive mode requires a connected terminal

Caused by:
Inappropriate ioctl for device (os error 25)
Error: Interactive mode requires a connected terminal

0 comments on commit edd0d74

Please sign in to comment.