Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs::File;
use std::io::{self, Write};
use std::io::{self, IsTerminal, Write};
use std::sync::mpsc;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -49,6 +49,10 @@ fn event_drain_timeout(drained: usize) -> Option<Duration> {
}
}

fn should_probe_keyboard_enhancement(output_to_stdout: bool, stdin_is_terminal: bool) -> bool {
!output_to_stdout && stdin_is_terminal
}

fn main() -> anyhow::Result<()> {
profile::init_from_env();

Expand Down Expand Up @@ -78,10 +82,13 @@ fn main() -> anyhow::Result<()> {
// Check keyboard enhancement support before enabling raw mode.
// Skip when --stdout is used because the probe writes escape sequences to stdout,
// which would leak into the captured export output.
let keyboard_enhancement_supported = if cli_args.output_to_stdout {
false
} else {
let keyboard_enhancement_supported = if should_probe_keyboard_enhancement(
cli_args.output_to_stdout,
io::stdin().is_terminal(),
) {
matches!(supports_keyboard_enhancement(), Ok(true))
} else {
false
};

// --path implies --working-tree unless -r is explicitly provided
Expand Down Expand Up @@ -974,4 +981,11 @@ mod tests {
"a capped burst must repaint instead of draining forever"
);
}

#[test]
fn keyboard_enhancement_probe_requires_interactive_stdin() {
assert!(should_probe_keyboard_enhancement(false, true));
assert!(!should_probe_keyboard_enhancement(false, false));
assert!(!should_probe_keyboard_enhancement(true, true));
}
}
Loading