printEditHistory lists every version the API returned, newest first, with who saved it and when. "Current" marks the newest version, and "Viewing" marks the earlier version shown.
(ios *iostreams.IOStreams, now time.Time, versions []client.Version, viewing *client.Version)
| 292 | // who saved it and when. "Current" marks the newest version, and "Viewing" |
| 293 | // marks the earlier version shown. |
| 294 | func printEditHistory(ios *iostreams.IOStreams, now time.Time, versions []client.Version, viewing *client.Version) error { |
| 295 | cs := ios.ColorScheme() |
| 296 | // The "Edit history" heading stands in for column headers. |
| 297 | tp := tableprinter.New(ios, tableprinter.NoHeader) |
| 298 | for i, v := range versions { |
| 299 | tp.AddField(strconv.Itoa(v.Version)) |
| 300 | if v.CreatedAt != nil { |
| 301 | tp.AddField(displayName(v.Actor)) |
| 302 | tp.AddTimeField(now, *v.CreatedAt, cs.Muted) |
| 303 | } else { |
| 304 | tp.AddField(login(v.Actor)) |
| 305 | tp.AddField("") |
| 306 | } |
| 307 | switch { |
| 308 | case i == 0: |
| 309 | tp.AddField("Current", tableprinter.WithColor(cs.CyanBold)) |
| 310 | case viewing != nil && v.Version == viewing.Version: |
| 311 | tp.AddField("Viewing", tableprinter.WithColor(cs.CyanBold)) |
| 312 | } |
| 313 | tp.EndRow() |
| 314 | } |
| 315 | return tp.Render() |
| 316 | } |
| 317 | |
| 318 | // displayName returns a user's login for the terminal. A null user shows as |
| 319 | // ghost, like a deleted user in gh pr view, so callers use it only when the |
no test coverage detected