Skip to content

Commit 08c01ff

Browse files
committed
don’t display broken pipe error messages (see rust-lang/rust#46016)
1 parent e89dd71 commit 08c01ff

File tree

5 files changed

+25
-80
lines changed

5 files changed

+25
-80
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ parts
1919
prime
2020
stage
2121
*.snap
22-
23-
# IntelliJ IDEA files
24-
.idea

man/exa.1.md

-6
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,6 @@ Specifies the number of spaces to print between an icon (see the ‘`--icons`’
224224

225225
Different terminals display icons differently, as they usually take up more than one character width on screen, so there’s no “standard” number of spaces that exa can use to separate an icon from text. One space may place the icon too close to the text, and two spaces may place it too far away. So the choice is left up to the user to configure depending on their terminal emulator.
226226

227-
## `NO_COLOR`
228-
229-
Disables ANSI colour in the output (regardless of its value). Can be overridden by `--color` option.
230-
231-
See `https://no-color.org/` for details.
232-
233227
## `LS_COLORS`, `EXA_COLORS`
234228

235229
Specifies the colour scheme used to highlight files based on their name and kind, as well as highlighting metadata and parts of the UI.

src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ mod theme;
5050
fn main() {
5151
use std::process::exit;
5252

53+
unsafe {
54+
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
55+
}
56+
5357
logger::configure(env::var_os(vars::EXA_DEBUG));
5458

5559
let args: Vec<_> = env::args_os().skip(1).collect();

src/options/theme.rs

+21-68
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::theme::{Options, UseColours, ColourScale, Definitions};
55

66
impl Options {
77
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
8-
let use_colours = UseColours::deduce(matches, vars)?;
8+
let use_colours = UseColours::deduce(matches)?;
99
let colour_scale = ColourScale::deduce(matches)?;
1010

1111
let definitions = if use_colours == UseColours::Never {
@@ -21,15 +21,10 @@ impl Options {
2121

2222

2323
impl UseColours {
24-
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
25-
let default_value = match vars.get(vars::NO_COLOR) {
26-
Some(_) => Self::Never,
27-
None => Self::Automatic,
28-
};
29-
24+
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
3025
let word = match matches.get_where(|f| f.matches(&flags::COLOR) || f.matches(&flags::COLOUR))? {
3126
Some(w) => w,
32-
None => return Ok(default_value),
27+
None => return Ok(Self::Automatic),
3328
};
3429

3530
if word == "always" {
@@ -92,16 +87,6 @@ mod terminal_test {
9287
}
9388
};
9489

95-
($name:ident: $type:ident <- $inputs:expr, $env:expr; $stricts:expr => $result:expr) => {
96-
#[test]
97-
fn $name() {
98-
let env = $env;
99-
for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &env)) {
100-
assert_eq!(result, $result);
101-
}
102-
}
103-
};
104-
10590
($name:ident: $type:ident <- $inputs:expr; $stricts:expr => err $result:expr) => {
10691
#[test]
10792
fn $name() {
@@ -110,39 +95,11 @@ mod terminal_test {
11095
}
11196
}
11297
};
113-
114-
($name:ident: $type:ident <- $inputs:expr, $env:expr; $stricts:expr => err $result:expr) => {
115-
#[test]
116-
fn $name() {
117-
let env = $env;
118-
for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &env)) {
119-
assert_eq!(result.unwrap_err(), $result);
120-
}
121-
}
122-
};
12398
}
12499

125100
struct MockVars {
126101
ls: &'static str,
127102
exa: &'static str,
128-
no_color: &'static str,
129-
}
130-
131-
impl MockVars {
132-
fn empty() -> MockVars {
133-
return MockVars {
134-
ls: "",
135-
exa: "",
136-
no_color: "",
137-
};
138-
}
139-
fn with_no_color() -> MockVars {
140-
return MockVars {
141-
ls: "",
142-
exa: "",
143-
no_color: "true",
144-
};
145-
}
146103
}
147104

148105
// Test impl that just returns the value it has.
@@ -154,9 +111,6 @@ mod terminal_test {
154111
else if name == vars::EXA_COLORS && ! self.exa.is_empty() {
155112
Some(OsString::from(self.exa.clone()))
156113
}
157-
else if name == vars::NO_COLOR && ! self.no_color.is_empty() {
158-
Some(OsString::from(self.no_color.clone()))
159-
}
160114
else {
161115
None
162116
}
@@ -166,33 +120,32 @@ mod terminal_test {
166120

167121

168122
// Default
169-
test!(empty: UseColours <- [], MockVars::empty(); Both => Ok(UseColours::Automatic));
170-
test!(empty_with_no_color: UseColours <- [], MockVars::with_no_color(); Both => Ok(UseColours::Never));
123+
test!(empty: UseColours <- []; Both => Ok(UseColours::Automatic));
171124

172125
// --colour
173-
test!(u_always: UseColours <- ["--colour=always"], MockVars::empty(); Both => Ok(UseColours::Always));
174-
test!(u_auto: UseColours <- ["--colour", "auto"], MockVars::empty(); Both => Ok(UseColours::Automatic));
175-
test!(u_never: UseColours <- ["--colour=never"], MockVars::empty(); Both => Ok(UseColours::Never));
126+
test!(u_always: UseColours <- ["--colour=always"]; Both => Ok(UseColours::Always));
127+
test!(u_auto: UseColours <- ["--colour", "auto"]; Both => Ok(UseColours::Automatic));
128+
test!(u_never: UseColours <- ["--colour=never"]; Both => Ok(UseColours::Never));
176129

177130
// --color
178-
test!(no_u_always: UseColours <- ["--color", "always"], MockVars::empty(); Both => Ok(UseColours::Always));
179-
test!(no_u_auto: UseColours <- ["--color=auto"], MockVars::empty(); Both => Ok(UseColours::Automatic));
180-
test!(no_u_never: UseColours <- ["--color", "never"], MockVars::empty(); Both => Ok(UseColours::Never));
131+
test!(no_u_always: UseColours <- ["--color", "always"]; Both => Ok(UseColours::Always));
132+
test!(no_u_auto: UseColours <- ["--color=auto"]; Both => Ok(UseColours::Automatic));
133+
test!(no_u_never: UseColours <- ["--color", "never"]; Both => Ok(UseColours::Never));
181134

182135
// Errors
183-
test!(no_u_error: UseColours <- ["--color=upstream"], MockVars::empty(); Both => err OptionsError::BadArgument(&flags::COLOR, OsString::from("upstream"))); // the error is for --color
184-
test!(u_error: UseColours <- ["--colour=lovers"], MockVars::empty(); Both => err OptionsError::BadArgument(&flags::COLOR, OsString::from("lovers"))); // and so is this one!
136+
test!(no_u_error: UseColours <- ["--color=upstream"]; Both => err OptionsError::BadArgument(&flags::COLOR, OsString::from("upstream"))); // the error is for --color
137+
test!(u_error: UseColours <- ["--colour=lovers"]; Both => err OptionsError::BadArgument(&flags::COLOR, OsString::from("lovers"))); // and so is this one!
185138

186139
// Overriding
187-
test!(overridden_1: UseColours <- ["--colour=auto", "--colour=never"], MockVars::empty(); Last => Ok(UseColours::Never));
188-
test!(overridden_2: UseColours <- ["--color=auto", "--colour=never"], MockVars::empty(); Last => Ok(UseColours::Never));
189-
test!(overridden_3: UseColours <- ["--colour=auto", "--color=never"], MockVars::empty(); Last => Ok(UseColours::Never));
190-
test!(overridden_4: UseColours <- ["--color=auto", "--color=never"], MockVars::empty(); Last => Ok(UseColours::Never));
191-
192-
test!(overridden_5: UseColours <- ["--colour=auto", "--colour=never"], MockVars::empty(); Complain => err OptionsError::Duplicate(Flag::Long("colour"), Flag::Long("colour")));
193-
test!(overridden_6: UseColours <- ["--color=auto", "--colour=never"], MockVars::empty(); Complain => err OptionsError::Duplicate(Flag::Long("color"), Flag::Long("colour")));
194-
test!(overridden_7: UseColours <- ["--colour=auto", "--color=never"], MockVars::empty(); Complain => err OptionsError::Duplicate(Flag::Long("colour"), Flag::Long("color")));
195-
test!(overridden_8: UseColours <- ["--color=auto", "--color=never"], MockVars::empty(); Complain => err OptionsError::Duplicate(Flag::Long("color"), Flag::Long("color")));
140+
test!(overridden_1: UseColours <- ["--colour=auto", "--colour=never"]; Last => Ok(UseColours::Never));
141+
test!(overridden_2: UseColours <- ["--color=auto", "--colour=never"]; Last => Ok(UseColours::Never));
142+
test!(overridden_3: UseColours <- ["--colour=auto", "--color=never"]; Last => Ok(UseColours::Never));
143+
test!(overridden_4: UseColours <- ["--color=auto", "--color=never"]; Last => Ok(UseColours::Never));
144+
145+
test!(overridden_5: UseColours <- ["--colour=auto", "--colour=never"]; Complain => err OptionsError::Duplicate(Flag::Long("colour"), Flag::Long("colour")));
146+
test!(overridden_6: UseColours <- ["--color=auto", "--colour=never"]; Complain => err OptionsError::Duplicate(Flag::Long("color"), Flag::Long("colour")));
147+
test!(overridden_7: UseColours <- ["--colour=auto", "--color=never"]; Complain => err OptionsError::Duplicate(Flag::Long("colour"), Flag::Long("color")));
148+
test!(overridden_8: UseColours <- ["--color=auto", "--color=never"]; Complain => err OptionsError::Duplicate(Flag::Long("color"), Flag::Long("color")));
196149

197150
test!(scale_1: ColourScale <- ["--color-scale", "--colour-scale"]; Last => Ok(ColourScale::Gradient));
198151
test!(scale_2: ColourScale <- ["--color-scale", ]; Last => Ok(ColourScale::Gradient));

src/options/vars.rs

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pub static COLUMNS: &str = "COLUMNS";
1515
/// Environment variable used to datetime format.
1616
pub static TIME_STYLE: &str = "TIME_STYLE";
1717

18-
/// Environment variable used to disable colors.
19-
/// See: https://no-color.org/
20-
pub static NO_COLOR: &str = "NO_COLOR";
2118

2219
// exa-specific variables
2320

0 commit comments

Comments
 (0)