From 5883e4e198cfcf7a21b890e654213c2c382ad16a Mon Sep 17 00:00:00 2001 From: Krisztian Barta Date: Tue, 14 Jul 2026 12:50:52 +0200 Subject: [PATCH 01/10] fix: disable ANSI colors in history list when stdout is not a TTY" --- package-lock.json | 2 +- src/command/history/list.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2aa3e2f..cb37f536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "3.3.0", + "version": "3.4.0", "license": "BSD-3-Clause", "dependencies": { "@ethereumjs/wallet": "^2.0.4", diff --git a/src/command/history/list.ts b/src/command/history/list.ts index 52297a3d..19ab706a 100644 --- a/src/command/history/list.ts +++ b/src/command/history/list.ts @@ -22,10 +22,14 @@ export class List extends HistoryCommand implements LeafCommand { return } + + const useColors = Boolean(process.stdout.isTTY) + const table = new Table({ head: ['Index', 'Timestamp', 'Reference', 'Postage stamp batch ID', 'File path', 'Upload type'], style: { - head: ['green', 'bold'], + head: useColors ? ['green', 'bold'] : [], + border: useColors ? ["grey"] : [] }, wordWrap: true, }) From c6d57e1ae5c3fb2ce346f880eb1f05b26813583a Mon Sep 17 00:00:00 2001 From: Krisztian Barta Date: Tue, 14 Jul 2026 13:14:57 +0200 Subject: [PATCH 02/10] fix: minor fix --- src/command/history/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/history/list.ts b/src/command/history/list.ts index 19ab706a..3cf6ea9d 100644 --- a/src/command/history/list.ts +++ b/src/command/history/list.ts @@ -29,7 +29,7 @@ export class List extends HistoryCommand implements LeafCommand { head: ['Index', 'Timestamp', 'Reference', 'Postage stamp batch ID', 'File path', 'Upload type'], style: { head: useColors ? ['green', 'bold'] : [], - border: useColors ? ["grey"] : [] + border: useColors ? ['grey'] : [] }, wordWrap: true, }) From ccdf3881ac1185e0ad0aaaf02f79186fef0110d5 Mon Sep 17 00:00:00 2001 From: Krisztian Barta Date: Tue, 14 Jul 2026 13:20:13 +0200 Subject: [PATCH 03/10] fix: minor fix --- src/command/history/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/history/list.ts b/src/command/history/list.ts index 3cf6ea9d..0a3881e2 100644 --- a/src/command/history/list.ts +++ b/src/command/history/list.ts @@ -29,7 +29,7 @@ export class List extends HistoryCommand implements LeafCommand { head: ['Index', 'Timestamp', 'Reference', 'Postage stamp batch ID', 'File path', 'Upload type'], style: { head: useColors ? ['green', 'bold'] : [], - border: useColors ? ['grey'] : [] + border: useColors ? ['grey'] : [], }, wordWrap: true, }) From 7241cdf23b9db7536806d9a84c1a6ac1ad880720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Mon, 3 Aug 2026 10:23:20 +0200 Subject: [PATCH 04/10] feat: adding test for ansii colors --- test/command/history.spec.ts | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index 4e52f433..079c1443 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -2,6 +2,9 @@ import chalk from 'chalk' import { randomUUID } from 'crypto' import { describeCommand, invokeTestCli } from '../utility' import { getStampOption } from '../utility/stamp' +import colors from '@colors/colors/safe' + +const ANSI_PATTERN = /\u001B\[\d+m/ //adding this for testing the ansi disable part async function uploadTestFile() { const uploadFilePath = `${__dirname}/../testpage/images/swarm.png` @@ -10,7 +13,7 @@ async function uploadTestFile() { describeCommand( 'Test History command', - ({ consoleMessages }) => { + ({ consoleMessages }) => { describe('list', () => { it('should have table header row', async () => { await invokeTestCli(['history', 'enable']) @@ -124,6 +127,42 @@ describeCommand( await invokeTestCli(['history', 'disable', '--yes']) }) }) + + describe('ansi: list colors', () =>{ + const originalIsTTY = process.stdout.isTTY + const colorsWereEnabled = colors.enabled + + beforeAll(() => { + colors.enable() + }) + + afterAll(() => { + if(!colorsWereEnabled) { + colors.disable() + } + }) + + afterEach(() => { + process.stdout.isTTY = originalIsTTY + invokeTestCli(['history', 'disable', '--yes']) + }) + + it('should not use colors when stdout is not a TTY', async () => { + await invokeTestCli(['history', 'enable']) + process.stdout.isTTY = false + await invokeTestCli(['history', 'list']) + + expect(consoleMessages[1]).not.toMatch(ANSI_PATTERN) + expect(consoleMessages[1]).toContain('Timestamp') + }) + + it('should use colors when stdout is a TTY', async () => { + await invokeTestCli(['history', 'enable']) + process.stdout.isTTY = true + await invokeTestCli(['history', 'list']) + + expect(consoleMessages[1]).toMatch(ANSI_PATTERN) }) + }) }, { configFileName: 'history' }, ) From cc5f15a3519193496bee273b85bd59c1f9e2f741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Mon, 3 Aug 2026 10:27:36 +0200 Subject: [PATCH 05/10] feat: minor fix --- test/command/history.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index 079c1443..d5fba4d8 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -13,7 +13,7 @@ async function uploadTestFile() { describeCommand( 'Test History command', - ({ consoleMessages }) => { + ({ consoleMessages }) => { describe('list', () => { it('should have table header row', async () => { await invokeTestCli(['history', 'enable']) @@ -128,7 +128,7 @@ describeCommand( }) }) - describe('ansi: list colors', () =>{ + describe('ansi: list colors', () => { const originalIsTTY = process.stdout.isTTY const colorsWereEnabled = colors.enabled @@ -137,7 +137,7 @@ describeCommand( }) afterAll(() => { - if(!colorsWereEnabled) { + if (!colorsWereEnabled) { colors.disable() } }) @@ -161,7 +161,8 @@ describeCommand( process.stdout.isTTY = true await invokeTestCli(['history', 'list']) - expect(consoleMessages[1]).toMatch(ANSI_PATTERN) }) + expect(consoleMessages[1]).toMatch(ANSI_PATTERN) + }) }) }, { configFileName: 'history' }, From 4175946ab2e45169fdb345bb8ccb6c29e0736da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Fri, 14 Aug 2026 11:02:02 +0200 Subject: [PATCH 06/10] feat: ansipattern move to its block --- test/command/history.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index d5fba4d8..6a839873 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -4,8 +4,6 @@ import { describeCommand, invokeTestCli } from '../utility' import { getStampOption } from '../utility/stamp' import colors from '@colors/colors/safe' -const ANSI_PATTERN = /\u001B\[\d+m/ //adding this for testing the ansi disable part - async function uploadTestFile() { const uploadFilePath = `${__dirname}/../testpage/images/swarm.png` await invokeTestCli(['upload', uploadFilePath, ...getStampOption()]) @@ -131,6 +129,8 @@ describeCommand( describe('ansi: list colors', () => { const originalIsTTY = process.stdout.isTTY const colorsWereEnabled = colors.enabled + const ANSI_PATTERN = /\u001B\[\d+m/ //adding this for testing the ansi disable part + beforeAll(() => { colors.enable() From 97386b24f18e5efb2d21bb27a476f708f66fb59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Fri, 14 Aug 2026 11:11:31 +0200 Subject: [PATCH 07/10] feat: minor fix --- test/command/history.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index 6a839873..0390886c 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -131,7 +131,6 @@ describeCommand( const colorsWereEnabled = colors.enabled const ANSI_PATTERN = /\u001B\[\d+m/ //adding this for testing the ansi disable part - beforeAll(() => { colors.enable() }) From a971dbb576e596aae0ed6695b9c9685b63035aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Fri, 14 Aug 2026 11:19:44 +0200 Subject: [PATCH 08/10] feat: added await for lint check --- test/command/history.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index 0390886c..4a986368 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -143,7 +143,7 @@ describeCommand( afterEach(() => { process.stdout.isTTY = originalIsTTY - invokeTestCli(['history', 'disable', '--yes']) + await invokeTestCli(['history', 'disable', '--yes']) }) it('should not use colors when stdout is not a TTY', async () => { From a50afad5ead06b0d7335411f064806e2480cb889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Fri, 14 Aug 2026 11:22:02 +0200 Subject: [PATCH 09/10] feat: made afterEach asynf function --- test/command/history.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index 4a986368..bad85616 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -141,7 +141,7 @@ describeCommand( } }) - afterEach(() => { + afterEach( async () => { process.stdout.isTTY = originalIsTTY await invokeTestCli(['history', 'disable', '--yes']) }) From e7527277d231ccb8ea9029246d703a8459ffa659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Barta?= Date: Fri, 14 Aug 2026 11:25:12 +0200 Subject: [PATCH 10/10] feat: fixed minor issues with npm run lint:check --- test/command/history.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index bad85616..3a90dacf 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -141,11 +141,10 @@ describeCommand( } }) - afterEach( async () => { + afterEach(async () => { process.stdout.isTTY = originalIsTTY await invokeTestCli(['history', 'disable', '--yes']) }) - it('should not use colors when stdout is not a TTY', async () => { await invokeTestCli(['history', 'enable']) process.stdout.isTTY = false