Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 0a85ce0

Browse files
authored
Added stdinSupportsAnsi and stdinSupportsAnsi (#9)
1 parent 4f5890d commit 0a85ce0

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 2.0.0
2+
* Added `stdinSupportsAnsi` and `stdinSupportsAnsi`
3+
* Removed `ansiSupported`
4+
15
### 1.1.1
26

37
* Updated `LocalPlatform` to use new `dart.io` API for ansi color support queries

lib/src/interface/local_platform.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io' as io show Platform, stdin;
5+
import 'dart:io' as io show Platform, stdin, stdout;
66

77
import 'platform.dart';
88

@@ -48,5 +48,8 @@ class LocalPlatform extends Platform {
4848
String get version => io.Platform.version;
4949

5050
@override
51-
bool get ansiSupported => io.stdin.supportsAnsiEscapes;
51+
bool get stdinSupportsAnsi => io.stdin.supportsAnsiEscapes;
52+
53+
@override
54+
bool get stdoutSupportsAnsi => io.stdout.supportsAnsiEscapes;
5255
}

lib/src/interface/platform.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ abstract class Platform {
114114
/// whitespace and other version and build details.
115115
String get version;
116116

117-
/// When stdio is connected to a terminal, whether ANSI codes are supported.
118-
///
119-
/// This value is hard-coded to true, except on Windows where only more recent
120-
/// versions of Windows 10 support the codes.
121-
bool get ansiSupported;
117+
/// When stdin is connected to a terminal, whether ANSI codes are supported.
118+
bool get stdinSupportsAnsi;
119+
120+
/// When stdout is connected to a terminal, whether ANSI codes are supported.
121+
bool get stdoutSupportsAnsi;
122122

123123
/// Returns a JSON-encoded representation of this platform.
124124
String toJson() {
@@ -135,7 +135,8 @@ abstract class Platform {
135135
'packageRoot': packageRoot,
136136
'packageConfig': packageConfig,
137137
'version': version,
138-
'ansiSupported': ansiSupported,
138+
'stdinSupportsAnsi': stdinSupportsAnsi,
139+
'stdoutSupportsAnsi': stdoutSupportsAnsi,
139140
});
140141
}
141142
}

lib/src/testing/fake_platform.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class FakePlatform extends Platform {
2525
this.packageRoot,
2626
this.packageConfig,
2727
this.version,
28-
this.ansiSupported,
28+
this.stdinSupportsAnsi,
29+
this.stdoutSupportsAnsi,
2930
});
3031

3132
/// Creates a new [FakePlatform] with properties whose initial values mirror
@@ -44,7 +45,8 @@ class FakePlatform extends Platform {
4445
packageRoot = platform.packageRoot,
4546
packageConfig = platform.packageConfig,
4647
version = platform.version,
47-
ansiSupported = platform.ansiSupported;
48+
stdinSupportsAnsi = platform.stdinSupportsAnsi,
49+
stdoutSupportsAnsi = platform.stdoutSupportsAnsi;
4850

4951
/// Creates a new [FakePlatform] with properties extracted from the encoded
5052
/// JSON string.
@@ -66,7 +68,8 @@ class FakePlatform extends Platform {
6668
packageRoot: map['packageRoot'],
6769
packageConfig: map['packageConfig'],
6870
version: map['version'],
69-
ansiSupported: map['ansiSupported'],
71+
stdinSupportsAnsi: map['stdinSupportsAnsi'],
72+
stdoutSupportsAnsi: map['stdoutSupportsAnsi'],
7073
);
7174
}
7275

@@ -107,5 +110,8 @@ class FakePlatform extends Platform {
107110
String version;
108111

109112
@override
110-
bool ansiSupported;
113+
bool stdinSupportsAnsi;
114+
115+
@override
116+
bool stdoutSupportsAnsi;
111117
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: platform
2-
version: 1.1.1
2+
version: 2.0.0
33
authors:
44
- Todd Volkert <[email protected]>
55
description: A pluggable, mockable platform abstraction for Dart.

0 commit comments

Comments
 (0)