@@ -111,7 +111,7 @@ func formatTable(data any) (string, error) {
111111 return formatGenericMap (mapVal )
112112}
113113
114- // formatToolsList formats a list of tools as a table
114+ // formatToolsList formats a list of tools as a table.
115115func formatToolsList (tools any ) (string , error ) {
116116 toolsSlice , ok := tools .([]any )
117117 if ! ok {
@@ -129,9 +129,9 @@ func formatToolsList(tools any) (string, error) {
129129 fmt .Fprintln (w , "----\t -----------" )
130130
131131 termWidth := getTermWidth ()
132- nameColWidth := 20 // Default name column width
132+ nameColWidth := 20 // Default name column width
133133 descColWidth := termWidth - nameColWidth - 5 // Leave some margin
134-
134+
135135 if descColWidth < 10 {
136136 descColWidth = 40 // Minimum width if terminal is too narrow
137137 }
@@ -147,20 +147,20 @@ func formatToolsList(tools any) (string, error) {
147147
148148 // Handle multiline description
149149 lines := wrapText (desc , descColWidth )
150-
150+
151151 if len (lines ) == 0 {
152152 fmt .Fprintf (w , "%s\t \n " , name )
153153 continue
154154 }
155-
155+
156156 // First line with name
157157 fmt .Fprintf (w , "%s\t %s\n " , name , lines [0 ])
158-
158+
159159 // Remaining lines with empty name column
160160 for _ , line := range lines [1 :] {
161161 fmt .Fprintf (w , "\t %s\n " , line )
162162 }
163-
163+
164164 // Add a blank line between entries
165165 if len (lines ) > 1 {
166166 fmt .Fprintln (w , "\t " )
@@ -171,7 +171,7 @@ func formatToolsList(tools any) (string, error) {
171171 return buf .String (), nil
172172}
173173
174- // getTermWidth returns the terminal width or a default value if detection fails
174+ // getTermWidth returns the terminal width or a default value if detection fails.
175175func getTermWidth () int {
176176 width , _ , err := term .GetSize (int (os .Stdout .Fd ()))
177177 if err != nil || width <= 0 {
@@ -180,42 +180,42 @@ func getTermWidth() int {
180180 return width
181181}
182182
183- // wrapText wraps text to fit within a specified width
183+ // wrapText wraps text to fit within a specified width.
184184func wrapText (text string , width int ) []string {
185185 if text == "" {
186186 return []string {}
187187 }
188-
188+
189189 words := strings .Fields (text )
190190 if len (words ) == 0 {
191191 return []string {}
192192 }
193-
193+
194194 var lines []string
195195 var currentLine string
196-
196+
197197 for _ , word := range words {
198- // Check if adding this word would exceed the width
199- if len (currentLine )+ len (word )+ 1 > width && len (currentLine ) > 0 {
198+ switch {
199+ case len (currentLine ) == 0 :
200+ currentLine = word
201+ case len (currentLine )+ len (word )+ 1 > width :
200202 // Add current line to lines and start a new line
201203 lines = append (lines , currentLine )
202204 currentLine = word
203- } else if len (currentLine ) == 0 {
204- currentLine = word
205- } else {
205+ default :
206206 currentLine += " " + word
207207 }
208208 }
209-
209+
210210 // Add the last line
211211 if len (currentLine ) > 0 {
212212 lines = append (lines , currentLine )
213213 }
214-
214+
215215 return lines
216216}
217217
218- // formatResourcesList formats a list of resources as a table
218+ // formatResourcesList formats a list of resources as a table.
219219func formatResourcesList (resources any ) (string , error ) {
220220 resourcesSlice , ok := resources .([]any )
221221 if ! ok {
@@ -241,7 +241,7 @@ func formatResourcesList(resources any) (string, error) {
241241 name , _ := resource ["name" ].(string )
242242 resType , _ := resource ["type" ].(string )
243243 uri , _ := resource ["uri" ].(string )
244-
244+
245245 // Use the entire URI instead of truncating
246246 fmt .Fprintf (w , "%s\t %s\t %s\n " , name , resType , uri )
247247 }
@@ -250,7 +250,7 @@ func formatResourcesList(resources any) (string, error) {
250250 return buf .String (), nil
251251}
252252
253- // formatPromptsList formats a list of prompts as a table
253+ // formatPromptsList formats a list of prompts as a table.
254254func formatPromptsList (prompts any ) (string , error ) {
255255 promptsSlice , ok := prompts .([]any )
256256 if ! ok {
@@ -268,9 +268,9 @@ func formatPromptsList(prompts any) (string, error) {
268268 fmt .Fprintln (w , "----\t -----------" )
269269
270270 termWidth := getTermWidth ()
271- nameColWidth := 20 // Default name column width
271+ nameColWidth := 20 // Default name column width
272272 descColWidth := termWidth - nameColWidth - 5 // Leave some margin
273-
273+
274274 if descColWidth < 10 {
275275 descColWidth = 40 // Minimum width if terminal is too narrow
276276 }
@@ -286,20 +286,20 @@ func formatPromptsList(prompts any) (string, error) {
286286
287287 // Handle multiline description
288288 lines := wrapText (desc , descColWidth )
289-
289+
290290 if len (lines ) == 0 {
291291 fmt .Fprintf (w , "%s\t \n " , name )
292292 continue
293293 }
294-
294+
295295 // First line with name
296296 fmt .Fprintf (w , "%s\t %s\n " , name , lines [0 ])
297-
297+
298298 // Remaining lines with empty name column
299299 for _ , line := range lines [1 :] {
300300 fmt .Fprintf (w , "\t %s\n " , line )
301301 }
302-
302+
303303 // Add a blank line between entries
304304 if len (lines ) > 1 {
305305 fmt .Fprintln (w , "\t " )
0 commit comments