Skip to content

Fix unicode terminal detection windows #2933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,14 @@ String _urlDecode(String encoded) =>
/// Set to `true` if ANSI colors should be output regardless of terminalD
bool forceColors = false;

/// Whether "special" strings such as Unicode characters or color escapes are
/// safe to use.
/// Whether ansi codes such as color escapes are safe to use.
///
/// On Windows or when not printing to a terminal, only printable ASCII
/// characters should be used.
/// On a terminal we can use ansi codes also on Windows.
///
/// Tests should make sure to run the subprocess with or without an attached
/// terminal to decide if colors will be provided.
bool get canUseAnsiCodes =>
forceColors ||
(stdioType(stdout) == StdioType.terminal && stdout.supportsAnsiEscapes);
forceColors || (stdout.hasTerminal && stdout.supportsAnsiEscapes);

/// Gets an ANSI escape if those are supported by stdout (or nothing).
String getAnsi(String ansiCode) => canUseAnsiCodes ? ansiCode : '';
Expand All @@ -418,7 +415,7 @@ bool get canUseUnicode =>
// The tests support unicode also on windows.
runningFromTest ||
// When not outputting to terminal we can also use unicode.
stdioType(stdout) != StdioType.terminal ||
!stdout.hasTerminal ||
!Platform.isWindows ||
Platform.environment.containsKey('WT_SESSION');

Expand Down