Skip to content

Commit 0e6e556

Browse files
committed
More chunkInput into common
1 parent 99f246d commit 0e6e556

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

src/vs/platform/terminal/common/terminalProcess.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,41 @@ export interface ReplayEntry {
6767
rows: number;
6868
data: string;
6969
}
70+
71+
const enum Constants {
72+
/**
73+
* Writing large amounts of data can be corrupted for some reason, after looking into this is
74+
* appears to be a race condition around writing to the FD which may be based on how powerful
75+
* the hardware is. The workaround for this is to space out when large amounts of data is being
76+
* written to the terminal. See https://github.com/microsoft/vscode/issues/38137
77+
*/
78+
WriteMaxChunkSize = 50,
79+
}
80+
81+
/**
82+
* Splits incoming pty data into chunks to try prevent data corruption that could occur when pasting
83+
* large amounts of data.
84+
*/
85+
export function chunkInput(data: string): string[] {
86+
const chunks: string[] = [];
87+
let nextChunkStartIndex = 0;
88+
for (let i = 0; i < data.length - 1; i++) {
89+
if (
90+
// If the max chunk size is reached
91+
i - nextChunkStartIndex + 1 >= Constants.WriteMaxChunkSize ||
92+
// If the next character is ESC, send the pending data to avoid splitting the escape
93+
// sequence.
94+
data[i + 1] === '\x1b'
95+
) {
96+
chunks.push(data.substring(nextChunkStartIndex, i + 1));
97+
nextChunkStartIndex = i + 1;
98+
// Skip the next character as the chunk would be a single character
99+
i++;
100+
}
101+
}
102+
// Push final chunk
103+
if (nextChunkStartIndex !== data.length) {
104+
chunks.push(data.substring(nextChunkStartIndex));
105+
}
106+
return chunks;
107+
}

src/vs/platform/terminal/node/terminalProcess.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ChildProcessMonitor } from 'vs/platform/terminal/node/childProcessMonit
1919
import { findExecutable, getShellIntegrationInjection, getWindowsBuildNumber, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment';
2020
import { WindowsShellHelper } from 'vs/platform/terminal/node/windowsShellHelper';
2121
import { IPty, IPtyForkOptions, IWindowsPtyForkOptions, spawn } from 'node-pty';
22+
import { chunkInput } from 'vs/platform/terminal/common/terminalProcess';
2223

2324
const enum ShutdownConstants {
2425
/**
@@ -54,14 +55,6 @@ const enum Constants {
5455
* interval.
5556
*/
5657
KillSpawnSpacingDuration = 50,
57-
58-
/**
59-
* Writing large amounts of data can be corrupted for some reason, after looking into this is
60-
* appears to be a race condition around writing to the FD which may be based on how powerful
61-
* the hardware is. The workaround for this is to space out when large amounts of data is being
62-
* written to the terminal. See https://github.com/microsoft/vscode/issues/38137
63-
*/
64-
WriteMaxChunkSize = 50,
6558
/**
6659
* How long to wait between chunk writes.
6760
*/
@@ -645,31 +638,3 @@ class DelayedResizer extends Disposable {
645638
this._register(toDisposable(() => clearTimeout(this._timeout)));
646639
}
647640
}
648-
649-
/**
650-
* Splits incoming pty data into chunks to try prevent data corruption that could occur when pasting
651-
* large amounts of data.
652-
*/
653-
export function chunkInput(data: string): string[] {
654-
const chunks: string[] = [];
655-
let nextChunkStartIndex = 0;
656-
for (let i = 0; i < data.length - 1; i++) {
657-
if (
658-
// If the max chunk size is reached
659-
i - nextChunkStartIndex + 1 >= Constants.WriteMaxChunkSize ||
660-
// If the next character is ESC, send the pending data to avoid splitting the escape
661-
// sequence.
662-
data[i + 1] === '\x1b'
663-
) {
664-
chunks.push(data.substring(nextChunkStartIndex, i + 1));
665-
nextChunkStartIndex = i + 1;
666-
// Skip the next character as the chunk would be a single character
667-
i++;
668-
}
669-
}
670-
// Push final chunk
671-
if (nextChunkStartIndex !== data.length) {
672-
chunks.push(data.substring(nextChunkStartIndex));
673-
}
674-
return chunks;
675-
}

src/vs/platform/terminal/test/node/terminalProcess.test.ts renamed to src/vs/platform/terminal/test/common/terminalProcess.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { deepStrictEqual } from 'assert';
77
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
8-
import { chunkInput } from 'vs/platform/terminal/node/terminalProcess';
8+
import { chunkInput } from 'vs/platform/terminal/common/terminalProcess';
99

1010
suite('platform - terminalProcess', () => {
1111
ensureNoDisposablesAreLeakedInTestSuite();

0 commit comments

Comments
 (0)