Flutter Engine
The Flutter Engine
stdio_win.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_WINDOWS)
7
8#include "bin/stdio.h"
9
10// These are not always defined in the header files. See:
11// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
12#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
13#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
14#endif
15
16#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
17#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
18#endif
19
20namespace dart {
21namespace bin {
22
23bool Stdin::ReadByte(intptr_t fd, int* byte) {
24 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
25 uint8_t buffer[1];
26 DWORD read = 0;
27 BOOL success = ReadFile(h, buffer, 1, &read, nullptr);
28 if (!success && (GetLastError() != ERROR_BROKEN_PIPE)) {
29 return false;
30 }
31 *byte = (read == 1) ? buffer[0] : -1;
32 return true;
33}
34
35bool Stdin::GetEchoMode(intptr_t fd, bool* enabled) {
36 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
37 DWORD mode;
38 if (!GetConsoleMode(h, &mode)) {
39 return false;
40 }
41 *enabled = ((mode & ENABLE_ECHO_INPUT) != 0);
42 return true;
43}
44
45bool Stdin::SetEchoMode(intptr_t fd, bool enabled) {
46 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
47 DWORD mode;
48 if (!GetConsoleMode(h, &mode)) {
49 return false;
50 }
51 if (enabled) {
52 mode |= ENABLE_ECHO_INPUT;
53 } else {
54 mode &= ~ENABLE_ECHO_INPUT;
55 }
56 return SetConsoleMode(h, mode);
57}
58
59bool Stdin::GetEchoNewlineMode(intptr_t fd, bool* enabled) {
60 *enabled = false;
61 return true;
62}
63
64bool Stdin::SetEchoNewlineMode(intptr_t fd, bool enabled) {
65 if (enabled) {
66 SetLastError(ERROR_NOT_CAPABLE);
67 return false;
68 }
69 return true;
70}
71
72bool Stdin::GetLineMode(intptr_t fd, bool* enabled) {
73 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
74 DWORD mode;
75 if (!GetConsoleMode(h, &mode)) {
76 return false;
77 }
78 *enabled = (mode & ENABLE_LINE_INPUT) != 0;
79 return true;
80}
81
82bool Stdin::SetLineMode(intptr_t fd, bool enabled) {
83 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
84 DWORD mode;
85 if (!GetConsoleMode(h, &mode)) {
86 return false;
87 }
88 if (enabled) {
89 mode |= ENABLE_LINE_INPUT;
90 } else {
91 mode &= ~ENABLE_LINE_INPUT;
92 }
93 return SetConsoleMode(h, mode);
94}
95
96bool Stdin::AnsiSupported(intptr_t fd, bool* supported) {
97 ASSERT(supported != nullptr);
98 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
99 if (h == INVALID_HANDLE_VALUE) {
100 *supported = false;
101 return true;
102 }
103 DWORD mode;
104 if (!GetConsoleMode(h, &mode)) {
105 *supported = false;
106 return true;
107 }
108 *supported = (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) != 0;
109 return true;
110}
111
112bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
113 HANDLE h;
114 if (fd == 1) {
115 h = GetStdHandle(STD_OUTPUT_HANDLE);
116 } else {
117 h = GetStdHandle(STD_ERROR_HANDLE);
118 }
119 CONSOLE_SCREEN_BUFFER_INFO info;
120 if (!GetConsoleScreenBufferInfo(h, &info)) {
121 return false;
122 }
123 size[0] = info.srWindow.Right - info.srWindow.Left + 1;
124 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1;
125 return true;
126}
127
128bool Stdout::AnsiSupported(intptr_t fd, bool* supported) {
129 ASSERT(supported != nullptr);
130 HANDLE h;
131 if (fd == 1) {
132 h = GetStdHandle(STD_OUTPUT_HANDLE);
133 } else {
134 h = GetStdHandle(STD_ERROR_HANDLE);
135 }
136 if (h == INVALID_HANDLE_VALUE) {
137 *supported = false;
138 return true;
139 }
140 DWORD mode;
141 if (!GetConsoleMode(h, &mode)) {
142 *supported = false;
143 return true;
144 }
145 *supported = (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0;
146 return true;
147}
148
149} // namespace bin
150} // namespace dart
151
152#endif // defined(DART_HOST_OS_WINDOWS)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static bool read(SkStream *stream, void *buffer, size_t amount)
static bool GetEchoNewlineMode(intptr_t fd, bool *enabled)
static bool GetEchoMode(intptr_t fd, bool *enabled)
static bool SetEchoMode(intptr_t fd, bool enabled)
static bool ReadByte(intptr_t fd, int *byte)
static bool AnsiSupported(intptr_t fd, bool *supported)
static bool SetLineMode(intptr_t fd, bool enabled)
static bool GetLineMode(intptr_t fd, bool *enabled)
static bool SetEchoNewlineMode(intptr_t fd, bool enabled)
static bool GetTerminalSize(intptr_t fd, int size[2])
static bool AnsiSupported(intptr_t fd, bool *supported)
#define ASSERT(E)
void ReadFile(uint8_t **data, intptr_t *file_len, void *stream)
Definition: dart_vm.cc:33
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkScalar h
int BOOL
Definition: windows_types.h:37
#define INVALID_HANDLE_VALUE
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
void * HANDLE
Definition: windows_types.h:36
unsigned long DWORD
Definition: windows_types.h:22