Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8981ee4

Browse files
committed
Auto merge ofrust-lang#125570 - tesuji:stdout-handle, r=Nilstrieb
Use STD_OUTPUT_HANDLE instead of magic number
2 parents4014081 +8a6d10d commit8981ee4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

‎test/src/term/win.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type WORD = u16;
2222
typeDWORD =u32;
2323
typeBOOL =i32;
2424
typeHANDLE =*mutu8;
25+
// https://docs.microsoft.com/en-us/windows/console/getstdhandle
26+
constSTD_OUTPUT_HANDLE:DWORD = -11as_;
2527

2628
#[allow(non_snake_case)]
2729
#[repr(C)]
@@ -99,16 +101,13 @@ impl<T: Write + Send + 'static> WinConsole<T> {
99101
accum |=color_to_bits(self.background) <<4;
100102

101103
unsafe{
102-
// Magic -11 means stdout, from
103-
// https://docs.microsoft.com/en-us/windows/console/getstdhandle
104-
//
105104
// You may be wondering, "but what about stderr?", and the answer
106105
// to that is that setting terminal attributes on the stdout
107106
// handle also sets them for stderr, since they go to the same
108107
// terminal! Admittedly, this is fragile, since stderr could be
109108
// redirected to a different console. This is good enough for
110109
// rustc though. See #13400.
111-
let out =GetStdHandle(-11i32asDWORD);
110+
let out =GetStdHandle(STD_OUTPUT_HANDLE);
112111
SetConsoleTextAttribute(out, accum);
113112
}
114113
}
@@ -120,9 +119,8 @@ impl<T: Write + Send + 'static> WinConsole<T> {
120119
let bg;
121120
unsafe{
122121
letmut buffer_info =MaybeUninit::<CONSOLE_SCREEN_BUFFER_INFO>::uninit();
123-
ifGetConsoleScreenBufferInfo(GetStdHandle(-11i32asDWORD), buffer_info.as_mut_ptr())
124-
!=0
125-
{
122+
let handle =GetStdHandle(STD_OUTPUT_HANDLE);
123+
ifGetConsoleScreenBufferInfo(handle, buffer_info.as_mut_ptr()) !=0{
126124
let buffer_info = buffer_info.assume_init();
127125
fg =bits_to_color(buffer_info.wAttributes);
128126
bg =bits_to_color(buffer_info.wAttributes >>4);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp