From 5883e4e198cfcf7a21b890e654213c2c382ad16a Mon Sep 17 00:00:00 2001 From: Krisztian Barta Date: Tue, 14 Jul 2026 12:50:52 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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' },