diff --git a/crates/anstream/src/wincon.rs b/crates/anstream/src/wincon.rs index 206e052e..570511dd 100644 --- a/crates/anstream/src/wincon.rs +++ b/crates/anstream/src/wincon.rs @@ -41,6 +41,7 @@ where S: anstyle_wincon::WinconStream, S: IsTerminal, { + /// Returns `true` if the descriptor/handle refers to a terminal/tty. #[inline] pub fn is_terminal(&self) -> bool { self.raw.is_terminal() diff --git a/crates/anstyle-query/src/windows.rs b/crates/anstyle-query/src/windows.rs index 113a8ef0..ea8579f4 100644 --- a/crates/anstyle-query/src/windows.rs +++ b/crates/anstyle-query/src/windows.rs @@ -17,7 +17,7 @@ mod windows_console { "console is detached", )); } - let handle: HANDLE = std::mem::transmute(handle); + let handle: HANDLE = handle as HANDLE; let mut dwmode: CONSOLE_MODE = 0; if windows_sys::Win32::System::Console::GetConsoleMode(handle, &mut dwmode) == 0 { @@ -33,7 +33,7 @@ mod windows_console { } } - pub fn enable_virtual_terminal_processing() -> std::io::Result<()> { + pub(crate) fn enable_virtual_terminal_processing() -> std::io::Result<()> { let stdout = std::io::stdout(); let stdout_handle = stdout.as_raw_handle(); let stderr = std::io::stderr(); @@ -72,7 +72,7 @@ pub fn enable_ansi_colors() -> Option { windows_console::enable_ansi_colors() } -/// Raw ENABLE_VIRTUAL_TERMINAL_PROCESSING on stdout/stderr +/// Raw `ENABLE_VIRTUAL_TERMINAL_PROCESSING` on stdout/stderr #[cfg(windows)] pub fn enable_virtual_terminal_processing() -> std::io::Result<()> { windows_console::enable_virtual_terminal_processing() diff --git a/crates/anstyle-wincon/examples/set-wincon.rs b/crates/anstyle-wincon/examples/set-wincon.rs index 6485a505..14224d9f 100644 --- a/crates/anstyle-wincon/examples/set-wincon.rs +++ b/crates/anstyle-wincon/examples/set-wincon.rs @@ -18,8 +18,9 @@ fn main() -> Result<(), lexopt::Error> { let fg = args.fg.and_then(|c| c.into_ansi()); let bg = args.bg.and_then(|c| c.into_ansi()); - let _ = stdout.write_colored(fg, bg, "".as_bytes()); + let _ = stdout.write_colored(fg, bg, b""); + #[allow(clippy::mem_forget)] std::mem::forget(stdout); Ok(()) diff --git a/crates/anstyle-wincon/src/windows.rs b/crates/anstyle-wincon/src/windows.rs index d446c2bf..ccacebaa 100644 --- a/crates/anstyle-wincon/src/windows.rs +++ b/crates/anstyle-wincon/src/windows.rs @@ -9,19 +9,13 @@ type StdioColorInnerResult = Result<(anstyle::AnsiColor, anstyle::AnsiColor), in /// Cached [`get_colors`] call for [`std::io::stdout`] pub fn stdout_initial_colors() -> StdioColorResult { static INITIAL: std::sync::OnceLock = std::sync::OnceLock::new(); - INITIAL - .get_or_init(|| get_colors_(&std::io::stdout())) - .clone() - .map_err(Into::into) + (*INITIAL.get_or_init(|| get_colors_(&std::io::stdout()))).map_err(Into::into) } /// Cached [`get_colors`] call for [`std::io::stderr`] pub fn stderr_initial_colors() -> StdioColorResult { static INITIAL: std::sync::OnceLock = std::sync::OnceLock::new(); - INITIAL - .get_or_init(|| get_colors_(&std::io::stderr())) - .clone() - .map_err(Into::into) + (*INITIAL.get_or_init(|| get_colors_(&std::io::stderr()))).map_err(Into::into) } /// Apply colors to future writes @@ -132,7 +126,7 @@ mod inner { if handle.is_null() { return Err(IoError::BrokenPipe); } - let handle: HANDLE = std::mem::transmute(handle); + let handle: HANDLE = handle as HANDLE; let mut info: CONSOLE_SCREEN_BUFFER_INFO = std::mem::zeroed(); if windows_sys::Win32::System::Console::GetConsoleScreenBufferInfo(handle, &mut info) @@ -153,7 +147,7 @@ mod inner { if handle.is_null() { return Err(IoError::BrokenPipe); } - let handle: HANDLE = std::mem::transmute(handle); + let handle: HANDLE = handle as HANDLE; if windows_sys::Win32::System::Console::SetConsoleTextAttribute(handle, attributes) != 0 { @@ -258,7 +252,7 @@ mod inner { for expected in COLORS { let nibble = to_nibble(expected); let actual = from_nibble(nibble); - assert_eq!(expected, actual, "Intermediate: {}", nibble); + assert_eq!(expected, actual, "Intermediate: {nibble}"); } } }