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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(HOST_OS_LINUX) | 8 #if defined(HOST_OS_LINUX) |
9 | 9 |
10 #include "bin/stdio.h" | 10 #include "bin/stdio.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (enabled) { | 76 if (enabled) { |
77 term.c_lflag |= ICANON; | 77 term.c_lflag |= ICANON; |
78 } else { | 78 } else { |
79 term.c_lflag &= ~(ICANON); | 79 term.c_lflag &= ~(ICANON); |
80 } | 80 } |
81 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term)); | 81 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term)); |
82 return (status == 0); | 82 return (status == 0); |
83 } | 83 } |
84 | 84 |
85 | 85 |
| 86 static bool TermHasXTerm() { |
| 87 const char* term = getenv("TERM"); |
| 88 if (term == NULL) { |
| 89 return false; |
| 90 } |
| 91 return strstr(term, "xterm") != NULL; |
| 92 } |
| 93 |
| 94 |
| 95 bool Stdin::AnsiSupported(bool* supported) { |
| 96 *supported = isatty(STDIN_FILENO) && TermHasXTerm(); |
| 97 return true; |
| 98 } |
| 99 |
| 100 |
86 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { | 101 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { |
87 struct winsize w; | 102 struct winsize w; |
88 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w)); | 103 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w)); |
89 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) { | 104 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) { |
90 size[0] = w.ws_col; | 105 size[0] = w.ws_col; |
91 size[1] = w.ws_row; | 106 size[1] = w.ws_row; |
92 return true; | 107 return true; |
93 } | 108 } |
94 return false; | 109 return false; |
95 } | 110 } |
96 | 111 |
| 112 |
| 113 bool Stdout::AnsiSupported(intptr_t fd, bool* supported) { |
| 114 *supported = isatty(fd) && TermHasXTerm(); |
| 115 return true; |
| 116 } |
| 117 |
97 } // namespace bin | 118 } // namespace bin |
98 } // namespace dart | 119 } // namespace dart |
99 | 120 |
100 #endif // defined(HOST_OS_LINUX) | 121 #endif // defined(HOST_OS_LINUX) |
101 | 122 |
102 #endif // !defined(DART_IO_DISABLED) | 123 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |