MCPcopy
hub / github.com/codeaashu/claude-code / truncateToWidth

Function truncateToWidth

src/utils/truncate.ts:63–75  ·  view source on GitHub ↗
(text: string, maxWidth: number)

Source from the content-addressed store, hash-verified

61 * Appends '…' when truncation occurs.
62 */
63export function truncateToWidth(text: string, maxWidth: number): string {
64 if (stringWidth(text) <= maxWidth) return text
65 if (maxWidth <= 1) return '…'
66 let width = 0
67 let result = ''
68 for (const { segment } of getGraphemeSegmenter().segment(text)) {
69 const segWidth = stringWidth(segment)
70 if (width + segWidth > maxWidth - 1) break
71 result += segment
72 width += segWidth
73 }
74 return result + '…'
75}
76
77/**
78 * Truncates from the start of a string, keeping the tail end.

Callers 15

HistorySearchDialogFunction · 0.85
truncateTagFunction · 0.85
TaskItemFunction · 0.85
GlobalSearchDialogFunction · 0.85
QuickOpenDialogFunction · 0.85
QuestionNavigationBarFunction · 0.85
getMessagePreviewFunction · 0.85
TeammateSpinnerLineFunction · 0.85
UserChannelMessageFunction · 0.85

Calls 2

getGraphemeSegmenterFunction · 0.85
segmentMethod · 0.80

Tested by

no test coverage detected