From c9c3455e23321212b0ece0ba49d5e412beef06db Mon Sep 17 00:00:00 2001 From: KOVACS Krisztian Date: Tue, 2 Feb 2021 20:58:18 +0100 Subject: [PATCH] fix(windows): fix windows terminal ANSI escape sequences (#2258) * fix(windows): don't inherit stdin when executing commands On Windows, inheriting stdin from starship might lead to leaking the console reference to the command we're executing. `id.exe` supplied with Git has been observed to disable the ENABLE_VIRTUAL_TERMINAL_PROCESSING console flag if it inherits stdin -- leading to Windows Terminal not processing ANSI escape sequences. This change fixes #2254 by explicitly disabling stdin inheritance. The fix was suggested by David Knaack. * fix(username): don't call `id -u` on Windows This was done to check if user is root by comparing the UID to 0. Windows does not have a concept of UID 0 anyway, so it's pointless to call `id.exe` (which is installed with MSYS2 or Git, for example). --- src/modules/username.rs | 8 ++++++-- src/utils.rs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/username.rs b/src/modules/username.rs index 36f88385..7fbd9e6e 100644 --- a/src/modules/username.rs +++ b/src/modules/username.rs @@ -21,10 +21,14 @@ pub fn module<'a>(context: &'a Context) -> Option> { let username = context.get_env(USERNAME_ENV_VAR)?; let logname = context.get_env("LOGNAME"); - let user_uid = get_uid(); + let is_root = if cfg!(not(target_os = "windows")) { + let user_uid = get_uid(); + user_uid == ROOT_UID + } else { + false + }; let is_not_login = logname.is_some() && username != logname.unwrap(); - let is_root = user_uid == ROOT_UID; let mut module = context.new_module("username"); let config: UsernameConfig = UsernameConfig::try_load(module.config); diff --git a/src/utils.rs b/src/utils.rs index 2ab34a88..6d561222 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -277,6 +277,7 @@ fn internal_exec_cmd(cmd: &str, args: &[&str]) -> Option { .args(args) .stderr(Stdio::piped()) .stdout(Stdio::piped()) + .stdin(Stdio::null()) .spawn() { Ok(process) => process,