summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-10-25 23:26:46 +0200
committerDan Davison <dandavison7@gmail.com>2021-10-25 18:29:43 -0400
commit3e82c125cc848b287fb1c05dd1cb4ca43cd65fab (patch)
treeb13796e9833464126c7d3072fcc5e35781483f33 /src
parenta8cd648929b46f485f30ea3709707ca615710747 (diff)
Remember if stdout is to an interactive terminal
Adapted `set_widths` because that's where there's a Term instance already.
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs1
-rw-r--r--src/options/set.rs10
2 files changed, 7 insertions, 4 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 12db6e2a..81fa228b 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -706,6 +706,7 @@ pub struct Opt {
#[derive(Default, Clone, Debug)]
pub struct ComputedValues {
pub available_terminal_width: usize,
+ pub stdout_is_term: bool,
pub background_color_extends_to_terminal_width: bool,
pub decorations_width: Width,
pub inspect_raw_lines: InspectRawLines,
diff --git a/src/options/set.rs b/src/options/set.rs
index c8a700e2..65691841 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -202,7 +202,7 @@ pub fn set_options(
);
// Setting ComputedValues
- set_widths(opt);
+ set_widths_and_isatty(opt);
set_true_color(opt);
theme::set__is_light_mode__syntax_theme__syntax_set(opt, assets);
opt.computed.inspect_raw_lines =
@@ -568,11 +568,13 @@ fn parse_width_specifier(width_arg: &str, terminal_width: usize) -> Result<usize
Ok(width)
}
-fn set_widths(opt: &mut cli::Opt) {
+fn set_widths_and_isatty(opt: &mut cli::Opt) {
+ let term_stdout = Term::stdout();
+ opt.computed.stdout_is_term = term_stdout.is_term();
+
// If one extra character for e.g. `less --status-column` is required use "-1"
// as an argument, also see #41, #10, #115 and #727.
-
- opt.computed.available_terminal_width = Term::stdout().size().1 as usize;
+ opt.computed.available_terminal_width = term_stdout.size().1 as usize;
let (decorations_width, background_color_extends_to_terminal_width) = match opt.width.as_deref()
{