Skip to content

Commit

Permalink
style: fix clippy warnings in cfg(windows) code
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-kruppe committed Jan 11, 2025
1 parent 6e1f38e commit e9c40b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions crates/anstream/src/wincon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions crates/anstyle-query/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn enable_ansi_colors() -> Option<bool> {
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()
Expand Down
3 changes: 2 additions & 1 deletion crates/anstyle-wincon/examples/set-wincon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
16 changes: 5 additions & 11 deletions crates/anstyle-wincon/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StdioColorInnerResult> = 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<StdioColorInnerResult> = 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
Expand Down Expand Up @@ -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)
Expand All @@ -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
{
Expand Down Expand Up @@ -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}");
}
}
}

0 comments on commit e9c40b1

Please sign in to comment.