MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / writeDiffToTerminal

Function writeDiffToTerminal

source code/ink/terminal.ts:192–250  ·  view source on GitHub ↗
(
  terminal: Terminal,
  diff: Diff,
  skipSyncMarkers = false,
)

Source from the content-addressed store, hash-verified

190}
191
192export function writeDiffToTerminal(
193 terminal: Terminal,
194 diff: Diff,
195 skipSyncMarkers = false,
196): void {
197 // No output if there are no patches
198 if (diff.length === 0) {
199 return
200 }
201
202 // BSU/ESU wrapping is opt-out to keep main-screen behavior unchanged.
203 // Callers pass skipSyncMarkers=true when the terminal doesn't support
204 // DEC 2026 (e.g. tmux) AND the cost matters (high-frequency alt-screen).
205 const useSync = !skipSyncMarkers
206
207 // Buffer all writes into a single string to avoid multiple write calls
208 let buffer = useSync ? BSU : ''
209
210 for (const patch of diff) {
211 switch (patch.type) {
212 case 'stdout':
213 buffer += patch.content
214 break
215 case 'clear':
216 if (patch.count > 0) {
217 buffer += eraseLines(patch.count)
218 }
219 break
220 case 'clearTerminal':
221 buffer += getClearTerminalSequence()
222 break
223 case 'cursorHide':
224 buffer += HIDE_CURSOR
225 break
226 case 'cursorShow':
227 buffer += SHOW_CURSOR
228 break
229 case 'cursorMove':
230 buffer += cursorMove(patch.x, patch.y)
231 break
232 case 'cursorTo':
233 buffer += cursorTo(patch.col)
234 break
235 case 'carriageReturn':
236 buffer += '\r'
237 break
238 case 'hyperlink':
239 buffer += link(patch.uri)
240 break
241 case 'styleStr':
242 buffer += patch.str
243 break
244 }
245 }
246
247 // Add synchronized update end and flush buffer
248 if (useSync) buffer += ESU
249 terminal.stdout.write(buffer)

Callers 2

onRenderMethod · 0.85
unmountMethod · 0.85

Calls 6

eraseLinesFunction · 0.85
getClearTerminalSequenceFunction · 0.85
cursorMoveFunction · 0.85
cursorToFunction · 0.85
linkFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected