Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: pkg/front_end/lib/src/fasta/colors.dart

Issue 2757593003: Work around Platform.ansiSupported missing from checked-in dart binary. (Closed)
Patch Set: Address comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
102 try {
103 ansiSupported = Platform.ansiSupported;
104 } on NoSuchMethodError catch (e) {
105 // Ignored: We're running on an older version of the Dart VM which doesn't
106 // implement `ansiSupported`.
107 }
108 if (ansiSupported == false) {
102 if (context.options.verbose) { 109 if (context.options.verbose) {
103 print("Not enabling colors, 'Platform.ansiSupported' is false."); 110 print("Not enabling colors, 'Platform.ansiSupported' is false.");
104 } 111 }
105 return false; 112 return false;
106 } 113 }
107 114
108 if (stdioType(stderr) != StdioType.TERMINAL) { 115 if (stdioType(stderr) != StdioType.TERMINAL) {
109 if (context.options.verbose) { 116 if (context.options.verbose) {
110 print("Not enabling colors, stderr isn't a terminal."); 117 print("Not enabling colors, stderr isn't a terminal.");
111 } 118 }
112 return false; 119 return false;
113 } 120 }
114 121
115 if (stdioType(stdout) != StdioType.TERMINAL) { 122 if (stdioType(stdout) != StdioType.TERMINAL) {
116 if (context.options.verbose) { 123 if (context.options.verbose) {
117 print("Not enabling colors, stdout isn't a terminal."); 124 print("Not enabling colors, stdout isn't a terminal.");
118 } 125 }
119 return false; 126 return false;
120 } 127 }
121 128
122 if (Platform.isWindows) { 129 if (ansiSupported == true && Platform.isWindows) {
123 if (context.options.verbose) { 130 if (context.options.verbose) {
124 print("Enabling colors as OS is Windows."); 131 print("Enabling colors as OS is Windows.");
125 } 132 }
126 return true; 133 return true;
127 } 134 }
128 135
129 // We have to check if the terminal actually supports colors. Currently, 136 // We have to check if the terminal actually supports colors. Currently,
130 // `Platform.ansiSupported` is hard-coded to true on non-Windows platforms. 137 // `Platform.ansiSupported` is hard-coded to true on non-Windows platforms.
131 138
132 // The `-S` option of `tput` allows us to query multiple capabilities at 139 // The `-S` option of `tput` allows us to query multiple capabilities at
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 "${JSON.encode(ALL_CODES)} != ${JSON.encode(allCodes)}."); 174 "${JSON.encode(ALL_CODES)} != ${JSON.encode(allCodes)}.");
168 } 175 }
169 return false; 176 return false;
170 } 177 }
171 178
172 if (context.options.verbose) { 179 if (context.options.verbose) {
173 print("Enabling colors."); 180 print("Enabling colors.");
174 } 181 }
175 return true; 182 return true;
176 } 183 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698