diff --git a/cmd/cmd.go b/cmd/cmd.go index 0f8072f06..df9af3547 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -747,11 +747,38 @@ func showInfo(resp *api.ShowResponse, verbose bool, w io.Writer) error { case float64: v = fmt.Sprintf("%g", vData) case []any: - n := 3 - if len(vData) < n { - n = len(vData) + targetWidth := 10 // Small width where we are displaying the data in a column + + var itemsToShow int + totalWidth := 1 // Start with 1 for opening bracket + + // Find how many we can fit + for i := range vData { + itemStr := fmt.Sprintf("%v", vData[i]) + width := runewidth.StringWidth(itemStr) + + // Add separator width (", ") for all items except the first + if i > 0 { + width += 2 + } + + // Check if adding this item would exceed our width limit + if totalWidth+width > targetWidth && i > 0 { + break + } + + totalWidth += width + itemsToShow++ + } + + // Format the output + if itemsToShow < len(vData) { + v = fmt.Sprintf("%v", vData[:itemsToShow]) + v = strings.TrimSuffix(v, "]") + v += fmt.Sprintf(" ...+%d more]", len(vData)-itemsToShow) + } else { + v = fmt.Sprintf("%v", vData) } - v = fmt.Sprintf("%v", vData[:n]) default: v = fmt.Sprintf("%T", vData) } @@ -772,10 +799,19 @@ func showInfo(resp *api.ShowResponse, verbose bool, w io.Writer) error { head := func(s string, n int) (rows [][]string) { scanner := bufio.NewScanner(strings.NewReader(s)) - for scanner.Scan() && (len(rows) < n || n < 0) { - if text := scanner.Text(); text != "" { - rows = append(rows, []string{"", strings.TrimSpace(text)}) + count := 0 + for scanner.Scan() { + text := strings.TrimSpace(scanner.Text()) + if text == "" { + continue } + count++ + if n < 0 || count <= n { + rows = append(rows, []string{"", text}) + } + } + if n >= 0 && count > n { + rows = append(rows, []string{"", "..."}) } return } diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index eb2fb124e..cf5fe7caa 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -225,6 +225,7 @@ Weigh anchor! System You are a pirate! Ahoy, matey! + ... ` if diff := cmp.Diff(expect, b.String()); diff != "" {