Skip to content

Commit

Permalink
feat: add detection of additional terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Feb 15, 2024
1 parent b55d96b commit 07010f1
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 2.3.0 (2024-02-15)

- feat: add detection of additional terminals, thanks @dse, [colors.js:issue #42](https://github.com/DABH/colors.js/issues/42)
- test: add test to detect various terminals

## 2.2.0 (2024-02-03)

- feat: add supports the argument as `number`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ See the features [comparison](https://github.com/webdiscus/ansis#compare) and [b

- Supports both **ESM** and **CommonJS**
- Supports **TypeScript**
- Supports **Deno**, **Next.JS** runtimes
- Supports **Bun**, **Deno**, **Next.JS** runtimes
- [Standard API](#base-colors) compatible with **Chalk**, switch from **Chalk** to **Ansis** without changing your code
```diff
- import chalk from 'chalk';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansis",
"version": "2.2.0",
"version": "2.3.0",
"description": "Colorize text in terminal or console output with ANSI colors & styles",
"keywords": [
"ansi",
Expand Down
2 changes: 1 addition & 1 deletion pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansis",
"version": "2.2.0",
"version": "2.3.0",
"description": "Colorize text in terminal or console output with ANSI colors & styles",
"keywords": [
"ansi",
Expand Down
2 changes: 1 addition & 1 deletion src/color-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const isSupported = (mockThis) => {
const isNextJS = (env.NEXT_RUNTIME || '').indexOf('edge') > -1;

const isTerm = (isTTY || isNextJS) &&
/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM);
/^screen|^tmux|^xterm|^vt[1-5][0-9][0-9]|^ansi|color|cygwin|linux|mintty|rxvt/i.test(env.TERM);

return !isForceDisabled && (isForceEnabled || isTerm || isWin || 'CI' in env);
};
115 changes: 101 additions & 14 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ describe('Node.JS isSupported', () => {
expect(received).toEqual(expected);
});

test(`colors in linux terminal`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'xterm' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`colors on windows platform`, () => {
const received = isSupported({
process: {
Expand Down Expand Up @@ -281,6 +267,107 @@ describe('Node.JS isSupported', () => {
});
});

describe('support colors in terminals', () => {
test(`xterm`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'xterm' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`vt220`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'vt220' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`vt320-w`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'vt320-w' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`vt525`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'vt525' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`tmux`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'tmux' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`mintty-direct`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'mintty-direct' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

test(`ansi.sysk`, () => {
const received = isSupported({
process: {
platform: 'linux',
env: { TERM: 'ansi.sysk' },
argv: [],
stdout: { isTTY: true },
stderr: { isTTY: true },
},
});
const expected = true;
expect(received).toEqual(expected);
});

});

// Deno
describe('Deno isSupported', () => {
test(`env TERM`, () => {
Expand Down

0 comments on commit 07010f1

Please sign in to comment.