Skip to content

Commit 933b254

Browse files
authored
Revert "Handle possible errors in set_virtual_terminal (#105)" (#160)
This reverts commit a9aa7d8.
1 parent 949f601 commit 933b254

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Unreleased
22
- Document crate MSRV of `1.70`.
3-
- Handle errors in `set_virtual_terminal`.
43

54
- Updated top-level docs to include a note about `ColoredString`\'s role in the `Colorize` pipeline as well as link to it to suggest learning more about how to manipulate existing `ColoredString`\'s.
65
- Changes to `ColoredString`:

src/control.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
1010
/// This is primarily used for Windows 10 environments which will not correctly colorize
1111
/// the outputs based on ANSI escape codes.
1212
///
13+
/// The returned `Result` is _always_ `Ok(())`, the return type was kept to ensure backwards
14+
/// compatibility.
15+
///
1316
/// # Notes
1417
/// > Only available to `Windows` build targets.
1518
///
@@ -25,25 +28,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
2528
#[allow(clippy::result_unit_err)]
2629
#[cfg(windows)]
2730
pub fn set_virtual_terminal(use_virtual: bool) -> Result<(), ()> {
28-
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
2931
use windows_sys::Win32::System::Console::{
3032
GetConsoleMode, GetStdHandle, SetConsoleMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING,
3133
STD_OUTPUT_HANDLE,
3234
};
3335

3436
unsafe {
3537
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
36-
if handle == INVALID_HANDLE_VALUE {
37-
return Err(());
38-
}
39-
4038
let mut original_mode = 0;
41-
// Return value of 0 means that the function failed:
42-
// https://learn.microsoft.com/en-us/windows/console/getconsolemode#return-value
43-
if GetConsoleMode(handle, &mut original_mode) == 0 {
44-
// TODO: It would be prudent to get the error using `GetLastError` here.
45-
return Err(());
46-
}
39+
GetConsoleMode(handle, &mut original_mode);
4740

4841
let enabled = original_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING
4942
== ENABLE_VIRTUAL_TERMINAL_PROCESSING;

0 commit comments

Comments
 (0)