Skip to content

Commit a659248

Browse files
authored
Revert "fix: alt values for process.stdout.columns (#131)"
This reverts commit 4956ac8.
1 parent 94d2bf5 commit a659248

File tree

5 files changed

+5
-146
lines changed

5 files changed

+5
-146
lines changed

examples/no-width-table.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
determineConfiguredWidth,
2828
determineWidthOfWrappedText,
2929
getColumns,
30-
getColumnWidth,
3130
getHeadings,
3231
intersperse,
3332
maybeStripAnsi,
@@ -432,7 +431,7 @@ const createStdout = (): FakeStdout => {
432431
// https://github.com/vadimdemedes/ink/blob/v5.0.1/src/ink.tsx#L174
433432
// This might be a bad idea but it works.
434433
stdout.rows = 10_000
435-
stdout.columns = getColumnWidth();
434+
stdout.columns = process.stdout.columns ?? 80
436435
const frames: string[] = []
437436

438437
stdout.write = (data: string) => {
@@ -569,7 +568,8 @@ export function printTables<T extends Record<string, unknown>[]>(
569568
const output = new Output()
570569
const leftMargin = options?.marginLeft ?? options?.margin ?? 0
571570
const rightMargin = options?.marginRight ?? options?.margin ?? 0
572-
const columns = getColumnWidth() - (leftMargin + rightMargin)
571+
const columns = process.stdout.columns - (leftMargin + rightMargin)
572+
573573
const processed = tables.map((table) => ({
574574
...table,
575575
// adjust maxWidth to account for margin and columnGap

src/utils.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ export function determineWidthOfWrappedText(text: string): number {
5151
return lines.reduce((max, line) => Math.max(max, line.length), 0)
5252
}
5353

54-
// In certain systems, `process.stdout.columns` can be 0
55-
// The column width is calculated by:
56-
// 1. The value of `OCLIF_TABLE_COLUMN_OVERRIDE` (if set)
57-
// 2. The value of `process.stdout.columns`
58-
// 3. If `process.stdout.columns` is 0, use 80
59-
export function getColumnWidth(): number {
60-
return Number.parseInt(process.env.OCLIF_TABLE_COLUMN_OVERRIDE || '0', 10) || process.stdout.columns || 80
61-
}
62-
6354
/**
6455
* Determines the configured width based on the provided width value.
6556
* If no width is provided, it returns the width of the current terminal.
@@ -72,7 +63,7 @@ export function getColumnWidth(): number {
7263
*/
7364
export function determineConfiguredWidth(
7465
providedWidth: number | Percentage | undefined,
75-
columns = getColumnWidth(),
66+
columns = process.stdout.columns,
7667
): number {
7768
if (!providedWidth) return columns
7869

test/table.test.tsx

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -718,90 +718,4 @@ describe('printTable compatibility with @oclif/test', () => {
718718
)
719719
expect(stdout).to.equal(expected)
720720
})
721-
722-
it('prints full table with no set width', async () => {
723-
console.log(process.stdout.columns)
724-
const data = [
725-
{name: 'Foo', age: '1'.repeat(60)},
726-
{name: 'Bar', age: '2'.repeat(60)},
727-
]
728-
729-
const expected = `┌──────┬──────────────────────────────────────────────────────────────┐
730-
│ name │ age │
731-
├──────┼──────────────────────────────────────────────────────────────┤
732-
│ Foo │ 111111111111111111111111111111111111111111111111111111111111 │
733-
├──────┼──────────────────────────────────────────────────────────────┤
734-
│ Bar │ 222222222222222222222222222222222222222222222222222222222222 │
735-
└──────┴──────────────────────────────────────────────────────────────┘
736-
737-
`
738-
739-
const {stdout} = await captureOutput(async () =>
740-
printTable({
741-
data,
742-
columns: ['name', 'age'],
743-
}),
744-
)
745-
expect(stdout).to.equal(expected)
746-
})
747-
748-
it('should use width of 80 if process.stdout.columns is 0', async () => {
749-
const backupColumns = process.stdout.columns
750-
process.stdout.columns = 0
751-
const data = [
752-
{name: 'Foo', age: '1'.repeat(100)},
753-
{name: 'Bar', age: '2'.repeat(100)},
754-
]
755-
756-
const expected = `┌──────┬───────────────────────────────────────────────────────────────────────┐
757-
│ name │ age │
758-
├──────┼───────────────────────────────────────────────────────────────────────┤
759-
│ Foo │ 11111111111111111111111111111111111111111111111111111111111111111111… │
760-
├──────┼───────────────────────────────────────────────────────────────────────┤
761-
│ Bar │ 22222222222222222222222222222222222222222222222222222222222222222222… │
762-
└──────┴───────────────────────────────────────────────────────────────────────┘
763-
764-
`
765-
766-
const {stdout} = await captureOutput(async () =>
767-
printTable({
768-
data,
769-
columns: ['name', 'age'],
770-
}),
771-
)
772-
expect(stdout).to.equal(expected)
773-
774-
process.stdout.columns = backupColumns;
775-
})
776-
777-
it('should respect the OCLIF_TABLE_COLUMN_OVERRIDE env var', async () => {
778-
const backupColumns = process.stdout.columns
779-
process.stdout.columns = 0
780-
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = '50'
781-
const data = [
782-
{name: 'Foo', age: '1'.repeat(100)},
783-
{name: 'Bar', age: '2'.repeat(100)},
784-
]
785-
786-
const expected = `┌──────┬─────────────────────────────────────────┐
787-
│ name │ age │
788-
├──────┼─────────────────────────────────────────┤
789-
│ Foo │ 11111111111111111111111111111111111111… │
790-
├──────┼─────────────────────────────────────────┤
791-
│ Bar │ 22222222222222222222222222222222222222… │
792-
└──────┴─────────────────────────────────────────┘
793-
794-
`
795-
796-
const {stdout} = await captureOutput(async () =>
797-
printTable({
798-
data,
799-
columns: ['name', 'age'],
800-
}),
801-
)
802-
expect(stdout).to.equal(expected)
803-
804-
delete process.env.OCLIF_TABLE_COLUMN_OVERRIDE;
805-
process.stdout.columns = backupColumns;
806-
})
807721
})

test/util.test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {config, expect} from 'chai'
22

3-
import {getColumnWidth, intersperse, sortData} from '../src/utils.js'
3+
import {intersperse, sortData} from '../src/utils.js'
44

55
config.truncateThreshold = 0
66

@@ -64,28 +64,3 @@ describe('sortData', () => {
6464
expect(sortData(data, sort)).to.deep.equal(expected)
6565
})
6666
})
67-
68-
describe('should get the correct column width', () => {
69-
it('should return the value of OCLIF_TABLE_COLUMN_OVERRIDE', () => {
70-
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = '100'
71-
expect(getColumnWidth()).to.equal(100)
72-
delete process.env.OCLIF_TABLE_COLUMN_OVERRIDE
73-
})
74-
75-
it('should return the value of process.stdout.columns', () => {
76-
if (process.env.CI && !process.stdout.columns) {
77-
// In GHA process.stdout.columns is undefined
78-
expect(getColumnWidth()).to.equal(80)
79-
} else {
80-
const currentColumns = process.stdout.columns
81-
expect(getColumnWidth()).to.equal(currentColumns)
82-
}
83-
})
84-
85-
it('should return the default value of 80', () => {
86-
const backupColumns = process.stdout.columns
87-
process.stdout.columns = 0
88-
expect(getColumnWidth()).to.equal(80)
89-
process.stdout.columns = backupColumns
90-
})
91-
})

0 commit comments

Comments
 (0)