From 9dd8b690a1b680d30660f0441fe49fe9b434ae20 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 28 Jul 2023 15:18:47 +0200 Subject: [PATCH] Do not set the terminal to raw mode if it isn't actually a terminal It doesn't make sense to try to set a terminal as a raw terminal if it isn't actually a terminal. Worse, this may break tests that assume they can simply provide a pipe to a subprocess and expect the terminal will be unchanged. See this PR, which needs this patch: https://github.com/sharkdp/bat/pull/2631 --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 65c7d45..423d055 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ use crossterm::terminal; use std::env; -use std::io::{self, Write}; +use std::io::{self, Write, IsTerminal}; use std::time::{Duration, Instant}; use thiserror::Error; #[cfg(target_os = "windows")] @@ -179,6 +179,10 @@ pub fn theme(timeout: Duration) -> Result { } fn from_xterm(term: Terminal, timeout: Duration) -> Result { + if !std::io::stdout().is_terminal() { + return Err(Error::Unsupported); + } + // Query by XTerm control sequence let query = if term == Terminal::Tmux { "\x1bPtmux;\x1b\x1b]11;?\x07\x1b\\\x03"