forked from WrongStack/WrongStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-diff-render.mjs
More file actions
68 lines (58 loc) · 2.81 KB
/
Copy pathverify-diff-render.mjs
File metadata and controls
68 lines (58 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Standalone verification script — does NOT go through vitest/ink-testing-library.
// Imports DiffBlock directly and uses Ink 7's render() against a captured
// stdout, so we can see the real ANSI escapes Ink emits.
import { render } from 'ink';
import { createElement as e } from 'react';
// FORCE_COLOR — set this in the parent shell or hard-code here.
// Hard-code '1' so we always see the color path in this verification.
process.env['FORCE_COLOR'] = '1';
const { DiffBlock } = await import('./packages/tui/src/components/history/code-block.tsx');
const rows = [
{ kind: 'hunk', text: '@@ -1 +1 @@' },
{ kind: 'del', text: '-old line', oldLine: 1 },
{ kind: 'add', text: '+new line', newLine: 1 },
];
async function capture(useColor, forceColor) {
const previous = process.env['FORCE_COLOR'];
process.env['FORCE_COLOR'] = forceColor;
return new Promise((resolve) => {
const chunks = [];
const originalWrite = process.stdout.write.bind(process.stdout);
process.stdout.write = (chunk, ...rest) => {
chunks.push(typeof chunk === 'string' ? chunk : chunk.toString('utf8'));
return true;
};
const instance = render(e(DiffBlock, { rows, hidden: 0, useColor }), {
exitOnCtrlC: false,
});
setTimeout(() => {
instance.unmount();
process.stdout.write = originalWrite;
if (previous === undefined) delete process.env['FORCE_COLOR'];
else process.env['FORCE_COLOR'] = previous;
resolve(chunks.join(''));
}, 200);
});
}
const colored = await capture(true, '1');
const fallback = await capture(false, '0');
console.log('=== DiffBlock useColor=true (FORCE_COLOR=1) ===');
console.log('Captured length:', colored.length);
console.log('Contains background truecolor escape (\\x1b[48;2;...m):', /\x1b\[48;2;\d+;\d+;\d+m/.test(colored));
console.log('Contains bold escape (\\x1b[1m):', /\x1b\[1m/.test(colored));
console.log('First 500 chars (JSON-quoted):');
console.log(JSON.stringify(colored.slice(0, 500)));
console.log();
console.log('=== DiffBlock useColor=false (FORCE_COLOR=0) ===');
console.log('Captured length:', fallback.length);
console.log('Contains any bg escape (\\x1b[48;):', /\x1b\[48;/.test(fallback));
console.log('Contains bold escape (\\x1b[1m):', /\x1b\[1m/.test(fallback));
console.log('First 500 chars (JSON-quoted):');
console.log(JSON.stringify(fallback.slice(0, 500)));
console.log();
console.log('=== Summary ===');
console.log('useColor=true emitted background truecolor escape:', /\x1b\[48;2;\d+;\d+;\d+m/.test(colored));
console.log('useColor=false emitted NO background escape: ', !/\x1b\[48;/.test(fallback));
console.log('useColor=false still emitted bold marker: ', /\x1b\[1m/.test(fallback));
console.log('useColor=false still shows the +/- markers in text: ', fallback.includes('-') && fallback.includes('+'));
process.exit(0);