@@ -15,17 +15,16 @@ const fallbackWidth = 120
1515
1616// TableOptions customizes human-readable table rendering.
1717type TableOptions struct {
18- Title string
19- EmptyText string
20- HighlightIDColumns bool
18+ Title string
19+ EmptyText string
20+ IdentifierColumns [] int
2121}
2222
2323// RenderTable prints rows in a table using the terminal width to wrap columns.
2424func RenderTable (w io.Writer , title string , headers []string , rows [][]attribute.Value ) error {
2525 return RenderTableWithOptions (w , headers , rows , TableOptions {
26- Title : title ,
27- EmptyText : "No items to display" ,
28- HighlightIDColumns : true ,
26+ Title : title ,
27+ EmptyText : "No items to display" ,
2928 })
3029}
3130
@@ -49,12 +48,10 @@ func RenderTableWithOptions(w io.Writer, headers []string, rows [][]attribute.Va
4948 idStyle := basePadding .Foreground (SumUpPink ).Bold (true )
5049 defaultStyle := basePadding
5150
52- idColumns := make ([]bool , len (headers ))
53- if opts .HighlightIDColumns {
54- for i , header := range headers {
55- if isIDHeader (header ) {
56- idColumns [i ] = true
57- }
51+ identifierColumns := make (map [int ]struct {}, len (opts .IdentifierColumns ))
52+ for _ , idx := range opts .IdentifierColumns {
53+ if idx >= 0 && idx < len (headers ) {
54+ identifierColumns [idx ] = struct {}{}
5855 }
5956 }
6057
@@ -87,7 +84,7 @@ func RenderTableWithOptions(w io.Writer, headers []string, rows [][]attribute.Va
8784 if rowIndex := row - 1 ; rowIndex >= 0 && rowIndex < len (rows ) && col >= 0 && col < len (rows [rowIndex ]) {
8885 style = style .Inherit (rows [rowIndex ][col ].Style )
8986 }
90- if col >= 0 && col < len ( idColumns ) && idColumns [col ] {
87+ if _ , ok := identifierColumns [col ]; ok {
9188 style = style .Inherit (idStyle )
9289 }
9390 return style
@@ -104,7 +101,3 @@ func RenderTableWithOptions(w io.Writer, headers []string, rows [][]attribute.Va
104101 }
105102 return nil
106103}
107-
108- func isIDHeader (header string ) bool {
109- return strings .EqualFold (strings .TrimSpace (header ), "id" )
110- }
0 commit comments