mirror of
https://github.com/dogkeeper886/ollama37.git
synced 2025-12-10 15:57:04 +00:00
cmd: add ellipses to truncated show metadata (#10717)
When a piece of information has been truncated in the show output an ellipses to indicate that more data has not been displayed
This commit is contained in:
50
cmd/cmd.go
50
cmd/cmd.go
@@ -747,11 +747,38 @@ func showInfo(resp *api.ShowResponse, verbose bool, w io.Writer) error {
|
|||||||
case float64:
|
case float64:
|
||||||
v = fmt.Sprintf("%g", vData)
|
v = fmt.Sprintf("%g", vData)
|
||||||
case []any:
|
case []any:
|
||||||
n := 3
|
targetWidth := 10 // Small width where we are displaying the data in a column
|
||||||
if len(vData) < n {
|
|
||||||
n = len(vData)
|
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:
|
default:
|
||||||
v = fmt.Sprintf("%T", vData)
|
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) {
|
head := func(s string, n int) (rows [][]string) {
|
||||||
scanner := bufio.NewScanner(strings.NewReader(s))
|
scanner := bufio.NewScanner(strings.NewReader(s))
|
||||||
for scanner.Scan() && (len(rows) < n || n < 0) {
|
count := 0
|
||||||
if text := scanner.Text(); text != "" {
|
for scanner.Scan() {
|
||||||
rows = append(rows, []string{"", strings.TrimSpace(text)})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ Weigh anchor!
|
|||||||
System
|
System
|
||||||
You are a pirate!
|
You are a pirate!
|
||||||
Ahoy, matey!
|
Ahoy, matey!
|
||||||
|
...
|
||||||
|
|
||||||
`
|
`
|
||||||
if diff := cmp.Diff(expect, b.String()); diff != "" {
|
if diff := cmp.Diff(expect, b.String()); diff != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user