Chromium Code Reviews| 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 | |
| 12 | |
| 13 namespace dart { | |
| 14 namespace bin { | |
| 15 | |
| 16 int Stdin::ReadByte() { | |
| 17 int c = getchar(); | |
| 18 if (c == EOF) { | |
| 19 c = -1; | |
| 20 } | |
| 21 return c; | |
| 22 } | |
| 23 | |
| 24 | |
| 25 void Stdin::setEchoMode(bool enabled) { | |
| 26 struct termios term; | |
| 27 tcgetattr(fileno(stdin), &term); | |
| 28 if (enabled) { | |
| 29 term.c_lflag |= ECHO; | |
| 30 } else { | |
| 31 term.c_lflag &= ~(ECHO|ECHONL); | |
|
Søren Gjesse
2013/07/24 12:18:49
Why is ECHONL not turned on above - is it turned o
Anders Johnsen
2013/07/24 12:57:49
Done.
| |
| 32 } | |
| 33 tcsetattr(fileno(stdin), TCSANOW, &term); | |
| 34 } | |
| 35 | |
| 36 | |
| 37 void Stdin::setLineMode(bool enabled) { | |
| 38 struct termios term; | |
| 39 tcgetattr(fileno(stdin), &term); | |
| 40 if (enabled) { | |
| 41 term.c_lflag |= ICANON; | |
| 42 } else { | |
| 43 term.c_lflag &= ~(ICANON); | |
| 44 } | |
| 45 tcsetattr(fileno(stdin), TCSANOW, &term); | |
| 46 } | |
| 47 | |
| 48 } // namespace bin | |
| 49 } // namespace dart | |
| 50 | |
| 51 #endif // defined(TARGET_OS_LINUX) | |
| 52 | |
| OLD | NEW |