MCPcopy
hub / github.com/deepnote/deepnote / printContentDiff

Function printContentDiff

packages/cli/src/commands/diff.ts:376–399  ·  view source on GitHub ↗

* Print content diff with line-by-line changes.

(before: string | undefined, after: string | undefined, c: ChalkInstance)

Source from the content-addressed store, hash-verified

374 * Print content diff with line-by-line changes.
375 */
376function printContentDiff(before: string | undefined, after: string | undefined, c: ChalkInstance): void {
377 const oldContent = before ?? ''
378 const newContent = after ?? ''
379
380 const changes = diffLines(oldContent, newContent)
381
382 for (const change of changes) {
383 // Split into lines and remove trailing empty line from the split
384 const lines = change.value.split('\n')
385 if (lines[lines.length - 1] === '') {
386 lines.pop()
387 }
388
389 for (const line of lines) {
390 if (change.added) {
391 output(c.green(` + ${line}`))
392 } else if (change.removed) {
393 output(c.red(` - ${line}`))
394 } else {
395 output(c.gray(` ${line}`))
396 }
397 }
398 }
399}
400
401function getStatusIcon(status: 'added' | 'removed' | 'modified'): string {
402 if (status === 'added') return '+'

Callers 1

printDiffFunction · 0.85

Calls 1

outputFunction · 0.90

Tested by

no test coverage detected