From 07010f1ebdffbc208eaf166e1ea57071e24ed607 Mon Sep 17 00:00:00 2001 From: biodiscus Date: Thu, 15 Feb 2024 14:30:52 +0100 Subject: [PATCH] feat: add detection of additional terminals --- CHANGELOG.md | 5 ++ README.md | 2 +- package.json | 2 +- pkg/package.json | 2 +- src/color-support.js | 2 +- test/unit.test.js | 115 +++++++++++++++++++++++++++++++++++++------ 6 files changed, 110 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 918ab2c..10205f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/README.md b/README.md index 137f972..41e4f55 100644 --- a/README.md +++ b/README.md @@ -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'; diff --git a/package.json b/package.json index f616473..4a650f7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pkg/package.json b/pkg/package.json index 0a890bc..f69a34e 100644 --- a/pkg/package.json +++ b/pkg/package.json @@ -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", diff --git a/src/color-support.js b/src/color-support.js index be48b0f..83413cb 100644 --- a/src/color-support.js +++ b/src/color-support.js @@ -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); }; diff --git a/test/unit.test.js b/test/unit.test.js index bca4141..f4593de 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -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: { @@ -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`, () => {