package presenter import ( "fmt" "io" "gitea.oblak.solutions/dimitar/gitFlow/pkg/status" ) // CompactFormatter renders one line per repository with color-coded status // symbols, aimed at dense terminals and dashboards. type CompactFormatter struct { opts Options } // Format implements Formatter. func (c *CompactFormatter) Format(w io.Writer, result status.ScanResult) error { r := newRendererTheme(c.opts.Color, c.opts.Theme, w) for _, repo := range result.Repos { sym := statusSymbol(repo.Status) line := r.paint(repo.Status, sym) + " " + shortPath(repo.Path) if repo.Branch != "" && !repo.Detached { line += " (" + repo.Branch + ")" } if repo.AheadBy > 0 || repo.BehindBy > 0 { line += fmt.Sprintf(" +%d/-%d", repo.AheadBy, repo.BehindBy) } if n := repo.FileCount(); n > 0 { line += fmt.Sprintf(" %d change(s)", n) } if repo.Status == status.StatusError { line += ": " + repo.Error } if _, err := fmt.Fprintln(w, line); err != nil { return err } } return nil } // StatusSymbolFor returns a single-character status marker for the given // status, shared by the compact formatter and the TUI. func StatusSymbolFor(s status.RepoStatus) string { return statusSymbol(s) } // statusSymbol returns a single-character status marker. func statusSymbol(s status.RepoStatus) string { switch s { case status.StatusClean: return "✓" case status.StatusModified: return "✗" case status.StatusAhead: return "↑" case status.StatusBehind: return "↓" case status.StatusDiverged: return "⇄" case status.StatusDetached: return "◉" case status.StatusBare: return "▢" case status.StatusError: return "!" default: return "?" } }