MCPcopy
hub / github.com/restic/restic / printLine

Function printLine

internal/ui/table/table.go:70–112  ·  view source on GitHub ↗
(w io.Writer, print func(io.Writer, string) error, sep string, data []string, widths []int)

Source from the content-addressed store, hash-verified

68}
69
70func printLine(w io.Writer, print func(io.Writer, string) error, sep string, data []string, widths []int) error {
71 var fields [][]string
72
73 maxLines := 1
74 for _, d := range data {
75 lines := strings.Split(d, "\n")
76 if len(lines) > maxLines {
77 maxLines = len(lines)
78 }
79 fields = append(fields, lines)
80 }
81
82 for i := 0; i < maxLines; i++ {
83 var s string
84
85 for fieldNum, lines := range fields {
86 var v string
87
88 if i < len(lines) {
89 v += lines[i]
90 }
91
92 // apply padding
93 pad := widths[fieldNum] - ui.DisplayWidth(v)
94 if pad > 0 {
95 v += strings.Repeat(" ", pad)
96 }
97
98 if fieldNum > 0 {
99 v = sep + v
100 }
101
102 s += v
103 }
104
105 err := print(w, strings.TrimRight(s, " "))
106 if err != nil {
107 return err
108 }
109 }
110
111 return nil
112}
113
114// Write prints the table to w.
115func (t *Table) Write(w io.Writer) error {

Callers 1

WriteMethod · 0.85

Calls 1

DisplayWidthFunction · 0.92

Tested by

no test coverage detected