7308e58c3f
Previously we would compile in implementaitions of native calls for IO functions that would never be used. This CL provides implementations that throw a Dart exception if they're called by mistake. It also uses a DART_IO_DISABLED preprocessor define to clean up the build files and check that we're not including code we shouldn't. R=iposva@google.com, johnmccutchan@google.com Review URL: https://codereview.chromium.org/1839463002 .
99 lines
2.0 KiB
C++
99 lines
2.0 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.
|
|
|
|
#if !defined(DART_IO_DISABLED)
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(TARGET_OS_WINDOWS)
|
|
|
|
#include "bin/stdio.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;
|
|
}
|
|
|
|
|
|
bool Stdin::GetEchoMode() {
|
|
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
|
DWORD mode;
|
|
if (!GetConsoleMode(h, &mode)) {
|
|
return false;
|
|
}
|
|
return ((mode & ENABLE_ECHO_INPUT) != 0);
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
bool Stdin::GetLineMode() {
|
|
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
|
DWORD mode;
|
|
if (!GetConsoleMode(h, &mode)) {
|
|
return false;
|
|
}
|
|
return (mode & ENABLE_LINE_INPUT) != 0;
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
|
|
HANDLE h;
|
|
if (fd == 1) {
|
|
h = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
} else {
|
|
h = GetStdHandle(STD_ERROR_HANDLE);
|
|
}
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
if (!GetConsoleScreenBufferInfo(h, &info)) {
|
|
return false;
|
|
}
|
|
size[0] = info.srWindow.Right - info.srWindow.Left + 1;
|
|
size[1] = info.srWindow.Bottom - info.srWindow.Top + 1;
|
|
return true;
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(TARGET_OS_WINDOWS)
|
|
|
|
#endif // !defined(DART_IO_DISABLED)
|