feat(list): port over to go-pretty

This commit is contained in:
Lewis Wynne 2025-11-07 13:49:43 +00:00
parent 4ace97bddc
commit 5ba0ff1e31
4 changed files with 101 additions and 75 deletions

View file

@ -98,15 +98,10 @@ func (s *Store) Print(pf string, includeBinary bool, vs ...[]byte) {
}
func (s *Store) PrintTo(w io.Writer, pf string, includeBinary bool, vs ...[]byte) {
nb := "(omitted binary data)"
fvs := make([]any, 0, len(vs))
tty := term.IsTerminal(int(os.Stdout.Fd()))
fvs := make([]any, 0, len(vs))
for _, v := range vs {
if tty && !includeBinary && !utf8.Valid(v) {
fvs = append(fvs, nb)
} else {
fvs = append(fvs, string(v))
}
fvs = append(fvs, s.formatBytes(includeBinary, v))
}
fmt.Fprintf(w, pf, fvs...)
if w == os.Stdout && tty && !strings.HasSuffix(pf, "\n") {
@ -114,6 +109,18 @@ func (s *Store) PrintTo(w io.Writer, pf string, includeBinary bool, vs ...[]byte
}
}
func (s *Store) FormatBytes(includeBinary bool, v []byte) string {
return s.formatBytes(includeBinary, v)
}
func (s *Store) formatBytes(includeBinary bool, v []byte) string {
tty := term.IsTerminal(int(os.Stdout.Fd()))
if tty && !includeBinary && !utf8.Valid(v) {
return "(omitted binary data)"
}
return string(v)
}
func (s *Store) AllStores() ([]string, error) {
path, err := s.path()
if err != nil {