refactor: replace custom isatty implementation with is-terminal crate
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::common::is_binary::is_binary;
|
|||||||
use clap::Command;
|
use clap::Command;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use is_terminal::IsTerminal;
|
||||||
|
|
||||||
pub fn mode_get(
|
pub fn mode_get(
|
||||||
cmd: &mut Command,
|
cmd: &mut Command,
|
||||||
@@ -46,7 +47,7 @@ pub fn mode_get(
|
|||||||
item_path.push(item_id.to_string());
|
item_path.push(item_id.to_string());
|
||||||
|
|
||||||
// Determine if we should detect binary data
|
// Determine if we should detect binary data
|
||||||
let mut detect_binary = !args.options.force && is_stdout_tty();
|
let mut detect_binary = !args.options.force && std::io::stdout().is_terminal();
|
||||||
|
|
||||||
// If we're detecting binary and there's binary metadata, check it
|
// If we're detecting binary and there's binary metadata, check it
|
||||||
if detect_binary {
|
if detect_binary {
|
||||||
@@ -94,21 +95,3 @@ pub fn mode_get(
|
|||||||
Err(anyhow!("Unable to find matching item in database"))
|
Err(anyhow!("Unable to find matching item in database"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_stdout_tty() -> bool {
|
|
||||||
#[cfg(unix)]
|
|
||||||
unsafe {
|
|
||||||
libc::isatty(libc::STDOUT_FILENO) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
unsafe {
|
|
||||||
let stdout_handle = winapi::um::processenv::GetStdHandle(winapi::um::winbase::STD_OUTPUT_HANDLE);
|
|
||||||
let mut console_mode: winapi::shared::minwindef::DWORD = 0;
|
|
||||||
winapi::um::consoleapi::GetConsoleMode(stdout_handle, &mut console_mode) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback for non-unix platforms or if we can't determine
|
|
||||||
#[cfg(not(any(unix, windows)))]
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user