on master help sign in
Add and use --style=auto by default
commitccf88fd5d8e767b9306e78ad954cf8cf3d4e3d28 authorsharkdp <davidpeter@web.de> dateThu 10 May 2018, 15:51 (8 years ago) parent6343535
1 file changed+13−4
src/main.rs+13−4
src/main.rs+13−4
@@ -69,6 +69,7 @@ use errors::*;
6969
7070#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
7171pub enum OutputComponent {
72+ Auto,
7273 Changes,
7374 Grid,
7475 Header,
@@ -78,8 +79,13 @@ pub enum OutputComponent {
7879}
7980
8081impl OutputComponent {
81− fn components(&self) -> &'static [OutputComponent] {
82+ fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
8283 match *self {
84+ OutputComponent::Auto => if interactive_terminal {
85+ OutputComponent::Full.components(interactive_terminal)
86+ } else {
87+ OutputComponent::Plain.components(interactive_terminal)
88+ },
8389 OutputComponent::Changes => &[OutputComponent::Changes],
8490 OutputComponent::Grid => &[OutputComponent::Grid],
8591 OutputComponent::Header => &[OutputComponent::Header],
@@ -100,6 +106,7 @@ impl FromStr for OutputComponent {
100106
101107 fn from_str(s: &str) -> Result<Self> {
102108 match s {
109+ "auto" => Ok(OutputComponent::Auto),
103110 "changes" => Ok(OutputComponent::Changes),
104111 "grid" => Ok(OutputComponent::Grid),
105112 "header" => Ok(OutputComponent::Header),
@@ -330,8 +337,10 @@ fn run() -> Result<()> {
330337 .long("style")
331338 .use_delimiter(true)
332339 .takes_value(true)
333− .possible_values(&["full", "plain", "changes", "header", "grid", "numbers"])
334− .default_value("full")
340+ .possible_values(&[
341+ "auto", "full", "plain", "changes", "header", "grid", "numbers",
342+ ])
343+ .default_value("auto")
335344 .help("Additional info to display along with content"),
336345 )
337346 .arg(
@@ -421,7 +430,7 @@ fn run() -> Result<()> {
421430
422431 let output_components = values_t!(app_matches.values_of("style"), OutputComponent)?
423432 .into_iter()
424− .map(|style| style.components())
433+ .map(|style| style.components(interactive_terminal))
425434 .fold(HashSet::new(), |mut acc, components| {
426435 acc.extend(components.iter().cloned());
427436 acc