Print formats the table and then prints it to the UI specified at the time of the construction. Afterwards the table is cleared, becoming ready for another round of rows and printing.
()
| 271 | // the time of the construction. Afterwards the table is cleared, |
| 272 | // becoming ready for another round of rows and printing. |
| 273 | func (u *UITable) Print() error { |
| 274 | result := &bytes.Buffer{} |
| 275 | t := u.Table |
| 276 | |
| 277 | err := t.PrintTo(result) |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | |
| 282 | // DevNote. With the change to printing into a buffer all |
| 283 | // lines now come with a terminating \n. The t.ui.Say() below |
| 284 | // will then add another \n to that. To avoid this additional |
| 285 | // line we chop off the last \n from the output (if there is |
| 286 | // any). Operating on the slice avoids string copying. |
| 287 | // |
| 288 | // WIBNI if the terminal API had a variant of Say not assuming |
| 289 | // that each output is a single line. |
| 290 | |
| 291 | r := result.Bytes() |
| 292 | if len(r) > 0 { |
| 293 | r = r[0 : len(r)-1] |
| 294 | } |
| 295 | |
| 296 | // Only generate output for a non-empty table. |
| 297 | if len(r) > 0 { |
| 298 | u.UI.Say("%s", string(r)) |
| 299 | } |
| 300 | return nil |
| 301 | } |
| 302 | |
| 303 | func (ui *terminalUI) NotifyUpdateIfNeeded(config coreconfig.Reader) { |
| 304 | if !config.IsMinCLIVersion(config.CLIVersion()) { |