From e64ad8f0782b51f37f1e232e17a530086219cf33 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 18 Jan 2026 21:44:06 -0300 Subject: [PATCH] git: better printing of server statuses. --- git.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/git.go b/git.go index e1b91eb..2fba856 100644 --- a/git.go +++ b/git.go @@ -824,15 +824,18 @@ aside from those, there is also: stateHEAD, _ := state.Branches[state.HEAD] stdout("\n" + color.CyanString("grasp status:")) - for _, server := range localConfig.GraspServers { + rows := make([][3]string, len(localConfig.GraspServers)) + for s, server := range localConfig.GraspServers { + row := [3]string{} + url := graspServerHost(server) - line := " " + url + row[0] = url upToDate := upToDateRelays != nil && slices.ContainsFunc(upToDateRelays, func(s string) bool { return graspServerHost(s) == url }) if upToDate { - line += " " + color.GreenString("announcement up-to-date") + row[1] = color.GreenString("announcement up-to-date") } else { - line += " " + color.YellowString("announcement outdated") + row[1] = color.YellowString("announcement outdated") } if state != nil { @@ -841,17 +844,30 @@ aside from those, there is also: lsRemoteCmd := exec.Command("git", "rev-parse", "--verify", refSpec) commitOutput, err := lsRemoteCmd.Output() if err != nil { - line += " " + color.YellowString("repository not pushed.") + row[2] = color.YellowString("repository not pushed") } else { commit := strings.TrimSpace(string(commitOutput)) if commit == stateHEAD { - line += " " + color.GreenString("repository synced with state.") + row[2] = color.GreenString("repository synced with state") } else { - line += " " + color.YellowString("mismatched HEAD state=%s, pushed=%s.", state.HEAD, commit) + row[2] = color.YellowString("mismatched HEAD state=%s, pushed=%s", state.HEAD, commit) } } } + rows[s] = row + } + + maxCol := [3]int{} + for i := range maxCol { + for _, row := range rows { + if len(row[i]) > maxCol[i] { + maxCol[i] = len(row[i]) + } + } + } + for _, row := range rows { + line := " " + row[0] + strings.Repeat(" ", maxCol[0]-len(row[0])) + " " + strings.Repeat(" ", maxCol[1]-len(row[1])) + row[1] + " " + strings.Repeat(" ", maxCol[2]-len(row[2])) + row[2] stdout(line) }