| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include <termios.h> // NOLINT | 8 #include <termios.h> // NOLINT |
| 9 | 9 |
| 10 #include "bin/stdin.h" | 10 #include "bin/stdin.h" |
| 11 #include "bin/fdutils.h" |
| 11 | 12 |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 namespace bin { | 15 namespace bin { |
| 15 | 16 |
| 16 int Stdin::ReadByte() { | 17 int Stdin::ReadByte() { |
| 18 FDUtils::SetBlocking(fileno(stdin)); |
| 17 int c = getchar(); | 19 int c = getchar(); |
| 18 if (c == EOF) { | 20 if (c == EOF) { |
| 19 c = -1; | 21 c = -1; |
| 20 } | 22 } |
| 23 FDUtils::SetNonBlocking(fileno(stdin)); |
| 21 return c; | 24 return c; |
| 22 } | 25 } |
| 23 | 26 |
| 24 | 27 |
| 25 void Stdin::SetEchoMode(bool enabled) { | 28 void Stdin::SetEchoMode(bool enabled) { |
| 26 struct termios term; | 29 struct termios term; |
| 27 tcgetattr(fileno(stdin), &term); | 30 tcgetattr(fileno(stdin), &term); |
| 28 if (enabled) { | 31 if (enabled) { |
| 29 term.c_lflag |= ECHO|ECHONL; | 32 term.c_lflag |= ECHO|ECHONL; |
| 30 } else { | 33 } else { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 term.c_lflag &= ~(ICANON); | 46 term.c_lflag &= ~(ICANON); |
| 44 } | 47 } |
| 45 tcsetattr(fileno(stdin), TCSANOW, &term); | 48 tcsetattr(fileno(stdin), TCSANOW, &term); |
| 46 } | 49 } |
| 47 | 50 |
| 48 } // namespace bin | 51 } // namespace bin |
| 49 } // namespace dart | 52 } // namespace dart |
| 50 | 53 |
| 51 #endif // defined(TARGET_OS_MACOS) | 54 #endif // defined(TARGET_OS_MACOS) |
| 52 | 55 |
| OLD | NEW |