Flutter Engine
The Flutter Engine
stdio_macos.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_MACOS)
7
8#include "bin/stdio.h"
9
10#include <errno.h> // NOLINT
11#include <sys/ioctl.h> // NOLINT
12#include <termios.h> // NOLINT
13
14#include "bin/fdutils.h"
16
17namespace dart {
18namespace bin {
19
20bool Stdin::ReadByte(intptr_t fd, int* byte) {
21 unsigned char b;
22 ssize_t s = TEMP_FAILURE_RETRY(read(fd, &b, 1));
23 if (s < 0) {
24 return false;
25 }
26 *byte = (s == 0) ? -1 : b;
27 return true;
28}
29
30bool Stdin::GetEchoMode(intptr_t fd, bool* enabled) {
31 struct termios term;
32 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
33 if (status != 0) {
34 return false;
35 }
36 *enabled = ((term.c_lflag & ECHO) != 0);
37 return true;
38}
39
40bool Stdin::SetEchoMode(intptr_t fd, bool enabled) {
41 struct termios term;
42 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
43 if (status != 0) {
44 return false;
45 }
46 if (enabled) {
47 term.c_lflag |= ECHO;
48 } else {
49 term.c_lflag &= ~(ECHO);
50 }
51 status = NO_RETRY_EXPECTED(tcsetattr(fd, TCSANOW, &term));
52 return (status == 0);
53}
54
55bool Stdin::GetEchoNewlineMode(intptr_t fd, bool* enabled) {
56 struct termios term;
57 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
58 if (status != 0) {
59 return false;
60 }
61 *enabled = ((term.c_lflag & ECHONL) != 0);
62 return true;
63}
64
65bool Stdin::SetEchoNewlineMode(intptr_t fd, bool enabled) {
66 struct termios term;
67 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
68 if (status != 0) {
69 return false;
70 }
71 if (enabled) {
72 term.c_lflag |= ECHONL;
73 } else {
74 term.c_lflag &= ~(ECHONL);
75 }
76 status = NO_RETRY_EXPECTED(tcsetattr(fd, TCSANOW, &term));
77 return (status == 0);
78}
79
80bool Stdin::GetLineMode(intptr_t fd, bool* enabled) {
81 struct termios term;
82 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
83 if (status != 0) {
84 return false;
85 }
86 *enabled = ((term.c_lflag & ICANON) != 0);
87 return true;
88}
89
90bool Stdin::SetLineMode(intptr_t fd, bool enabled) {
91 struct termios term;
92 int status = NO_RETRY_EXPECTED(tcgetattr(fd, &term));
93 if (status != 0) {
94 return false;
95 }
96 if (enabled) {
97 term.c_lflag |= ICANON;
98 } else {
99 term.c_lflag &= ~(ICANON);
100 }
101 status = NO_RETRY_EXPECTED(tcsetattr(fd, TCSANOW, &term));
102 return (status == 0);
103}
104
105static bool TermIsKnownToSupportAnsi() {
106 const char* term = getenv("TERM");
107 if (term == nullptr) {
108 return false;
109 }
110
111 return strstr(term, "xterm") != nullptr ||
112 strstr(term, "screen") != nullptr || strstr(term, "rxvt") != nullptr;
113}
114
115bool Stdin::AnsiSupported(intptr_t fd, bool* supported) {
116 *supported = isatty(fd) && TermIsKnownToSupportAnsi();
117 return true;
118}
119
120bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
121 struct winsize w;
122 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
123 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
124 size[0] = w.ws_col;
125 size[1] = w.ws_row;
126 return true;
127 }
128 return false;
129}
130
131bool Stdout::AnsiSupported(intptr_t fd, bool* supported) {
132 *supported = isatty(fd) && TermIsKnownToSupportAnsi();
133 return true;
134}
135
136} // namespace bin
137} // namespace dart
138
139#endif // defined(DART_HOST_OS_MACOS)
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)
static bool b
struct MyStruct s
Definition: dart_vm.cc:33
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 w
#define NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)