MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / truncateText

Function truncateText

utils.go:210–226  ·  view source on GitHub ↗

truncateText truncates text to maxWidth and adds ellipsis if needed

(text string, maxWidth int)

Source from the content-addressed store, hash-verified

208
209// truncateText truncates text to maxWidth and adds ellipsis if needed
210func truncateText(text string, maxWidth int) string {
211 if maxWidth <= 0 {
212 return text
213 }
214
215 runes := []rune(text)
216 if len(runes) <= maxWidth {
217 return text
218 }
219
220 // Reserve 3 characters for ellipsis
221 if maxWidth <= 3 {
222 return string(runes[:maxWidth])
223 }
224
225 return string(runes[:maxWidth-3]) + "..."
226}
227
228// getColumnMaxWidth determines the maximum width for a column
229func getColumnMaxWidth(colIndex int) int {

Callers 5

TestTruncateText_ShortFunction · 0.85
TestTruncateText_LongFunction · 0.85
drawBufferFunction · 0.85

Calls

no outgoing calls

Tested by 4

TestTruncateText_ShortFunction · 0.68
TestTruncateText_LongFunction · 0.68