Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // TODO(ahe): Orignially copied from sdk/pkg/compiler/lib/src/colors.dart, | 5 // TODO(ahe): Orignially copied from sdk/pkg/compiler/lib/src/colors.dart, |
| 6 // merge these two packages. | 6 // merge these two packages. |
| 7 library colors; | 7 library colors; |
| 8 | 8 |
| 9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 String white(String string) => wrap(string, WHITE_COLOR); | 91 String white(String string) => wrap(string, WHITE_COLOR); |
| 92 | 92 |
| 93 /// True if we should enable colors in output. We enable colors when: | 93 /// True if we should enable colors in output. We enable colors when: |
| 94 /// 1. stdout and stderr are terminals, | 94 /// 1. stdout and stderr are terminals, |
| 95 /// 2. the terminal supports more than 8 colors, and | 95 /// 2. the terminal supports more than 8 colors, and |
| 96 /// 3. the terminal's ANSI color codes matches what we expect. | 96 /// 3. the terminal's ANSI color codes matches what we expect. |
| 97 /// | 97 /// |
| 98 /// Note: do not call this method directly, as it is expensive to | 98 /// Note: do not call this method directly, as it is expensive to |
| 99 /// compute. Instead, use [CompilerContext.enableColors]. | 99 /// compute. Instead, use [CompilerContext.enableColors]. |
| 100 bool computeEnableColors(CompilerContext context) { | 100 bool computeEnableColors(CompilerContext context) { |
| 101 if (!Platform.ansiSupported) { | 101 bool ansiSupported; |
|
karlklose
2017/03/16 13:01:47
Initialize with 'false'?
ahe
2017/03/16 13:11:09
I have to distinguish between three cases:
* We k
| |
| 102 try { | |
| 103 ansiSupported = Platform.ansiSupported; | |
| 104 } catch (e) { | |
|
karlklose
2017/03/16 13:01:47
Could you be more specific about the exception typ
ahe
2017/03/16 13:11:10
Done.
| |
| 105 // Ignored. | |
|
karlklose
2017/03/16 13:01:46
Maybe add something like: 'the getter is not suppo
ahe
2017/03/16 13:11:09
Done.
| |
| 106 } | |
| 107 if (ansiSupported == false) { | |
| 102 if (context.options.verbose) { | 108 if (context.options.verbose) { |
| 103 print("Not enabling colors, 'Platform.ansiSupported' is false."); | 109 print("Not enabling colors, 'Platform.ansiSupported' is false."); |
| 104 } | 110 } |
| 105 return false; | 111 return false; |
| 106 } | 112 } |
| 107 | 113 |
| 108 if (stdioType(stderr) != StdioType.TERMINAL) { | 114 if (stdioType(stderr) != StdioType.TERMINAL) { |
| 109 if (context.options.verbose) { | 115 if (context.options.verbose) { |
| 110 print("Not enabling colors, stderr isn't a terminal."); | 116 print("Not enabling colors, stderr isn't a terminal."); |
| 111 } | 117 } |
| 112 return false; | 118 return false; |
| 113 } | 119 } |
| 114 | 120 |
| 115 if (stdioType(stdout) != StdioType.TERMINAL) { | 121 if (stdioType(stdout) != StdioType.TERMINAL) { |
| 116 if (context.options.verbose) { | 122 if (context.options.verbose) { |
| 117 print("Not enabling colors, stdout isn't a terminal."); | 123 print("Not enabling colors, stdout isn't a terminal."); |
| 118 } | 124 } |
| 119 return false; | 125 return false; |
| 120 } | 126 } |
| 121 | 127 |
| 122 if (Platform.isWindows) { | 128 if (ansiSupported == true && Platform.isWindows) { |
| 123 if (context.options.verbose) { | 129 if (context.options.verbose) { |
| 124 print("Enabling colors as OS is Windows."); | 130 print("Enabling colors as OS is Windows."); |
| 125 } | 131 } |
| 126 return true; | 132 return true; |
| 127 } | 133 } |
| 128 | 134 |
| 129 // We have to check if the terminal actually supports colors. Currently, | 135 // We have to check if the terminal actually supports colors. Currently, |
| 130 // `Platform.ansiSupported` is hard-coded to true on non-Windows platforms. | 136 // `Platform.ansiSupported` is hard-coded to true on non-Windows platforms. |
| 131 | 137 |
| 132 // The `-S` option of `tput` allows us to query multiple capabilities at | 138 // The `-S` option of `tput` allows us to query multiple capabilities at |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 "${JSON.encode(ALL_CODES)} != ${JSON.encode(allCodes)}."); | 173 "${JSON.encode(ALL_CODES)} != ${JSON.encode(allCodes)}."); |
| 168 } | 174 } |
| 169 return false; | 175 return false; |
| 170 } | 176 } |
| 171 | 177 |
| 172 if (context.options.verbose) { | 178 if (context.options.verbose) { |
| 173 print("Enabling colors."); | 179 print("Enabling colors."); |
| 174 } | 180 } |
| 175 return true; | 181 return true; |
| 176 } | 182 } |
| OLD | NEW |