fix(cli): copy uses OSC52 only in SSH/WSL (#16554)

Signed-off-by: assagman <ahmetsercansagman@gmail.com>
This commit is contained in:
Sercan Sagman
2026-01-14 01:55:28 +03:00
committed by GitHub
parent d66ec38f82
commit c7c409c68f
3 changed files with 23 additions and 5 deletions

View File

@@ -239,11 +239,12 @@ describe('commandUtils', () => {
expect(mockClipboardyWrite).not.toHaveBeenCalled();
});
it('wraps OSC-52 for tmux', async () => {
it('wraps OSC-52 for tmux when in SSH', async () => {
const testText = 'tmux-copy';
const tty = makeWritable({ isTTY: true });
mockFs.createWriteStream.mockReturnValue(tty);
process.env['SSH_CONNECTION'] = '1';
process.env['TMUX'] = '1';
await copyToClipboard(testText);
@@ -257,12 +258,13 @@ describe('commandUtils', () => {
expect(mockClipboardyWrite).not.toHaveBeenCalled();
});
it('wraps OSC-52 for GNU screen with chunked DCS', async () => {
it('wraps OSC-52 for GNU screen with chunked DCS when in SSH', async () => {
// ensure payload > chunk size (240) so there are multiple chunks
const testText = 'x'.repeat(1200);
const tty = makeWritable({ isTTY: true });
mockFs.createWriteStream.mockReturnValue(tty);
process.env['SSH_CONNECTION'] = '1';
process.env['STY'] = 'screen-session';
await copyToClipboard(testText);
@@ -358,6 +360,21 @@ describe('commandUtils', () => {
expect(tty.end).not.toHaveBeenCalled();
});
it('uses clipboardy in tmux when not in SSH/WSL', async () => {
const tty = makeWritable({ isTTY: true });
mockFs.createWriteStream.mockReturnValue(tty);
const text = 'tmux-local';
mockClipboardyWrite.mockResolvedValue(undefined);
process.env['TMUX'] = '1';
await copyToClipboard(text);
expect(mockClipboardyWrite).toHaveBeenCalledWith(text);
expect(tty.write).not.toHaveBeenCalled();
expect(tty.end).not.toHaveBeenCalled();
});
it('skips /dev/tty on Windows and uses stderr fallback for OSC-52', async () => {
mockProcess.platform = 'win32';
const stderrStream = makeWritable({ isTTY: true });