MCPcopy
hub / github.com/sammcj/gollama / Render

Method Render

item_delegate.go:57–131  ·  view source on GitHub ↗
(w io.Writer, m list.Model, index int, item list.Item)

Source from the content-addressed store, hash-verified

55}
56
57func (d itemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
58 model, ok := item.(Model)
59 if !ok {
60 return
61 }
62
63 // If StripString is set in the config, strip it from the model name
64 if d.appModel.cfg.StripString != "" {
65 model.Name = strings.Replace(model.Name, d.appModel.cfg.StripString, "", 1)
66 }
67
68 nameStyle := styles.ItemNameStyle(index)
69 dateStyle := styles.ItemDateStyle()
70 shaStyle := styles.ItemShaStyle()
71 sizeStyle := styles.SizeStyle(model.Size)
72 familyStyle := styles.FamilyStyle(model.Family)
73 quantStyle := styles.QuantStyle(model.QuantizationLevel)
74 modifiedStyle := styles.ItemDateStyle() // Use date style for modified date
75
76 if index == m.Index() {
77 // Apply border and highlight styles for selected item
78 nameStyle = nameStyle.Bold(true).BorderLeft(true).BorderStyle(lipgloss.InnerHalfBlockBorder()).BorderForeground(styles.GetTheme().GetColour(styles.GetTheme().Colours.ItemBorder)).PaddingLeft(1)
79 sizeStyle = sizeStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
80 quantStyle = quantStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
81 familyStyle = familyStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
82 modifiedStyle = modifiedStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
83 shaStyle = shaStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
84 dateStyle = dateStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2)
85 }
86
87 // Check if the model is selected in both filtered and unfiltered states
88 isSelected := model.Selected
89 if d.appModel.list.FilterState() == list.Filtering || d.appModel.list.FilterState() == list.FilterApplied {
90 // When filtering, also check the main models list to ensure selection state is accurate
91 for _, m := range d.appModel.models {
92 if m.Name == model.Name && m.Selected {
93 isSelected = true
94 break
95 }
96 }
97 }
98
99 if isSelected {
100 selectedStyle := styles.SelectedItemStyle()
101 // Create new styles that inherit from selected style first
102 // Keep the foreground colour but add the background highlight
103 nameStyle = selectedStyle.Bold(true).
104 Italic(true)
105 shaStyle = selectedStyle.Inherit(shaStyle)
106 dateStyle = selectedStyle.Inherit(dateStyle)
107 sizeStyle = selectedStyle.Inherit(sizeStyle)
108 familyStyle = selectedStyle.Inherit(familyStyle)
109 quantStyle = selectedStyle.Inherit(quantStyle)
110 }
111
112 nameWidth, sizeWidth, quantWidth, modifiedWidth, idWidth, familyWidth, paramSizeWidth := calculateColumnWidths(m.Width())
113
114 // Ensure the text fits within the terminal width

Callers 15

listModelsFunction · 0.80
modelfileDiffViewMethod · 0.80
handleUnloadModelsKeyMethod · 0.80
handleCopyModelKeyMethod · 0.80
handlePushModelKeyMethod · 0.80
handlePullModelKeyMethod · 0.80
handleRenameModelKeyMethod · 0.80
ViewMethod · 0.80
topViewMethod · 0.80
externalEditorViewMethod · 0.80
ViewMethod · 0.80

Calls 12

ItemNameStyleFunction · 0.92
ItemDateStyleFunction · 0.92
ItemShaStyleFunction · 0.92
SizeStyleFunction · 0.92
FamilyStyleFunction · 0.92
QuantStyleFunction · 0.92
GetThemeFunction · 0.92
SelectedItemStyleFunction · 0.92
ParamSizeStyleFunction · 0.92
calculateColumnWidthsFunction · 0.85
truncateFunction · 0.85
GetColourMethod · 0.80

Tested by

no test coverage detected