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 authored and epage committed Jan 13, 2025
1 parent 8180067 commit 86dca69
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 @@ -11,7 +11,7 @@ mod windows_console {

fn enable_vt(handle: RawHandle) -> std::io::Result<()> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
let handle: HANDLE = handle as HANDLE;
if handle.is_null() {
return Err(std::io::Error::new(
std::io::ErrorKind::BrokenPipe,
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 @@ -129,7 +123,7 @@ mod inner {
handle: RawHandle,
) -> Result<CONSOLE_SCREEN_BUFFER_INFO, IoError> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
let handle: HANDLE = handle as HANDLE;
if handle.is_null() {
return Err(IoError::BrokenPipe);
}
Expand All @@ -150,7 +144,7 @@ mod inner {
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> Result<(), IoError> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
let handle: HANDLE = handle as HANDLE;
if handle.is_null() {
return Err(IoError::BrokenPipe);
}
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 86dca69

Please sign in to comment.