MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / render

Method render

src/utils/Cursor.ts:178–274  ·  view source on GitHub ↗
(
    cursorChar: string,
    mask: string,
    invert: (text: string) => string,
    ghostText?: { text: string; dim: (text: string) => string },
    maxVisibleLines?: number,
  )

Source from the content-addressed store, hash-verified

176 }
177
178 render(
179 cursorChar: string,
180 mask: string,
181 invert: (text: string) => string,
182 ghostText?: { text: string; dim: (text: string) => string },
183 maxVisibleLines?: number,
184 ) {
185 const { line, column } = this.getPosition()
186 const allLines = this.measuredText.getWrappedText()
187
188 const startLine = this.getViewportStartLine(maxVisibleLines)
189 const endLine =
190 maxVisibleLines !== undefined && maxVisibleLines > 0
191 ? Math.min(allLines.length, startLine + maxVisibleLines)
192 : allLines.length
193
194 return allLines
195 .slice(startLine, endLine)
196 .map((text, i) => {
197 const currentLine = i + startLine
198 let displayText = text
199 if (mask) {
200 const graphemes = Array.from(getGraphemeSegmenter().segment(text))
201 if (currentLine === allLines.length - 1) {
202 // Last line: mask all but the trailing 6 chars so the user can
203 // confirm they pasted the right thing without exposing the full token
204 const visibleCount = Math.min(6, graphemes.length)
205 const maskCount = graphemes.length - visibleCount
206 const splitOffset =
207 graphemes.length > visibleCount ? graphemes[maskCount]!.index : 0
208 displayText = mask.repeat(maskCount) + text.slice(splitOffset)
209 } else {
210 // Earlier wrapped lines: fully mask. Previously only the last line
211 // was masked, leaking the start of the token on narrow terminals
212 // where the pasted OAuth code wraps across multiple lines.
213 displayText = mask.repeat(graphemes.length)
214 }
215 }
216 // looking for the line with the cursor
217 if (line !== currentLine) return displayText.trimEnd()
218
219 // Split the line into before/at/after cursor in a single pass over the
220 // graphemes, accumulating display width until we reach the cursor column.
221 // This replaces a two-pass approach (displayWidthToStringIndex + a second
222 // segmenter pass) — the intermediate stringIndex from that approach is
223 // always a grapheme boundary, so the "cursor in the middle of a
224 // multi-codepoint character" branch was unreachable.
225 let beforeCursor = ''
226 let atCursor = cursorChar
227 let afterCursor = ''
228 let currentWidth = 0
229 let cursorFound = false
230
231 for (const { segment } of getGraphemeSegmenter().segment(displayText)) {
232 if (cursorFound) {
233 afterCursor += segment
234 continue
235 }

Callers 6

showDialogFunction · 0.45
exitWithMessageFunction · 0.45
renderAndRunFunction · 0.45
useTextInputFunction · 0.45

Calls 7

getPositionMethod · 0.95
getViewportStartLineMethod · 0.95
isAtEndMethod · 0.95
getWrappedTextMethod · 0.80
segmentMethod · 0.80
getGraphemeSegmenterFunction · 0.70
firstGraphemeFunction · 0.70

Tested by

no test coverage detected