MCPcopy Index your code
hub / github.com/devspace-sh/devspace / PrintTableWithOptions

Function PrintTableWithOptions

pkg/util/log/log.go:56–93  ·  view source on GitHub ↗

PrintTableWithOptions prints a table with header columns and string values

(s Logger, header []string, values [][]string, modify func(table *tablewriter.Table))

Source from the content-addressed store, hash-verified

54
55// PrintTableWithOptions prints a table with header columns and string values
56func 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}

Callers 2

RunListCommandsMethod · 0.92
PrintTableFunction · 0.85

Calls 6

NewScannerFunction · 0.92
closeFunction · 0.85
CloseMethod · 0.65
WriteStringMethod · 0.65
RenderMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected