diff --git a/src/internalTable/internal-table.ts b/src/internalTable/internal-table.ts index fa4f5ad2..d67b3b0d 100644 --- a/src/internalTable/internal-table.ts +++ b/src/internalTable/internal-table.ts @@ -72,7 +72,9 @@ class TableInternal { this.rowSeparator = options?.rowSeparator || this.rowSeparator; this.charLength = options?.charLength || this.charLength; - if (options?.colorMap) { + if (options?.shouldDisableColors) { + this.colorMap = {}; + } else if (options?.colorMap) { this.colorMap = { ...this.colorMap, ...options.colorMap }; } diff --git a/src/models/external-table.ts b/src/models/external-table.ts index b9d57188..4fcfdc86 100644 --- a/src/models/external-table.ts +++ b/src/models/external-table.ts @@ -32,6 +32,7 @@ export interface ComplexOptions { disabledColumns?: string[]; computedColumns?: ComputedColumn[]; rowSeparator?: boolean; + shouldDisableColors? : boolean; colorMap?: ColorMap; charLength?: CharLengthDict; } diff --git a/test/__snapshots__/customizedColor.test.ts.snap b/test/__snapshots__/customizedColor.test.ts.snap index 3728c907..fea8ab2e 100644 --- a/test/__snapshots__/customizedColor.test.ts.snap +++ b/test/__snapshots__/customizedColor.test.ts.snap @@ -9,3 +9,13 @@ exports[`Example: Print a simple Table with Custom column colors Custom column c │ 4  │  This row is green │  10.212 │ └──────────────────────┴──────────────────────────┴─────────────┘" `; + +exports[`Example: Print a simple Table with Custom column colors Disabling color works 1`] = ` +"┌──────────────────────┬──────────────────────────┬─────────────┐ +│ red_left_align_index │ right_align_text │ green_value │ +├──────────────────────┼──────────────────────────┼─────────────┤ +│ 2 │ This is my defined Green │ 10.212 │ +│ 3 │ This row is blue as well │ 10.212 │ +│ 4 │ This row is green │ 10.212 │ +└──────────────────────┴──────────────────────────┴─────────────┘" +`; diff --git a/test/customizedColor.test.ts b/test/customizedColor.test.ts index 68317a8c..4b215cca 100644 --- a/test/customizedColor.test.ts +++ b/test/customizedColor.test.ts @@ -44,4 +44,46 @@ describe('Example: Print a simple Table with Custom column colors', () => { p.printTable(); expect(p.render()).toMatchSnapshot(); }); + + it('Disabling color works', () => { + // Create a table + const p = new Table({ + columns: [ + { name: 'red_left_align_index', alignment: 'left' }, + { name: 'right_align_text', alignment: 'right' }, + { name: 'green_value' }, + ], + shouldDisableColors: true, + }); + + // add rows with custom color + p.addRow( + { + red_left_align_index: 2, + right_align_text: 'This is my defined Green', + green_value: 10.212, + }, + { color: 'custom_green' } // custom color + ); + p.addRow( + { + red_left_align_index: 3, + right_align_text: 'This row is blue as well', + green_value: 10.212, + }, + { color: 'blue' } + ); + p.addRow( + { + red_left_align_index: 4, + right_align_text: 'This row is green', + green_value: 10.212, + }, + { color: 'green' } + ); + + // print + p.printTable(); + expect(p.render()).toMatchSnapshot(); + }); });