Skip to content
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

fix: addressing some unanticipated situations #142

Merged
merged 10 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 29 additions & 10 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
/* eslint-env browser */

const isBlinkBasedBrowser = navigator.userAgentData
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);

const colorSupport = isBlinkBasedBrowser ? {
level: 1,
hasBasic: true,
has256: false,
has16m: false,
} : false;
function translateLevel(level) {
if (level === 0) {
return false;
}

return {
level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3,
};
}

function check() {
if (navigator.userAgentData) {
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
if (brand && brand.version > 93) {
idranme marked this conversation as resolved.
Show resolved Hide resolved
return 3;
}
}

if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
return 1;
}

return 0;
}

const colorSupport = translateLevel(check());
idranme marked this conversation as resolved.
Show resolved Hide resolved

const supportsColor = {
stdout: colorSupport,
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'node:os';
import tty from 'node:tty';

// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
function hasFlag(flag, argv = process.argv) {
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
Expand Down Expand Up @@ -84,6 +84,10 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return 0;
}

if (env.COLORTERM === 'truecolor') {
return 3;
}
idranme marked this conversation as resolved.
Show resolved Hide resolved

const min = forceColor || 0;

if (env.TERM === 'dumb') {
Expand Down Expand Up @@ -121,10 +125,6 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return 1;
}

if (env.COLORTERM === 'truecolor') {
return 3;
}

if ('TERM_PROGRAM' in env) {
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);

Expand Down