fix(client): enable ANSI processing explicitly for admin/elevated terminals
This commit is contained in:
parent
e0edf60461
commit
72cf15a6e3
2 changed files with 21 additions and 0 deletions
|
|
@ -36,4 +36,5 @@ windows = { version = "0.54", features = [
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
"Win32_UI_Shell",
|
"Win32_UI_Shell",
|
||||||
|
"Win32_System_Console",
|
||||||
] }
|
] }
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,22 @@ fn is_admin() -> bool {
|
||||||
unsafe { IsUserAnAdmin().as_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 {
|
macro_rules! log_status {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
println!(" {} {}", "→".cyan().bold(), format!($($arg)*));
|
println!(" {} {}", "→".cyan().bold(), format!($($arg)*));
|
||||||
|
|
@ -144,6 +160,10 @@ fn prompt_config() -> Config {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
// Enable ANSI color codes on Windows (required when running as admin)
|
||||||
|
#[cfg(windows)]
|
||||||
|
enable_ansi();
|
||||||
|
|
||||||
// Suppress tracing output by default
|
// Suppress tracing output by default
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
unsafe { std::env::set_var("RUST_LOG", "off"); }
|
unsafe { std::env::set_var("RUST_LOG", "off"); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue