MCPcopy
hub / github.com/claude-code-best/claude-code / writeDiffToTerminal

Function writeDiffToTerminal

packages/@ant/ink/src/core/terminal.ts:188–246  ·  view source on GitHub ↗
(
  terminal: Terminal,
  diff: Diff,
  skipSyncMarkers = false,
)

Source from the content-addressed store, hash-verified

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