Fix HAS_WORKING_TTY_TIMESTAMPS in rust

Like the WSL check, this was incorrectly assuming WSL implies
cfg(windows) when it's actually picked up as Linux.

Also, improve over the C++ code by not relying on the build-time WSL
status to determine if we are running on WSL at runtime since it's often
the case that the fish binaries are built on a non-WSL host (for
packaging) then executed on a WSL only at runtime.

(But it's ok to assume if fish has been built for Windows or not Linux
that it will either be run or not run on top of a Win32 character device
system.)

Also, port of the comment and relevant WSL and fish issue links over
from the CPP codebase for posterity.
This commit is contained in:
Mahmoud Al-Qudsi 2023-04-26 16:05:24 -05:00
parent 67124dfb11
commit 85d8f2b27f

View file

@ -995,12 +995,19 @@ pub static PROFILING_ACTIVE: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
/// Name of the current program. Should be set at startup. Used by the debug function.
pub static mut PROGRAM_NAME: Lazy<&'static wstr> = Lazy::new(|| L!(""));
#[cfg(windows)]
/// Set to false if it's been determined we can't trust the last modified timestamp on the tty.
pub const HAS_WORKING_TTY_TIMESTAMPS: bool = false;
#[cfg(not(windows))]
/// Set to false if it's been determined we can't trust the last modified timestamp on the tty.
pub const HAS_WORKING_TTY_TIMESTAMPS: bool = true;
/// MS Windows tty devices do not currently have either a read or write timestamp - those respective
/// fields of `struct stat` are always set to the current time, which means we can't rely on them.
/// In this case, we assume no external program has written to the terminal behind our back, making
/// the multiline prompt usable. See #2859 and https://github.com/Microsoft/BashOnWindows/issues/545
pub fn has_working_tty_timestamps() -> bool {
if cfg!(target_os = "windows") {
false
} else if cfg!(target_os = "linux") {
!is_windows_subsystem_for_linux()
} else {
true
}
}
/// A global, empty string. This is useful for functions which wish to return a reference to an
/// empty string.
@ -1639,7 +1646,7 @@ pub fn is_windows_subsystem_for_linux() -> bool {
let build: Result<u32, _> = std::str::from_utf8(&release).unwrap().parse();
match build {
Ok(17763..) => return true,
Ok(_) => (), // handled below
Ok(_) => (), // return true, but first warn (see below)
_ => return false, // if parsing fails, assume this isn't WSL
};