1#[cfg(not(windows))]
5pub const fn start() {}
6
7#[cfg(windows)]
9pub fn start() {
10 start_windows();
11}
12
13#[cfg(windows)]
14#[expect(
15 unsafe_code,
16 reason = "configuring the Windows console codepage requires a Win32 API call"
17)]
18fn start_windows() {
19 use windows_sys::Win32::System::Console::SetConsoleOutputCP;
20 let result = unsafe { SetConsoleOutputCP(65_001) };
22 if result == 0 {
23 tracing::warn!("failed to configure Windows console output as UTF-8");
24 }
25}
26
27#[must_use]
29pub fn stdout_is_tty() -> bool {
30 use std::io::IsTerminal;
31 std::io::stdout().is_terminal()
32}
33
34#[must_use]
36pub fn stderr_is_tty() -> bool {
37 use std::io::IsTerminal;
38 std::io::stderr().is_terminal()
39}
40
41#[must_use]
43pub fn user_accepts_ansi_color() -> bool {
44 if std::env::var_os("NO_COLOR").is_some() {
45 return false;
46 }
47 std::env::var("CLICOLOR").as_deref() != Ok("0")
48}