@@ -24,7 +24,7 @@ function termwidth(stream: NodeJS.WriteStream): number {
24
24
return 80 ;
25
25
}
26
26
27
- const width = stream . getWindowSize ( ) [ 0 ] ;
27
+ const [ width ] = stream . getWindowSize ( ) ;
28
28
if ( width < 1 ) {
29
29
return 80 ;
30
30
}
@@ -36,7 +36,10 @@ function termwidth(stream: NodeJS.WriteStream): number {
36
36
return width ;
37
37
}
38
38
39
- const stdtermwidth = Number . parseInt ( process . env . OCLIF_COLUMNS ! , 10 ) || termwidth ( process . stdout ) ;
39
+ const stdtermwidth =
40
+ typeof process . env . OCLIF_COLUMNS === 'string'
41
+ ? Number . parseInt ( process . env . OCLIF_COLUMNS , 10 )
42
+ : termwidth ( process . stdout ) ;
40
43
41
44
class Table < T extends Record < string , unknown > > {
42
45
private columns : Array < Column < T > & { key : string ; maxWidth ?: number ; width ?: number } > ;
@@ -47,8 +50,7 @@ class Table<T extends Record<string, unknown>> {
47
50
48
51
public constructor ( data : T [ ] , columns : Columns < T > , options : Options = { } ) {
49
52
// assign columns
50
- this . columns = Object . keys ( columns ) . map ( ( key : string ) => {
51
- const col = columns [ key ] ;
53
+ this . columns = Object . entries ( columns ) . map ( ( [ key , col ] ) => {
52
54
const extended = col . extended ?? false ;
53
55
// turn null and undefined into empty strings by default
54
56
const get = col . get ?? ( ( row : Record < string , unknown > ) : unknown => row [ key ] ?? '' ) ;
@@ -148,7 +150,7 @@ class Table<T extends Record<string, unknown>> {
148
150
// terminal width
149
151
const maxWidth = stdtermwidth - 2 ;
150
152
// truncation logic
151
- const shouldShorten = ( ) : void => {
153
+ const maybeShorten = ( ) : void => {
152
154
// don't shorten if full mode
153
155
if ( options [ 'no-truncate' ] ?? ( ! process . stdout . isTTY && ! process . env . CLI_UX_SKIP_TTY_CHECK ) ) return ;
154
156
@@ -187,7 +189,7 @@ class Table<T extends Record<string, unknown>> {
187
189
}
188
190
} ;
189
191
190
- shouldShorten ( ) ;
192
+ maybeShorten ( ) ;
191
193
192
194
// print table title
193
195
if ( options . title ) {
0 commit comments