MCPcopy Create free account
hub / github.com/Noumena-Network/code / computeWrap

Function computeWrap

src/ink/wrap-text.ts:71–105  ·  view source on GitHub ↗
(
  text: string,
  maxWidth: number,
  wrapType: Styles['textWrap'],
)

Source from the content-addressed store, hash-verified

69}
70
71function computeWrap(
72 text: string,
73 maxWidth: number,
74 wrapType: Styles['textWrap'],
75): string {
76 if (wrapType === 'wrap') {
77 return wrapAnsi(text, maxWidth, {
78 trim: false,
79 hard: true,
80 })
81 }
82
83 if (wrapType === 'wrap-trim') {
84 return wrapAnsi(text, maxWidth, {
85 trim: true,
86 hard: true,
87 })
88 }
89
90 if (wrapType!.startsWith('truncate')) {
91 let position: 'end' | 'middle' | 'start' = 'end'
92
93 if (wrapType === 'truncate-middle') {
94 position = 'middle'
95 }
96
97 if (wrapType === 'truncate-start') {
98 position = 'start'
99 }
100
101 return truncate(text, maxWidth, position)
102 }
103
104 return text
105}
106
107export function resetWrapTextCacheForTesting(): void {
108 wrapCache.clear()

Callers 1

wrapTextFunction · 0.85

Calls 1

truncateFunction · 0.70

Tested by

no test coverage detected