Skip to content

Commit 1027056

Browse files
committed
fixup commandio init
1 parent 5001ce6 commit 1027056

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/bin/ion/commands/inspect.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use clap::builder::ValueParser;
1313
use clap::{Arg, ArgAction, ArgMatches, Command};
1414
use ion_rs::v1_0::{EncodedBinaryValue, RawValueRef};
1515
use ion_rs::*;
16-
use termcolor::{Color, ColorChoice, ColorSpec, WriteColor};
16+
use termcolor::{Color, ColorSpec, WriteColor};
1717

1818
pub struct InspectCommand;
1919

@@ -107,14 +107,7 @@ impl IonCliCommand for InspectCommand {
107107
}
108108

109109
fn run(&self, _command_path: &mut Vec<String>, args: &ArgMatches) -> Result<()> {
110-
use std::io::IsTerminal;
111-
let pre_pager_stdout = std::io::stdout().is_terminal();
112-
113-
// We have to compensate for the way Pager changes tty detection
114-
let mut command_io = CommandIo::new(args)?;
115-
if command_io.color == ColorChoice::Auto && !pre_pager_stdout {
116-
command_io.color = ColorChoice::Never
117-
}
110+
let mut command_io = CommandIo::new(args)?; // must initialize *before* initializing pager
118111

119112
// On macOS and Linux, the `inspect` command's output will automatically be rerouted to a paging
120113
// utility like `less` when STDOUT is a TTY.

src/bin/ion/commands/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ impl CommandIo<'_> {
292292
ColorChoice::Never
293293
} else if *color {
294294
ColorChoice::Always
295-
} else if *monochrome {
295+
} else if !std::io::stdout().is_terminal() || *monochrome {
296+
// We disable color if stdout is not a terminal or if explicitly disabled by the user
296297
ColorChoice::Never
297298
} else {
298299
ColorChoice::Auto

0 commit comments

Comments
 (0)