OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 main() { | 9 testStdout(Stdout s) { |
10 try { | 10 try { |
11 Platform.ansiSupported; | 11 s.ansiSupported; |
12 } catch (e, s) { | 12 } catch (e, st) { |
13 Expect.fail("Platform.ansiSupported threw: $e\n$s\n"); | 13 Expect.fail("$s.ansiSupported threw: $e\n$st\n"); |
14 } | 14 } |
15 Expect.isNotNull(Platform.ansiSupported); | 15 Expect.isNotNull(s.ansiSupported); |
16 Expect.isTrue(Platform.ansiSupported is bool); | 16 Expect.isTrue(s.ansiSupported is bool); |
17 if (stdout.hasTerminal && Platform.ansiSupported) { | 17 if (s.ansiSupported) { |
18 stdout.writeln('\x1b[31mThis text has a red foreground using SGR.31.'); | 18 s.writeln('\x1b[31mThis text has a red foreground using SGR.31.'); |
19 stdout.writeln('\x1b[39mThis text has restored the foreground color.'); | 19 s.writeln('\x1b[39mThis text has restored the foreground color.'); |
20 } else { | 20 } else { |
21 stdout.writeln('ANSI codes not supported on this platform'); | 21 s.writeln('ANSI codes not supported on this platform'); |
22 } | 22 } |
23 } | 23 } |
| 24 |
| 25 main() { |
| 26 testStdout(stdout); |
| 27 testStdout(stderr); |
| 28 try { |
| 29 stdin.ansiSupported; |
| 30 } catch (e, st) { |
| 31 Expect.fail("stdin.ansiSupported threw: $e\n$st\n"); |
| 32 } |
| 33 Expect.isNotNull(stdin.ansiSupported); |
| 34 Expect.isTrue(stdin.ansiSupported is bool); |
| 35 } |
OLD | NEW |