MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / appendSegment

Function appendSegment

cli/src/utils/text-layout.ts:16–40  ·  view source on GitHub ↗
(
    segment: string,
    { flushBeforeOversize = true }: { flushBeforeOversize?: boolean } = {},
  )

Source from the content-addressed store, hash-verified

14 }
15
16 const appendSegment = (
17 segment: string,
18 { flushBeforeOversize = true }: { flushBeforeOversize?: boolean } = {},
19 ) => {
20 if (!segment) return
21
22 const segmentWidth = stringWidth(segment)
23 if (segmentWidth > cols) {
24 if (flushBeforeOversize && current > 0) emitHardWrap()
25 let acc = 0
26 for (const ch of Array.from(segment)) {
27 const w = stringWidth(ch)
28 if (acc + w > cols) {
29 emitHardWrap()
30 acc = 0
31 }
32 acc += w
33 }
34 current = acc
35 return
36 }
37
38 if (current + segmentWidth > cols) emitHardWrap()
39 current += segmentWidth
40 }
41
42 for (const token of tokens) {
43 if (!token) continue

Callers 2

measureLinesFunction · 0.85
getLastNVisualLinesFunction · 0.85

Calls 3

emitHardWrapFunction · 0.85
pushLineFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected