Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: runtime/bin/stdio_win.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/stdio.h" 8 #include "bin/stdio.h"
9 9
10
11 namespace dart { 10 namespace dart {
12 namespace bin { 11 namespace bin {
13 12
14 int Stdin::ReadByte() { 13 int Stdin::ReadByte() {
15 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 14 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
16 uint8_t buffer[1]; 15 uint8_t buffer[1];
17 DWORD read = 0; 16 DWORD read = 0;
18 int c = -1; 17 int c = -1;
19 if (ReadFile(h, buffer, 1, &read, NULL) && read == 1) { 18 if (ReadFile(h, buffer, 1, &read, NULL) && (read == 1)) {
20 c = buffer[0]; 19 c = buffer[0];
21 } 20 }
22 return c; 21 return c;
23 } 22 }
24 23
25 24
26 bool Stdin::GetEchoMode() { 25 bool Stdin::GetEchoMode() {
27 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 26 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
28 DWORD mode; 27 DWORD mode;
29 if (!GetConsoleMode(h, &mode)) return false; 28 if (!GetConsoleMode(h, &mode)) {
30 return (mode & ENABLE_ECHO_INPUT) != 0; 29 return false;
30 }
31 return ((mode & ENABLE_ECHO_INPUT) != 0);
31 } 32 }
32 33
33 34
34 void Stdin::SetEchoMode(bool enabled) { 35 void Stdin::SetEchoMode(bool enabled) {
35 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 36 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
36 DWORD mode; 37 DWORD mode;
37 if (!GetConsoleMode(h, &mode)) return; 38 if (!GetConsoleMode(h, &mode)) {
39 return;
40 }
38 if (enabled) { 41 if (enabled) {
39 mode |= ENABLE_ECHO_INPUT; 42 mode |= ENABLE_ECHO_INPUT;
40 } else { 43 } else {
41 mode &= ~ENABLE_ECHO_INPUT; 44 mode &= ~ENABLE_ECHO_INPUT;
42 } 45 }
43 SetConsoleMode(h, mode); 46 SetConsoleMode(h, mode);
44 } 47 }
45 48
46 49
47 bool Stdin::GetLineMode() { 50 bool Stdin::GetLineMode() {
48 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 51 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
49 DWORD mode; 52 DWORD mode;
50 if (!GetConsoleMode(h, &mode)) return false; 53 if (!GetConsoleMode(h, &mode)) {
54 return false;
55 }
51 return (mode & ENABLE_LINE_INPUT) != 0; 56 return (mode & ENABLE_LINE_INPUT) != 0;
52 } 57 }
53 58
54 59
55 void Stdin::SetLineMode(bool enabled) { 60 void Stdin::SetLineMode(bool enabled) {
56 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 61 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
57 DWORD mode; 62 DWORD mode;
58 if (!GetConsoleMode(h, &mode)) return; 63 if (!GetConsoleMode(h, &mode)) {
64 return;
65 }
59 if (enabled) { 66 if (enabled) {
60 mode |= ENABLE_LINE_INPUT; 67 mode |= ENABLE_LINE_INPUT;
61 } else { 68 } else {
62 mode &= ~ENABLE_LINE_INPUT; 69 mode &= ~ENABLE_LINE_INPUT;
63 } 70 }
64 SetConsoleMode(h, mode); 71 SetConsoleMode(h, mode);
65 } 72 }
66 73
67 74
68 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { 75 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
69 HANDLE h; 76 HANDLE h;
70 if (fd == 1) { 77 if (fd == 1) {
71 h = GetStdHandle(STD_OUTPUT_HANDLE); 78 h = GetStdHandle(STD_OUTPUT_HANDLE);
72 } else { 79 } else {
73 h = GetStdHandle(STD_ERROR_HANDLE); 80 h = GetStdHandle(STD_ERROR_HANDLE);
74 } 81 }
75 CONSOLE_SCREEN_BUFFER_INFO info; 82 CONSOLE_SCREEN_BUFFER_INFO info;
76 if (!GetConsoleScreenBufferInfo(h, &info)) return false; 83 if (!GetConsoleScreenBufferInfo(h, &info)) {
84 return false;
85 }
77 size[0] = info.srWindow.Right - info.srWindow.Left + 1; 86 size[0] = info.srWindow.Right - info.srWindow.Left + 1;
78 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1; 87 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1;
79 return true; 88 return true;
80 } 89 }
81 90
82 } // namespace bin 91 } // namespace bin
83 } // namespace dart 92 } // namespace dart
84 93
85 #endif // defined(TARGET_OS_WINDOWS) 94 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698