Skip to content

Commit

Permalink
Do not set the terminal to raw mode if it isn't actually a terminal
Browse files Browse the repository at this point in the history
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:
sharkdp/bat#2631
  • Loading branch information
aykevl committed Jul 28, 2023
1 parent e9ca93d commit 1307875
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -179,6 +179,11 @@ pub fn theme(timeout: Duration) -> Result<Theme, Error> {
}

fn from_xterm(term: Terminal, timeout: Duration) -> Result<Rgb, Error> {
if !std::io::stdin().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"
Expand Down

0 comments on commit 1307875

Please sign in to comment.