Add setting to support OSC 52 paste (#15336)

This commit is contained in:
Tommaso Sciortino
2026-01-05 16:11:50 -08:00
committed by GitHub
parent 2cb33b2f76
commit 384fb6a465
7 changed files with 216 additions and 10 deletions

View File

@@ -4,7 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { renderWithProviders } from '../../test-utils/render.js';
import {
renderWithProviders,
createMockSettings,
} from '../../test-utils/render.js';
import { waitFor } from '../../test-utils/async.js';
import { act } from 'react';
import type { InputPromptProps } from './InputPrompt.js';
@@ -598,7 +601,7 @@ describe('InputPrompt', () => {
});
await waitFor(() => {
expect(debugLoggerErrorSpy).toHaveBeenCalledWith(
'Error handling clipboard image:',
'Error handling paste:',
expect.any(Error),
);
});
@@ -633,6 +636,31 @@ describe('InputPrompt', () => {
});
unmount();
});
it('should use OSC 52 when useOSC52Paste setting is enabled', async () => {
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);
const settings = createMockSettings({
experimental: { useOSC52Paste: true },
});
const { stdout, stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ settings },
);
const writeSpy = vi.spyOn(stdout, 'write');
await act(async () => {
stdin.write('\x16'); // Ctrl+V
});
await waitFor(() => {
expect(writeSpy).toHaveBeenCalledWith('\x1b]52;c;?\x07');
});
// Should NOT call clipboardy.read()
expect(clipboardy.read).not.toHaveBeenCalled();
unmount();
});
});
it.each([