diff --git a/Cargo.toml b/Cargo.toml index 0c5159e..6aaada4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ pre-release-replacements = [ async-std = "1.9.0" crossterm = "0.19" thiserror = "1" +is-terminal = "0.4.9" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["wincon", "winbase", "processenv", "impl-default"] } diff --git a/src/lib.rs b/src/lib.rs index 65c7d45..233dfe5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ use crossterm::terminal; +use is_terminal::IsTerminal; use std::env; use std::io::{self, Write}; use std::time::{Duration, Instant}; @@ -179,6 +180,14 @@ pub fn theme(timeout: Duration) -> Result { } fn from_xterm(term: Terminal, timeout: Duration) -> Result { + if !std::io::stdin().is_terminal() + || !std::io::stdout().is_terminal() + || !std::io::stderr().is_terminal() + { + // Not a terminal, so don't try to read the current background color. + return Err(Error::Unsupported); + } + // Query by XTerm control sequence let query = if term == Terminal::Tmux { "\x1bPtmux;\x1b\x1b]11;?\x07\x1b\\\x03"