Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
static const uint8_t buffer[]
void ReadFile(uint8_t **data, intptr_t *file_len, void *stream)
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
#define INVALID_HANDLE_VALUE
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
void * HANDLE
unsigned long DWORD