MCPcopy Create free account
hub / github.com/github/gh-aw / renderSlice

Function renderSlice

pkg/console/render.go:180–214  ·  view source on GitHub ↗

renderSlice renders a slice as a table using the console table renderer

(val reflect.Value, title string, output *strings.Builder, depth int)

Source from the content-addressed store, hash-verified

178
179// renderSlice renders a slice as a table using the console table renderer
180func renderSlice(val reflect.Value, title string, output *strings.Builder, depth int) {
181 if val.Len() == 0 {
182 return
183 }
184
185 renderLog.Printf("Rendering slice: title=%s, length=%d, element_type=%s", title, val.Len(), val.Type().Elem().Name())
186
187 // Print title without FormatInfoMessage styling
188 if title != "" {
189 if depth == 0 {
190 fmt.Fprintf(output, "# %s\n\n", title)
191 } else {
192 fmt.Fprintf(output, "%s %s\n\n", strings.Repeat("#", depth+1), title)
193 }
194 }
195
196 // Check if slice elements are structs (for table rendering)
197 elemType := val.Type().Elem()
198 for elemType.Kind() == reflect.Pointer {
199 elemType = elemType.Elem()
200 }
201
202 if elemType.Kind() == reflect.Struct {
203 // Render as table
204 config := buildTableConfig(val, title)
205 output.WriteString(RenderTable(config))
206 } else {
207 // Render as list
208 for i := range val.Len() {
209 elem := val.Index(i)
210 fmt.Fprintf(output, " • %v\n", formatFieldValue(elem))
211 }
212 output.WriteString("\n")
213 }
214}
215
216// renderMap renders a map as markdown-style headers
217func renderMap(val reflect.Value, title string, output *strings.Builder, depth int) {

Calls 4

buildTableConfigFunction · 0.85
formatFieldValueFunction · 0.85
RenderTableFunction · 0.70
PrintfMethod · 0.45