|
1 | | -import {Ux, Spinner} from '@salesforce/sf-plugins-core'; |
| 1 | +import {TableOptions} from '@oclif/table'; |
| 2 | +import {Spinner} from '@salesforce/sf-plugins-core'; |
2 | 3 |
|
3 | 4 | /** |
4 | 5 | * Interface for objects that display output information to users. E.g., a class that prints to the CLI would implement |
@@ -31,7 +32,7 @@ export interface Display { |
31 | 32 | /** |
32 | 33 | * Output table to stdout only if the "--json" flag is not present. |
33 | 34 | */ |
34 | | - displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void; |
| 35 | + displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void; |
35 | 36 |
|
36 | 37 | /** |
37 | 38 | * Prompt the user to confirm that the described action should be carried out, and block until they respond (or a timeout |
@@ -73,12 +74,28 @@ export class UxDisplay implements Display { |
73 | 74 | this.displayable.log(message); |
74 | 75 | } |
75 | 76 |
|
76 | | - public displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void { |
77 | | - this.displayable.table(data, columns); |
| 77 | + public displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void { |
| 78 | + // Currently oclif's table options do not allow us to set the width of the table larger than the user's current |
| 79 | + // terminal width. This means if the user's terminal width is small then we will table cells with "truncate" by |
| 80 | + // default or "wrap" depending on the passed in 'overflow' value in the table options. To work around this |
| 81 | + // limitation, we temporarily set the OCLIF_TABLE_COLUMN_OVERRIDE environment variable so that the user's |
| 82 | + // terminal width is ignored so that no truncating or wrapping occurs in order to maintain our original table |
| 83 | + // view behavior (prior to when we upgraded oclif). |
| 84 | + const oldTableColumnOverrideValue = process.env.OCLIF_TABLE_COLUMN_OVERRIDE; |
| 85 | + |
| 86 | + // If we use too large a number (like 99999), then we can get out of memory issues. Using 3000 seems to the best |
| 87 | + // number that fits everything without causing memory issues. And if there is more than 3000 characters then at |
| 88 | + // that point we are fine wrapping or truncating |
| 89 | + process.env.OCLIF_TABLE_COLUMN_OVERRIDE = '3000'; |
| 90 | + try { |
| 91 | + this.displayable.table(options); |
| 92 | + } finally { |
| 93 | + process.env.OCLIF_TABLE_COLUMN_OVERRIDE = oldTableColumnOverrideValue; |
| 94 | + } |
78 | 95 | } |
79 | 96 |
|
80 | 97 | public confirm(message: string): Promise<boolean> { |
81 | | - return this.displayable.confirm(message); |
| 98 | + return this.displayable.confirm({message}); |
82 | 99 | } |
83 | 100 |
|
84 | 101 | public spinnerStart(msg: string, status?: string): void { |
@@ -111,8 +128,8 @@ export interface Displayable { |
111 | 128 | log(message?: string): void; |
112 | 129 |
|
113 | 130 | // Prompt the user to confirm that the described action should be performed. [Implemented by SfCommand] |
114 | | - confirm(message: string): Promise<boolean>; |
| 131 | + confirm(promptInputs: {message: string}): Promise<boolean>; |
115 | 132 |
|
116 | 133 | // Output table to stdout only when "--json" flag is not present. [Implemented by SfCommand] |
117 | | - table<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>, options?: Ux.Table.Options): void; |
| 134 | + table<R extends Record<string, unknown>>(options: TableOptions<R>): void; |
118 | 135 | } |
0 commit comments