Skip to content

Commit

Permalink
Detect 16m color support on Windows >=10.0.14931 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayla Washburn authored and sindresorhus committed Dec 11, 2017
1 parent 46d2378 commit cf7bd05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ function supportsColor(stream) {
// libuv that enables 256 color output on Windows. Anything earlier and it
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
// release that supports 256 colors.
// release that supports 256 colors. Windows 10 build 14931 is the first release
// that supports 16m/TrueColor.
const osRelease = os.release().split('.');
if (
Number(process.versions.node.split('.')[0]) >= 8 &&
Number(osRelease[0]) >= 10 &&
Number(osRelease[2]) >= 10586
) {
return 2;
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}

return 1;
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,15 @@ test('return level 2 if on Windows 10 build 10586 or later and Node version is >
const result = importFresh('.');
t.is(result.stdout.level, 2);
});

test('return level 3 if on Windows 10 build 14931 or later and Node version is >= 8.0.0', t => {
Object.defineProperty(process, 'platform', {
value: 'win32'
});
Object.defineProperty(process.versions, 'node', {
value: '8.0.0'
});
os.release = () => '10.0.14931';
const result = importFresh('.');
t.is(result.stdout.level, 3);
});

0 comments on commit cf7bd05

Please sign in to comment.