| 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 <errno.h> // NOLINT |
| 9 #include <sys/ioctl.h> // NOLINT |
| 8 #include <termios.h> // NOLINT | 10 #include <termios.h> // NOLINT |
| 9 | 11 |
| 10 #include "bin/stdin.h" | 12 #include "bin/stdio.h" |
| 11 #include "bin/fdutils.h" | 13 #include "bin/fdutils.h" |
| 12 | 14 |
| 13 | 15 |
| 14 namespace dart { | 16 namespace dart { |
| 15 namespace bin { | 17 namespace bin { |
| 16 | 18 |
| 17 int Stdin::ReadByte() { | 19 int Stdin::ReadByte() { |
| 18 FDUtils::SetBlocking(fileno(stdin)); | 20 FDUtils::SetBlocking(STDIN_FILENO); |
| 19 int c = getchar(); | 21 int c = getchar(); |
| 20 if (c == EOF) { | 22 if (c == EOF) { |
| 21 c = -1; | 23 c = -1; |
| 22 } | 24 } |
| 23 FDUtils::SetNonBlocking(fileno(stdin)); | 25 FDUtils::SetNonBlocking(STDIN_FILENO); |
| 24 return c; | 26 return c; |
| 25 } | 27 } |
| 26 | 28 |
| 27 | 29 |
| 28 bool Stdin::GetEchoMode() { | 30 bool Stdin::GetEchoMode() { |
| 29 struct termios term; | 31 struct termios term; |
| 30 tcgetattr(fileno(stdin), &term); | 32 tcgetattr(STDIN_FILENO, &term); |
| 31 return (term.c_lflag & ECHO) != 0; | 33 return (term.c_lflag & ECHO) != 0; |
| 32 } | 34 } |
| 33 | 35 |
| 34 | 36 |
| 35 void Stdin::SetEchoMode(bool enabled) { | 37 void Stdin::SetEchoMode(bool enabled) { |
| 36 struct termios term; | 38 struct termios term; |
| 37 tcgetattr(fileno(stdin), &term); | 39 tcgetattr(STDIN_FILENO, &term); |
| 38 if (enabled) { | 40 if (enabled) { |
| 39 term.c_lflag |= ECHO|ECHONL; | 41 term.c_lflag |= ECHO|ECHONL; |
| 40 } else { | 42 } else { |
| 41 term.c_lflag &= ~(ECHO|ECHONL); | 43 term.c_lflag &= ~(ECHO|ECHONL); |
| 42 } | 44 } |
| 43 tcsetattr(fileno(stdin), TCSANOW, &term); | 45 tcsetattr(STDIN_FILENO, TCSANOW, &term); |
| 44 } | 46 } |
| 45 | 47 |
| 46 | 48 |
| 47 bool Stdin::GetLineMode() { | 49 bool Stdin::GetLineMode() { |
| 48 struct termios term; | 50 struct termios term; |
| 49 tcgetattr(fileno(stdin), &term); | 51 tcgetattr(STDIN_FILENO, &term); |
| 50 return (term.c_lflag & ICANON) != 0; | 52 return (term.c_lflag & ICANON) != 0; |
| 51 } | 53 } |
| 52 | 54 |
| 53 | 55 |
| 54 void Stdin::SetLineMode(bool enabled) { | 56 void Stdin::SetLineMode(bool enabled) { |
| 55 struct termios term; | 57 struct termios term; |
| 56 tcgetattr(fileno(stdin), &term); | 58 tcgetattr(STDIN_FILENO, &term); |
| 57 if (enabled) { | 59 if (enabled) { |
| 58 term.c_lflag |= ICANON; | 60 term.c_lflag |= ICANON; |
| 59 } else { | 61 } else { |
| 60 term.c_lflag &= ~(ICANON); | 62 term.c_lflag &= ~(ICANON); |
| 61 } | 63 } |
| 62 tcsetattr(fileno(stdin), TCSANOW, &term); | 64 tcsetattr(STDIN_FILENO, TCSANOW, &term); |
| 65 } |
| 66 |
| 67 |
| 68 bool Stdout::GetTerminalSize(int size[2]) { |
| 69 struct winsize w; |
| 70 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
| 71 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != 0)) { |
| 72 return false; |
| 73 } |
| 74 size[0] = w.ws_col; |
| 75 size[1] = w.ws_row; |
| 76 return true; |
| 63 } | 77 } |
| 64 | 78 |
| 65 } // namespace bin | 79 } // namespace bin |
| 66 } // namespace dart | 80 } // namespace dart |
| 67 | 81 |
| 68 #endif // defined(TARGET_OS_MACOS) | 82 #endif // defined(TARGET_OS_MACOS) |
| 69 | 83 |
| OLD | NEW |