@@ -138,29 +138,15 @@ func collectStatuses(r git.Runner, candidates []git.WorktreeEntry, s *spinner.Sp
138138
139139// renderStatusDashboard prints the summary header and per-worktree table.
140140func renderStatusDashboard (out io.Writer , p * termcolor.Painter , results []statusEntry , staleDays int ) {
141- var totalCount , dirtyCount , staleCount , behindCount int
142- totalCount = len (results )
143141 staleThreshold := time .Now ().Add (- time .Duration (staleDays ) * 24 * time .Hour )
144-
145- for _ , r := range results {
146- if r .status .Dirty {
147- dirtyCount ++
148- }
149- if r .status .Behind > 0 {
150- behindCount ++
151- }
152- if r .hasTime && r .commitTime .Before (staleThreshold ) {
153- staleCount ++
154- }
155- }
156-
142+ summary := buildCLIStatusSummary (results , staleThreshold )
157143 prefixes := resolver .AllPrefixes ()
158144
159145 fmt .Fprintf (out , "Worktrees: %s Dirty: %s Stale: %s Behind: %s\n \n " ,
160- p .Paint (strconv .Itoa (totalCount ), termcolor .Bold ),
161- colorCount (p , dirtyCount , termcolor .Yellow ),
162- colorCount (p , staleCount , termcolor .Red ),
163- colorCount (p , behindCount , termcolor .Red ),
146+ p .Paint (strconv .Itoa (summary . total ), termcolor .Bold ),
147+ colorCount (p , summary . dirty , termcolor .Yellow ),
148+ colorCount (p , summary . stale , termcolor .Red ),
149+ colorCount (p , summary . behind , termcolor .Red ),
164150 )
165151
166152 tbl := termcolor .NewTable (2 )
@@ -173,33 +159,57 @@ func renderStatusDashboard(out io.Writer, p *termcolor.Painter, results []status
173159 )
174160
175161 for _ , r := range results {
176- task , matchedPrefix := resolver . TaskFromBranch ( r . entry . Branch , prefixes )
177- typeName := strings . TrimSuffix ( matchedPrefix , "/" )
162+ tbl . AddRow ( buildStatusRow ( r , prefixes , staleThreshold , p ) ... )
163+ }
178164
179- taskCell := " " + task
180- typeCell := typeName
181- if c := typeColor (typeName ); c != "" {
182- typeCell = p .Paint (typeCell , c )
183- }
165+ tbl .Render (out )
166+ }
184167
185- statusCell := colorStatus (p , r .status )
168+ type cliStatusSummary struct {
169+ total , dirty , stale , behind int
170+ }
186171
187- var ageCell string
188- if r .hasTime {
189- ageStr := resolver .FormatAge (r .commitTime )
190- if r .commitTime .Before (staleThreshold ) {
191- ageCell = p .Paint (ageStr , termcolor .Red ) + " " + p .Paint ("⚠ stale" , termcolor .Red )
192- } else {
193- ageCell = p .Paint (ageStr , resolver .AgeColor (r .commitTime ))
194- }
195- } else {
196- ageCell = p .Paint ("unknown" , termcolor .Gray )
172+ // buildCLIStatusSummary counts summary stats from results.
173+ func buildCLIStatusSummary (results []statusEntry , staleThreshold time.Time ) cliStatusSummary {
174+ s := cliStatusSummary {total : len (results )}
175+ for _ , r := range results {
176+ if r .status .Dirty {
177+ s .dirty ++
197178 }
179+ if r .status .Behind > 0 {
180+ s .behind ++
181+ }
182+ if r .hasTime && r .commitTime .Before (staleThreshold ) {
183+ s .stale ++
184+ }
185+ }
186+ return s
187+ }
198188
199- tbl .AddRow (taskCell , typeCell , r .entry .Branch , statusCell , ageCell )
189+ // buildStatusRow formats a single worktree row for the status table.
190+ func buildStatusRow (r statusEntry , prefixes []string , staleThreshold time.Time , p * termcolor.Painter ) []string {
191+ task , matchedPrefix := resolver .TaskFromBranch (r .entry .Branch , prefixes )
192+ typeName := strings .TrimSuffix (matchedPrefix , "/" )
193+
194+ taskCell := " " + task
195+ typeCell := typeName
196+ if c := typeColor (typeName ); c != "" {
197+ typeCell = p .Paint (typeCell , c )
200198 }
201199
202- tbl .Render (out )
200+ return []string {taskCell , typeCell , r .entry .Branch , colorStatus (p , r .status ), formatAgeCell (r , staleThreshold , p )}
201+ }
202+
203+ // formatAgeCell formats the age cell with color and stale indicator.
204+ func formatAgeCell (r statusEntry , staleThreshold time.Time , p * termcolor.Painter ) string {
205+ if ! r .hasTime {
206+ return p .Paint ("unknown" , termcolor .Gray )
207+ }
208+ ageStr := resolver .FormatAge (r .commitTime )
209+ if r .commitTime .Before (staleThreshold ) {
210+ return p .Paint (ageStr , termcolor .Red ) + " " + p .Paint ("⚠ stale" , termcolor .Red )
211+ }
212+ return p .Paint (ageStr , resolver .AgeColor (r .commitTime ))
203213}
204214
205215// writeStatusJSON builds the JSON output for the status command.
0 commit comments