package cliui import ( "strings" "github.com/jedib0t/go-pretty/v6/table" ) // Table creates a new table with standardized styles. func Table() table.Writer { tableWriter := table.NewWriter() tableWriter.Style().Box.PaddingLeft = "" tableWriter.Style().Box.PaddingRight = " " tableWriter.Style().Options.DrawBorder = false tableWriter.Style().Options.SeparateHeader = false tableWriter.Style().Options.SeparateColumns = false return tableWriter } // FilterTableColumns returns configurations to hide columns // that are not provided in the array. If the array is empty, // no filtering will occur! func FilterTableColumns(header table.Row, columns []string) []table.ColumnConfig { if len(columns) == 0 { return nil } columnConfigs := make([]table.ColumnConfig, 0) for _, headerTextRaw := range header { headerText, _ := headerTextRaw.(string) hidden := true for _, column := range columns { if strings.EqualFold(strings.ReplaceAll(column, "_", " "), headerText) { hidden = false break } } columnConfigs = append(columnConfigs, table.ColumnConfig{ Name: headerText, Hidden: hidden, }) } return columnConfigs }