fix(client): enable ANSI processing explicitly for admin/elevated terminals

This commit is contained in:
Helios Agent 2026-03-03 15:49:55 +01:00
parent e0edf60461
commit 72cf15a6e3
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
2 changed files with 21 additions and 0 deletions

View file

@ -36,4 +36,5 @@ windows = { version = "0.54", features = [
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
"Win32_UI_Shell",
"Win32_System_Console",
] }

View file

@ -43,6 +43,22 @@ fn is_admin() -> bool {
unsafe { IsUserAnAdmin().as_bool() }
}
#[cfg(windows)]
fn enable_ansi() {
use windows::Win32::System::Console::{
GetConsoleMode, GetStdHandle, SetConsoleMode,
ENABLE_VIRTUAL_TERMINAL_PROCESSING, STD_OUTPUT_HANDLE,
};
unsafe {
if let Ok(handle) = GetStdHandle(STD_OUTPUT_HANDLE) {
let mut mode = Default::default();
if GetConsoleMode(handle, &mut mode).is_ok() {
let _ = SetConsoleMode(handle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
}
}
}
macro_rules! log_status {
($($arg:tt)*) => {
println!(" {} {}", "".cyan().bold(), format!($($arg)*));
@ -144,6 +160,10 @@ fn prompt_config() -> Config {
#[tokio::main]
async fn main() {
// Enable ANSI color codes on Windows (required when running as admin)
#[cfg(windows)]
enable_ansi();
// Suppress tracing output by default
if std::env::var("RUST_LOG").is_err() {
unsafe { std::env::set_var("RUST_LOG", "off"); }