MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / renderResults

Method renderResults

internal/tui/views/pricing.go:1076–1176  ·  view source on GitHub ↗
(active bool, minHeight int)

Source from the content-addressed store, hash-verified

1074}
1075
1076func (v *PricingView) renderResults(active bool, minHeight int) string {
1077 isFocused := active && v.ActiveSection == PricingSectionResults
1078 borderColor := colorDarkGray
1079 if isFocused {
1080 borderColor = colorGreen
1081 }
1082
1083 box := func(title, content string, color lipgloss.Color) string {
1084 return boxWithTitleMinHeight(title, content, color, v.Width, minHeight)
1085 }
1086
1087 if v.Loading {
1088 loadTitle := lipgloss.NewStyle().Foreground(colorYellow).Render("Results")
1089 return box(loadTitle, lipgloss.NewStyle().Foreground(colorYellow).Render("Loading pricing data..."), borderColor)
1090 }
1091
1092 if v.ErrorMessage != "" {
1093 errTitle := lipgloss.NewStyle().Foreground(colorRed).Render("Results")
1094 return box(errTitle, lipgloss.NewStyle().Foreground(colorRed).Render("Error: "+v.ErrorMessage), colorRed)
1095 }
1096
1097 if len(v.FilteredItems) == 0 {
1098 emptyTitle := lipgloss.NewStyle().Foreground(colorDarkGray).Render("Results (0)")
1099 return box(emptyTitle, lipgloss.NewStyle().Foreground(colorDarkGray).Render("No results found. Press Enter to submit query."), borderColor)
1100 }
1101
1102 totalPages := (len(v.FilteredItems) + v.ResultsPerPage - 1) / v.ResultsPerPage
1103 pageStart := v.ResultsPage * v.ResultsPerPage
1104 pageEnd := pageStart + v.ResultsPerPage
1105 if pageEnd > len(v.FilteredItems) {
1106 pageEnd = len(v.FilteredItems)
1107 }
1108
1109 // Collect attr keys from visible items
1110 attrKeySeen := map[string]struct{}{}
1111 var attrKeys []string
1112 for _, item := range v.FilteredItems {
1113 for _, k := range item.AttrKeys {
1114 if _, exists := attrKeySeen[k]; !exists {
1115 attrKeySeen[k] = struct{}{}
1116 attrKeys = append(attrKeys, k)
1117 }
1118 }
1119 }
1120
1121 // Build table header
1122 colWidths := v.computeColumnWidths(attrKeys)
1123 header := v.buildResultRow(-1, attrKeys, colWidths, false)
1124 headerLine := lipgloss.NewStyle().Foreground(colorYellow).Bold(true).Render(header)
1125
1126 var rows []string
1127 rows = append(rows, headerLine)
1128
1129 for idx := pageStart; idx < pageEnd; idx++ {
1130 isSel := idx == v.Selected
1131 row := v.buildResultRow(idx, attrKeys, colWidths, isSel)
1132 if isSel {
1133 rows = append(rows, lipgloss.NewStyle().Background(colorGreen).Foreground(colorBlack).Bold(true).Render(row))

Callers 1

RenderMethod · 0.95

Calls 6

computeColumnWidthsMethod · 0.95
buildResultRowMethod · 0.95
boxWithTitleMinHeightFunction · 0.85
maxFunction · 0.85
countByProviderFunction · 0.85
RenderMethod · 0.45

Tested by

no test coverage detected