Skip to content

Commit

Permalink
Don't emit ANSI codes to Windows terminals that don't support them (#403
Browse files Browse the repository at this point in the history
)

These codes *could* be supported on all Windows terminals, but
dart-lang/sdk#28614 means that they won't actually be recognized.

Partially addresses #395
  • Loading branch information
nex3 committed Jul 10, 2018
1 parent 3269632 commit df7c103
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.9.1

* Don't emit ANSI codes to Windows terminals that don't support them.

## 1.9.0

### Node API
Expand Down
5 changes: 3 additions & 2 deletions lib/src/executable/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ class ExecutableOptions {
bool get indented => _ifParsed('indented') as bool;

/// Whether to use ANSI terminal colors.
bool get color =>
_options.wasParsed('color') ? _options['color'] as bool : hasTerminal;
bool get color => _options.wasParsed('color')
? _options['color'] as bool
: supportsAnsiEscapes;

/// Whether to silence normal output.
bool get quiet => _options['quiet'] as bool;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/io/interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ bool get hasTerminal => false;
/// Whether we're running as Node.JS.
bool get isNode => false;

/// Whether this process is connected to a terminal that supports ANSI escape
/// sequences.
bool get supportsAnsiEscapes => false;

/// The current working directory.
String get currentPath => null;

Expand Down
3 changes: 3 additions & 0 deletions lib/src/io/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ bool get isWindows => _process.platform == 'win32';

bool get isNode => true;

// Node seems to support ANSI escapes on all terminals.
bool get supportsAnsiEscapes => hasTerminal;

String get currentPath => _process.cwd();

@JS("process.stdout.isTTY")
Expand Down
9 changes: 9 additions & 0 deletions lib/src/io/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ bool get hasTerminal => io.stdout.hasTerminal;

bool get isNode => false;

bool get supportsAnsiEscapes {
if (!hasTerminal) return false;

// We don't trust [io.stdout.supportsAnsiEscapes] except on Windows because it
// relies on the TERM environment variable which has many false negatives.
if (!isWindows) return true;
return io.stdout.supportsAnsiEscapes;
}

String get currentPath => io.Directory.current.path;

String readFile(String path) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.9.0
version: 1.9.1-dev
description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass
Expand Down

0 comments on commit df7c103

Please sign in to comment.