~emersion/hut

9c42e4c6ac582bbace3d068296c15e809cce8f32 — Thorben Günther 4 months ago 1a48056
patchset list: Align output

References: https://todo.sr.ht/~emersion/hut/16
2 files changed, 10 insertions(+), 6 deletions(-)

M lists.go
M termfmt/formatting.go
M lists.go => lists.go +7 -4
@@ 10,6 10,7 @@ import (
	"os/exec"
	"strconv"
	"strings"
	"text/tabwriter"

	"github.com/spf13/cobra"



@@ 235,8 236,10 @@ func newListsPatchsetListCommand() *cobra.Command {
			patches = list.Patches
		}

		tw := tabwriter.NewWriter(os.Stdout, 0, 4, 1, ' ', 0)
		defer tw.Flush()
		for _, patchset := range patches.Results {
			s := fmt.Sprintf("%s %s ", termfmt.DarkYellow.Sprintf("#%d", patchset.Id), patchset.Status.TermString())
			s := fmt.Sprintf("%s %s\t", termfmt.DarkYellow.Sprintf("#%d", patchset.Id), patchset.Status.TermString())
			if patchset.Prefix != nil && *patchset.Prefix != "" {
				s += fmt.Sprintf("[%s] ", *patchset.Prefix)
			}


@@ 246,13 249,13 @@ func newListsPatchsetListCommand() *cobra.Command {
			}

			if byUser {
				s += fmt.Sprintf(" (%s/%s %s ago)", patchset.List.Owner.CanonicalName,
				s += fmt.Sprintf("\t(%s/%s %s ago)", patchset.List.Owner.CanonicalName,
					patchset.List.Name, timeDelta(patchset.Created))
			} else {
				s += fmt.Sprintf(" (%s %s ago)", patchset.Submitter.CanonicalName,
				s += fmt.Sprintf("\t(%s %s ago)", patchset.Submitter.CanonicalName,
					timeDelta(patchset.Created))
			}
			fmt.Println(s)
			fmt.Fprintln(tw, s)
		}
	}


M termfmt/formatting.go => termfmt/formatting.go +3 -2
@@ 35,11 35,12 @@ func (style Style) String(s string) string {
		return s
	}

	// All formatting strings have to be the same length for tabwriter to work
	switch style {
	case Bold:
		return fmt.Sprintf("\033[1m%s\033[0m", s)
		return fmt.Sprintf("\033[01m%s\033[0m", s)
	case Dim:
		return fmt.Sprintf("\033[2m%s\033[0m", s)
		return fmt.Sprintf("\033[02m%s\033[0m", s)
	case Red:
		return fmt.Sprintf("\033[91m%s\033[0m", s)
	case Green: