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