| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 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 #include "bin/fdutils.h" |
| 12 | 12 |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 namespace bin { | 15 namespace bin { |
| 16 | 16 |
| 17 int Stdin::ReadByte() { | 17 int Stdin::ReadByte() { |
| 18 FDUtils::SetBlocking(fileno(stdin)); | 18 FDUtils::SetBlocking(fileno(stdin)); |
| 19 int c = getchar(); | 19 int c = getchar(); |
| 20 if (c == EOF) { | 20 if (c == EOF) { |
| 21 c = -1; | 21 c = -1; |
| 22 } | 22 } |
| 23 FDUtils::SetNonBlocking(fileno(stdin)); | 23 FDUtils::SetNonBlocking(fileno(stdin)); |
| 24 return c; | 24 return c; |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 bool Stdin::GetEchoMode() { |
| 29 struct termios term; |
| 30 tcgetattr(fileno(stdin), &term); |
| 31 return (term.c_lflag & ECHO) != 0; |
| 32 } |
| 33 |
| 34 |
| 28 void Stdin::SetEchoMode(bool enabled) { | 35 void Stdin::SetEchoMode(bool enabled) { |
| 29 struct termios term; | 36 struct termios term; |
| 30 tcgetattr(fileno(stdin), &term); | 37 tcgetattr(fileno(stdin), &term); |
| 31 if (enabled) { | 38 if (enabled) { |
| 32 term.c_lflag |= ECHO|ECHONL; | 39 term.c_lflag |= ECHO|ECHONL; |
| 33 } else { | 40 } else { |
| 34 term.c_lflag &= ~(ECHO|ECHONL); | 41 term.c_lflag &= ~(ECHO|ECHONL); |
| 35 } | 42 } |
| 36 tcsetattr(fileno(stdin), TCSANOW, &term); | 43 tcsetattr(fileno(stdin), TCSANOW, &term); |
| 37 } | 44 } |
| 38 | 45 |
| 39 | 46 |
| 47 bool Stdin::GetLineMode() { |
| 48 struct termios term; |
| 49 tcgetattr(fileno(stdin), &term); |
| 50 return (term.c_lflag & ICANON) != 0; |
| 51 } |
| 52 |
| 53 |
| 40 void Stdin::SetLineMode(bool enabled) { | 54 void Stdin::SetLineMode(bool enabled) { |
| 41 struct termios term; | 55 struct termios term; |
| 42 tcgetattr(fileno(stdin), &term); | 56 tcgetattr(fileno(stdin), &term); |
| 43 if (enabled) { | 57 if (enabled) { |
| 44 term.c_lflag |= ICANON; | 58 term.c_lflag |= ICANON; |
| 45 } else { | 59 } else { |
| 46 term.c_lflag &= ~(ICANON); | 60 term.c_lflag &= ~(ICANON); |
| 47 } | 61 } |
| 48 tcsetattr(fileno(stdin), TCSANOW, &term); | 62 tcsetattr(fileno(stdin), TCSANOW, &term); |
| 49 } | 63 } |
| 50 | 64 |
| 51 } // namespace bin | 65 } // namespace bin |
| 52 } // namespace dart | 66 } // namespace dart |
| 53 | 67 |
| 54 #endif // defined(TARGET_OS_ANDROID) | 68 #endif // defined(TARGET_OS_ANDROID) |
| 55 | 69 |
| OLD | NEW |