printTable writes aligned tabular output to stdout.
(headers []string, rows [][]string)
| 275 | |
| 276 | // printTable writes aligned tabular output to stdout. |
| 277 | func printTable(headers []string, rows [][]string) { |
| 278 | w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) |
| 279 | |
| 280 | _, _ = fmt.Fprintln(w, strings.Join(headers, "\t")) |
| 281 | |
| 282 | seps := make([]string, len(headers)) |
| 283 | for i, h := range headers { |
| 284 | seps[i] = strings.Repeat("-", len(h)) |
| 285 | } |
| 286 | |
| 287 | _, _ = fmt.Fprintln(w, strings.Join(seps, "\t")) |
| 288 | |
| 289 | for _, row := range rows { |
| 290 | _, _ = fmt.Fprintln(w, strings.Join(row, "\t")) |
| 291 | } |
| 292 | |
| 293 | _ = w.Flush() |
| 294 | } |
| 295 | |
| 296 | // formatBytes formats a byte count as a human-readable string (e.g. 1.5 GiB). |
| 297 | func formatBytes(b int64) string { |
no outgoing calls