6
6
"os"
7
7
"strings"
8
8
9
+ "github.com/charmbracelet/lipgloss"
9
10
"github.com/sammcj/gollama/config"
10
11
"github.com/sammcj/gollama/logging"
11
12
"github.com/sammcj/gollama/styles"
@@ -26,6 +27,7 @@ func parseAPIResponse(resp *api.ListResponse) []Model {
26
27
QuantizationLevel : modelResp .Details .QuantizationLevel ,
27
28
Family : modelResp .Details .Family ,
28
29
Modified : modelResp .ModifiedAt ,
30
+ ParameterSize : modelResp .Details .ParameterSize ,
29
31
}
30
32
}
31
33
logging .DebugLogger .Println ("Models:" , models )
@@ -36,14 +38,18 @@ func normalizeSize(size float64) float64 {
36
38
return size // Sizes are already in GB in the API response
37
39
}
38
40
39
- func calculateColumnWidths (totalWidth int ) (nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth int ) {
41
+ // Constant for parameter size column width
42
+ const minParamSizeWidth = 10
43
+
44
+ func calculateColumnWidths (totalWidth int ) (nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth , paramSizeWidth int ) {
40
45
// Calculate column widths
41
- nameWidth = int (0.45 * float64 (totalWidth ))
46
+ nameWidth = int (0.40 * float64 (totalWidth ))
42
47
sizeWidth = int (0.05 * float64 (totalWidth ))
43
48
quantWidth = int (0.05 * float64 (totalWidth ))
44
49
familyWidth = int (0.05 * float64 (totalWidth ))
45
50
modifiedWidth = int (0.05 * float64 (totalWidth ))
46
51
idWidth = int (0.02 * float64 (totalWidth ))
52
+ paramSizeWidth = int (0.05 * float64 (totalWidth ))
47
53
48
54
// Set the absolute minimum width for each column
49
55
if nameWidth < minNameWidth {
@@ -64,10 +70,13 @@ func calculateColumnWidths(totalWidth int) (nameWidth, sizeWidth, quantWidth, mo
64
70
if familyWidth < minFamilyWidth {
65
71
familyWidth = minFamilyWidth
66
72
}
73
+ if paramSizeWidth < minParamSizeWidth {
74
+ paramSizeWidth = minParamSizeWidth
75
+ }
67
76
68
77
// If the total width is less than the sum of the minimum column widths, adjust the name column width and make sure all columns are aligned
69
- if totalWidth < nameWidth + sizeWidth + quantWidth + familyWidth + modifiedWidth + idWidth {
70
- nameWidth = totalWidth - sizeWidth - quantWidth - familyWidth - modifiedWidth - idWidth
78
+ if totalWidth < nameWidth + sizeWidth + quantWidth + familyWidth + modifiedWidth + idWidth + paramSizeWidth {
79
+ nameWidth = totalWidth - sizeWidth - quantWidth - familyWidth - modifiedWidth - idWidth - paramSizeWidth
71
80
}
72
81
73
82
return
@@ -109,7 +118,7 @@ func wrapText(text string, width int) string {
109
118
return wrapped
110
119
}
111
120
112
- func calculateColumnWidthsTerminal () (nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth int ) {
121
+ func calculateColumnWidthsTerminal () (nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth , paramSizeWidth int ) {
113
122
// use the terminal width to calculate column widths
114
123
minWidth := 120
115
124
@@ -140,16 +149,17 @@ func listModels(models []Model) {
140
149
}
141
150
142
151
stripString := cfg .StripString
143
- nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth := calculateColumnWidthsTerminal ()
152
+ nameWidth , sizeWidth , quantWidth , modifiedWidth , idWidth , familyWidth , paramSizeWidth := calculateColumnWidthsTerminal ()
144
153
145
154
// Add extra spacing between columns
146
155
colSpacing := 2
147
156
longestNameAllowed := 60
148
157
149
158
// Create the header with proper padding and alignment
150
- header := fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s%-*s" ,
159
+ header := fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s%-*s%-*s " ,
151
160
nameWidth , "Name" ,
152
161
sizeWidth + colSpacing , "Size" ,
162
+ paramSizeWidth + colSpacing , "Params" ,
153
163
quantWidth + colSpacing , "Quant" ,
154
164
familyWidth + colSpacing , "Family" ,
155
165
modifiedWidth + colSpacing , "Modified" ,
@@ -163,7 +173,7 @@ func listModels(models []Model) {
163
173
}
164
174
165
175
// Prepare columns for padding
166
- var names , sizes , quants , families , modified , ids []string
176
+ var names , sizes , quants , families , modified , ids , paramSizes []string
167
177
var longestName int
168
178
for _ , model := range models {
169
179
if len (model .Name ) > longestName {
@@ -175,6 +185,7 @@ func listModels(models []Model) {
175
185
}
176
186
names = append (names , model .Name )
177
187
sizes = append (sizes , fmt .Sprintf ("%.2fGB" , model .Size ))
188
+ paramSizes = append (paramSizes , model .ParameterSize )
178
189
quants = append (quants , model .QuantizationLevel )
179
190
families = append (families , model .Family )
180
191
modified = append (modified , model .Modified .Format ("2006-01-02" ))
@@ -184,6 +195,7 @@ func listModels(models []Model) {
184
195
// Calculate maximum width for each column
185
196
maxNameWidth := nameWidth
186
197
maxSizeWidth := sizeWidth + colSpacing
198
+ maxParamSizeWidth := paramSizeWidth + colSpacing
187
199
maxQuantWidth := quantWidth + colSpacing
188
200
maxFamilyWidth := familyWidth + colSpacing
189
201
maxModifiedWidth := modifiedWidth + colSpacing
@@ -193,14 +205,21 @@ func listModels(models []Model) {
193
205
for i := range names {
194
206
names [i ] = fmt .Sprintf ("%-*s" , maxNameWidth , names [i ])
195
207
sizes [i ] = fmt .Sprintf ("%-*s" , maxSizeWidth , sizes [i ])
208
+ paramSizes [i ] = fmt .Sprintf ("%-*s" , maxParamSizeWidth , paramSizes [i ])
196
209
quants [i ] = fmt .Sprintf ("%-*s" , maxQuantWidth , quants [i ])
197
210
families [i ] = fmt .Sprintf ("%-*s" , maxFamilyWidth , families [i ])
198
211
modified [i ] = fmt .Sprintf ("%-*s" , maxModifiedWidth , modified [i ])
199
212
// if the longest name is more than longestNameAllowed characters, don't display the model sha
200
213
if longestName > longestNameAllowed {
201
214
ids [i ] = ""
202
215
// remove the ID header
203
- header = fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s" , nameWidth , "Name" , sizeWidth + colSpacing , "Size" , quantWidth + colSpacing , "Quant" , familyWidth + colSpacing , "Family" , modifiedWidth , "Modified" )
216
+ header = fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s%-*s" ,
217
+ nameWidth , "Name" ,
218
+ sizeWidth + colSpacing , "Size" ,
219
+ paramSizeWidth + colSpacing , "Params" ,
220
+ quantWidth + colSpacing , "Quant" ,
221
+ familyWidth + colSpacing , "Family" ,
222
+ modifiedWidth , "Modified" )
204
223
} else {
205
224
ids [i ] = fmt .Sprintf ("%-*s" , maxIdWidth , ids [i ])
206
225
}
@@ -215,13 +234,24 @@ func listModels(models []Model) {
215
234
name := styles .ItemNameStyle (index ).Render (names [index ])
216
235
id := styles .ItemIDStyle ().Render (ids [index ])
217
236
size := styles .SizeStyle (model .Size ).Render (sizes [index ])
237
+ // Apply direct color based on parameter size
238
+ var paramSize string
239
+ if paramSizes [index ] != "" {
240
+ // Format the string first
241
+ formattedParamSize := fmt .Sprintf ("%-*s" , maxParamSizeWidth , paramSizes [index ])
242
+ // Apply color directly using paramSizeColour
243
+ paramSize = lipgloss .NewStyle ().Foreground (paramSizeColour (paramSizes [index ])).Render (formattedParamSize )
244
+ } else {
245
+ paramSize = fmt .Sprintf ("%-*s" , maxParamSizeWidth , paramSizes [index ])
246
+ }
218
247
family := styles .FamilyStyle (model .Family ).Render (families [index ])
219
248
quant := styles .QuantStyle (model .QuantizationLevel ).Render (quants [index ])
220
249
modified := styles .ItemIDStyle ().Render (modified [index ])
221
250
222
- row := fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s%-*s" ,
251
+ row := fmt .Sprintf ("%-*s%-*s%-*s%-*s%-*s%-*s%-*s " ,
223
252
maxNameWidth , name ,
224
253
maxSizeWidth , size ,
254
+ maxParamSizeWidth , paramSize ,
225
255
maxQuantWidth , quant ,
226
256
maxFamilyWidth , family ,
227
257
maxModifiedWidth , modified ,
0 commit comments