4b4f0307ba
BUG=https://code.google.com/p/dart/issues/detail?id=8190,https://code.google.com/p/dart/issues/detail?id=9825,https://code.google.com/p/dart/issues/detail?id=11659 R=sgjesse@google.com Review URL: https://codereview.chromium.org//19627004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25413 260f80e4-7a28-3924-810f-c04153c831b5
55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(TARGET_OS_WINDOWS)
|
|
|
|
#include "bin/stdin.h"
|
|
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
int Stdin::ReadByte() {
|
|
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
|
uint8_t buffer[1];
|
|
DWORD read = 0;
|
|
int c = -1;
|
|
if (ReadFile(h, buffer, 1, &read, NULL) && read == 1) {
|
|
c = buffer[0];
|
|
}
|
|
return c;
|
|
}
|
|
|
|
|
|
void Stdin::SetEchoMode(bool enabled) {
|
|
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
|
DWORD mode;
|
|
if (!GetConsoleMode(h, &mode)) return;
|
|
if (enabled) {
|
|
mode |= ENABLE_ECHO_INPUT;
|
|
} else {
|
|
mode &= ~ENABLE_ECHO_INPUT;
|
|
}
|
|
SetConsoleMode(h, mode);
|
|
}
|
|
|
|
|
|
void Stdin::SetLineMode(bool enabled) {
|
|
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
|
DWORD mode;
|
|
if (!GetConsoleMode(h, &mode)) return;
|
|
if (enabled) {
|
|
mode |= ENABLE_LINE_INPUT;
|
|
} else {
|
|
mode &= ~ENABLE_LINE_INPUT;
|
|
}
|
|
SetConsoleMode(h, mode);
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(TARGET_OS_WINDOWS)
|