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

Function truncateToWidthNoEllipsis

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

Source from the content-addressed store, hash-verified

106 * Width-aware and grapheme-safe.
107 */
108export function truncateToWidthNoEllipsis(
109 text: string,
110 maxWidth: number,
111): string {
112 if (stringWidth(text) <= maxWidth) return text
113 if (maxWidth <= 0) return ''
114 let width = 0
115 let result = ''
116 for (const { segment } of getGraphemeSegmenter().segment(text)) {
117 const segWidth = stringWidth(segment)
118 if (width + segWidth > maxWidth) break
119 result += segment
120 width += segWidth
121 }
122 return result
123}
124
125/**
126 * Truncates a string to fit within a maximum display width (terminal columns),

Callers 3

truncateCommandFunction · 0.85
truncatePathMiddleFunction · 0.85
truncatePathFunction · 0.85

Calls 2

getGraphemeSegmenterFunction · 0.85
segmentMethod · 0.80

Tested by

no test coverage detected