PrintTableWithOptions prints a table with header columns and string values
(s Logger, header []string, values [][]string, modify func(table *tablewriter.Table))
| 54 | |
| 55 | // PrintTableWithOptions prints a table with header columns and string values |
| 56 | func PrintTableWithOptions(s Logger, header []string, values [][]string, modify func(table *tablewriter.Table)) { |
| 57 | reader, writer := io.Pipe() |
| 58 | defer writer.Close() |
| 59 | |
| 60 | done := make(chan struct{}) |
| 61 | go func() { |
| 62 | defer close(done) |
| 63 | |
| 64 | sa := scanner.NewScanner(reader) |
| 65 | for sa.Scan() { |
| 66 | s.WriteString(logrus.InfoLevel, " "+sa.Text()+"\n") |
| 67 | } |
| 68 | }() |
| 69 | |
| 70 | table := tablewriter.NewWriter(writer) |
| 71 | table.SetHeader(header) |
| 72 | if runtime.GOOS == "darwin" || runtime.GOOS == "linux" { |
| 73 | colors := []tablewriter.Colors{} |
| 74 | for range header { |
| 75 | colors = append(colors, tablewriter.Color(tablewriter.FgGreenColor)) |
| 76 | } |
| 77 | table.SetHeaderColor(colors...) |
| 78 | } |
| 79 | |
| 80 | table.SetAlignment(tablewriter.ALIGN_LEFT) |
| 81 | table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false}) |
| 82 | table.AppendBulk(values) |
| 83 | if modify != nil { |
| 84 | modify(table) |
| 85 | } |
| 86 | |
| 87 | // Render |
| 88 | _, _ = writer.Write([]byte("\n")) |
| 89 | table.Render() |
| 90 | _, _ = writer.Write([]byte("\n")) |
| 91 | _ = writer.Close() |
| 92 | <-done |
| 93 | } |
no test coverage detected