const NO_WORKAROUNDS: &str = "DELTA_NO_WORKAROUNDS";
#[cfg(target_os = "windows")]
pub fn windows_msys2_width_fix(height_width: (u16, u16), term_stdout: &console::Term) -> usize {
fn guess_real_width(current_width: u16, term_stdout: &console::Term) -> Option<u16> {
use std::process::{Command, Stdio};
let term_var = std::env::var("TERM").ok()?;
if term_var.starts_with("xterm")
&& term_stdout.is_term()
&& term_stdout.features().is_msys_tty()
{
if std::env::var(NO_WORKAROUNDS).is_ok() {
return Some(current_width);
}
let pseudo_term = "/dev/fd/2";
let result = Command::new("stty")
.stderr(Stdio::inherit())
.arg("-F")
.arg(pseudo_term)
.arg("size")
.output()
.ok()?;
if result.status.success() {
let size = std::str::from_utf8(&result.stdout).ok()?;
let mut it = size.split_whitespace();
let _height = it.next()?;
return it.next().map(|width| width.parse().ok())?;
}
}
None
}
let (height, width) = height_width;
match (height, width) {
(24..=25, 79..=80) => guess_real_width(width, term_stdout).unwrap_or(width),
_ => width,
}
.into()
}
#[cfg(not(target_os = "windows"))]
pub fn windows_msys2_width_fix(height_width: (u16, u16), _: &console::Term) -> usize {
let _ = NO_WORKAROUNDS;
height_width.1.into()
}