@theia/terminal 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/base/terminal-service.d.ts +34 -34
  3. package/lib/browser/base/terminal-service.js +7 -7
  4. package/lib/browser/base/terminal-widget.d.ts +192 -192
  5. package/lib/browser/base/terminal-widget.js +34 -34
  6. package/lib/browser/index.d.ts +1 -1
  7. package/lib/browser/index.js +28 -28
  8. package/lib/browser/search/terminal-search-container.d.ts +3 -3
  9. package/lib/browser/search/terminal-search-container.js +28 -28
  10. package/lib/browser/search/terminal-search-widget.d.ts +30 -30
  11. package/lib/browser/search/terminal-search-widget.js +147 -147
  12. package/lib/browser/shell-terminal-profile.d.ts +20 -20
  13. package/lib/browser/shell-terminal-profile.js +42 -42
  14. package/lib/browser/terminal-contribution.d.ts +3 -3
  15. package/lib/browser/terminal-contribution.js +20 -20
  16. package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
  17. package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
  18. package/lib/browser/terminal-file-link-provider.d.ts +24 -24
  19. package/lib/browser/terminal-file-link-provider.js +200 -200
  20. package/lib/browser/terminal-frontend-contribution.d.ts +115 -115
  21. package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
  22. package/lib/browser/terminal-frontend-contribution.js +1078 -1056
  23. package/lib/browser/terminal-frontend-contribution.js.map +1 -1
  24. package/lib/browser/terminal-frontend-module.d.ts +5 -5
  25. package/lib/browser/terminal-frontend-module.js +117 -117
  26. package/lib/browser/terminal-link-helpers.d.ts +27 -27
  27. package/lib/browser/terminal-link-helpers.js +155 -155
  28. package/lib/browser/terminal-link-provider.d.ts +51 -51
  29. package/lib/browser/terminal-link-provider.js +197 -197
  30. package/lib/browser/terminal-preferences.d.ts +61 -61
  31. package/lib/browser/terminal-preferences.d.ts.map +1 -1
  32. package/lib/browser/terminal-preferences.js +357 -356
  33. package/lib/browser/terminal-preferences.js.map +1 -1
  34. package/lib/browser/terminal-profile-service.d.ts +58 -58
  35. package/lib/browser/terminal-profile-service.js +158 -158
  36. package/lib/browser/terminal-quick-open-service.d.ts +36 -36
  37. package/lib/browser/terminal-quick-open-service.js +137 -137
  38. package/lib/browser/terminal-theme-service.d.ts +21 -21
  39. package/lib/browser/terminal-theme-service.d.ts.map +1 -1
  40. package/lib/browser/terminal-theme-service.js +222 -218
  41. package/lib/browser/terminal-theme-service.js.map +1 -1
  42. package/lib/browser/terminal-url-link-provider.d.ts +11 -11
  43. package/lib/browser/terminal-url-link-provider.js +76 -76
  44. package/lib/browser/terminal-widget-impl.d.ts +180 -187
  45. package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
  46. package/lib/browser/terminal-widget-impl.js +857 -867
  47. package/lib/browser/terminal-widget-impl.js.map +1 -1
  48. package/lib/common/base-terminal-protocol.d.ts +55 -55
  49. package/lib/common/base-terminal-protocol.js +84 -84
  50. package/lib/common/shell-terminal-protocol.d.ts +66 -66
  51. package/lib/common/shell-terminal-protocol.js +35 -35
  52. package/lib/common/terminal-common-module.d.ts +7 -7
  53. package/lib/common/terminal-common-module.js +31 -31
  54. package/lib/common/terminal-protocol.d.ts +12 -12
  55. package/lib/common/terminal-protocol.js +21 -21
  56. package/lib/common/terminal-watcher.d.ts +13 -13
  57. package/lib/common/terminal-watcher.js +70 -70
  58. package/lib/node/base-terminal-server.d.ts +24 -24
  59. package/lib/node/base-terminal-server.js +168 -168
  60. package/lib/node/buffering-stream.d.ts +39 -39
  61. package/lib/node/buffering-stream.js +75 -75
  62. package/lib/node/buffering-stream.spec.d.ts +1 -1
  63. package/lib/node/buffering-stream.spec.js +43 -43
  64. package/lib/node/index.d.ts +1 -1
  65. package/lib/node/index.js +28 -28
  66. package/lib/node/shell-process.d.ts +27 -27
  67. package/lib/node/shell-process.js +107 -107
  68. package/lib/node/shell-process.js.map +1 -1
  69. package/lib/node/shell-terminal-server.d.ts +30 -30
  70. package/lib/node/shell-terminal-server.js +212 -212
  71. package/lib/node/shell-terminal-server.spec.d.ts +1 -1
  72. package/lib/node/shell-terminal-server.spec.js +35 -35
  73. package/lib/node/terminal-backend-contribution.d.ts +9 -9
  74. package/lib/node/terminal-backend-contribution.js +75 -75
  75. package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
  76. package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
  77. package/lib/node/terminal-backend-module.d.ts +11 -11
  78. package/lib/node/terminal-backend-module.js +69 -69
  79. package/lib/node/terminal-server.d.ts +9 -9
  80. package/lib/node/terminal-server.js +64 -64
  81. package/lib/node/terminal-server.spec.d.ts +1 -1
  82. package/lib/node/terminal-server.spec.js +41 -41
  83. package/lib/node/test/terminal-test-container.d.ts +2 -2
  84. package/lib/node/test/terminal-test-container.js +40 -40
  85. package/lib/package.spec.js +25 -25
  86. package/package.json +12 -12
  87. package/src/browser/base/terminal-service.ts +60 -60
  88. package/src/browser/base/terminal-widget.ts +254 -254
  89. package/src/browser/index.ts +17 -17
  90. package/src/browser/search/terminal-search-container.ts +28 -28
  91. package/src/browser/search/terminal-search-widget.tsx +161 -161
  92. package/src/browser/shell-terminal-profile.ts +45 -45
  93. package/src/browser/style/terminal-search.css +99 -99
  94. package/src/browser/style/terminal.css +32 -32
  95. package/src/browser/terminal-contribution.ts +19 -19
  96. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  97. package/src/browser/terminal-file-link-provider.ts +200 -200
  98. package/src/browser/terminal-frontend-contribution.ts +1120 -1098
  99. package/src/browser/terminal-frontend-module.ts +136 -136
  100. package/src/browser/terminal-link-helpers.ts +187 -187
  101. package/src/browser/terminal-link-provider.ts +203 -203
  102. package/src/browser/terminal-preferences.ts +428 -427
  103. package/src/browser/terminal-profile-service.ts +180 -180
  104. package/src/browser/terminal-quick-open-service.ts +132 -132
  105. package/src/browser/terminal-theme-service.ts +213 -209
  106. package/src/browser/terminal-url-link-provider.ts +66 -66
  107. package/src/browser/terminal-widget-impl.ts +939 -936
  108. package/src/common/base-terminal-protocol.ts +125 -125
  109. package/src/common/shell-terminal-protocol.ts +103 -103
  110. package/src/common/terminal-common-module.ts +30 -30
  111. package/src/common/terminal-protocol.ts +32 -32
  112. package/src/common/terminal-watcher.ts +69 -69
  113. package/src/node/base-terminal-server.ts +173 -173
  114. package/src/node/buffering-stream.spec.ts +46 -46
  115. package/src/node/buffering-stream.ts +95 -95
  116. package/src/node/index.ts +17 -17
  117. package/src/node/shell-process.ts +101 -101
  118. package/src/node/shell-terminal-server.spec.ts +40 -40
  119. package/src/node/shell-terminal-server.ts +221 -221
  120. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  121. package/src/node/terminal-backend-contribution.ts +60 -60
  122. package/src/node/terminal-backend-module.ts +82 -82
  123. package/src/node/terminal-server.spec.ts +47 -47
  124. package/src/node/terminal-server.ts +52 -52
  125. package/src/node/test/terminal-test-container.ts +39 -39
  126. package/src/package.spec.ts +28 -28
@@ -1,169 +1,169 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.BaseTerminalServer = void 0;
31
- const inversify_1 = require("@theia/core/shared/inversify");
32
- const common_1 = require("@theia/core/lib/common");
33
- const base_terminal_protocol_1 = require("../common/base-terminal-protocol");
34
- const node_1 = require("@theia/process/lib/node");
35
- const shell_process_1 = require("./shell-process");
36
- let BaseTerminalServer = class BaseTerminalServer {
37
- constructor(processManager, logger) {
38
- this.processManager = processManager;
39
- this.logger = logger;
40
- this.client = undefined;
41
- this.terminalToDispose = new Map();
42
- processManager.onDelete(id => {
43
- const toDispose = this.terminalToDispose.get(id);
44
- if (toDispose !== undefined) {
45
- toDispose.dispose();
46
- this.terminalToDispose.delete(id);
47
- }
48
- });
49
- }
50
- async attach(id) {
51
- const term = this.processManager.get(id);
52
- if (term && term instanceof node_1.TerminalProcess) {
53
- return term.id;
54
- }
55
- else {
56
- this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
57
- return -1;
58
- }
59
- }
60
- async onAttachAttempted(id) {
61
- const terminal = this.processManager.get(id);
62
- if (terminal instanceof node_1.TaskTerminalProcess) {
63
- terminal.attachmentAttempted = true;
64
- if (terminal.exited) {
65
- // Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
66
- // Fixes https://github.com/eclipse-theia/theia/issues/2961
67
- terminal.unregisterProcess();
68
- }
69
- else {
70
- this.postAttachAttempted(terminal);
71
- }
72
- }
73
- }
74
- async getProcessId(id) {
75
- const terminal = this.processManager.get(id);
76
- if (!(terminal instanceof node_1.TerminalProcess)) {
77
- throw new Error(`terminal "${id}" does not exist`);
78
- }
79
- return terminal.pid;
80
- }
81
- async getProcessInfo(id) {
82
- const terminal = this.processManager.get(id);
83
- if (!(terminal instanceof node_1.TerminalProcess)) {
84
- throw new Error(`terminal "${id}" does not exist`);
85
- }
86
- return {
87
- executable: terminal.executable,
88
- arguments: terminal.arguments,
89
- };
90
- }
91
- async getCwdURI(id) {
92
- const terminal = this.processManager.get(id);
93
- if (!(terminal instanceof node_1.TerminalProcess)) {
94
- throw new Error(`terminal "${id}" does not exist`);
95
- }
96
- return terminal.getCwdURI();
97
- }
98
- async close(id) {
99
- const term = this.processManager.get(id);
100
- if (term instanceof node_1.TerminalProcess) {
101
- term.kill();
102
- }
103
- }
104
- async getDefaultShell() {
105
- return shell_process_1.ShellProcess.getShellExecutablePath();
106
- }
107
- dispose() {
108
- // noop
109
- }
110
- async resize(id, cols, rows) {
111
- const term = this.processManager.get(id);
112
- if (term && term instanceof node_1.TerminalProcess) {
113
- term.resize(cols, rows);
114
- }
115
- else {
116
- console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
117
- }
118
- }
119
- /* Set the client to receive notifications on. */
120
- setClient(client) {
121
- this.client = client;
122
- if (!this.client) {
123
- return;
124
- }
125
- this.client.updateTerminalEnvVariables();
126
- }
127
- notifyClientOnExit(term) {
128
- const toDispose = new common_1.DisposableCollection();
129
- toDispose.push(term.onError(error => {
130
- this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
131
- if (this.client !== undefined) {
132
- this.client.onTerminalError({
133
- terminalId: term.id,
134
- error: new Error(`Failed to execute terminal process (${error.code})`),
135
- attached: term instanceof node_1.TaskTerminalProcess && term.attachmentAttempted
136
- });
137
- }
138
- }));
139
- toDispose.push(term.onExit(event => {
140
- if (this.client !== undefined) {
141
- this.client.onTerminalExitChanged({
142
- terminalId: term.id,
143
- code: event.code,
144
- reason: base_terminal_protocol_1.TerminalExitReason.Process,
145
- signal: event.signal,
146
- attached: term instanceof node_1.TaskTerminalProcess && term.attachmentAttempted
147
- });
148
- }
149
- }));
150
- return toDispose;
151
- }
152
- postCreate(term) {
153
- const toDispose = this.notifyClientOnExit(term);
154
- this.terminalToDispose.set(term.id, toDispose);
155
- }
156
- postAttachAttempted(term) {
157
- const toDispose = this.notifyClientOnExit(term);
158
- this.terminalToDispose.set(term.id, toDispose);
159
- }
160
- };
161
- BaseTerminalServer = __decorate([
162
- (0, inversify_1.injectable)(),
163
- __param(0, (0, inversify_1.inject)(node_1.ProcessManager)),
164
- __param(1, (0, inversify_1.inject)(common_1.ILogger)),
165
- __param(1, (0, inversify_1.named)('terminal')),
166
- __metadata("design:paramtypes", [node_1.ProcessManager, Object])
167
- ], BaseTerminalServer);
168
- exports.BaseTerminalServer = BaseTerminalServer;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.BaseTerminalServer = void 0;
31
+ const inversify_1 = require("@theia/core/shared/inversify");
32
+ const common_1 = require("@theia/core/lib/common");
33
+ const base_terminal_protocol_1 = require("../common/base-terminal-protocol");
34
+ const node_1 = require("@theia/process/lib/node");
35
+ const shell_process_1 = require("./shell-process");
36
+ let BaseTerminalServer = class BaseTerminalServer {
37
+ constructor(processManager, logger) {
38
+ this.processManager = processManager;
39
+ this.logger = logger;
40
+ this.client = undefined;
41
+ this.terminalToDispose = new Map();
42
+ processManager.onDelete(id => {
43
+ const toDispose = this.terminalToDispose.get(id);
44
+ if (toDispose !== undefined) {
45
+ toDispose.dispose();
46
+ this.terminalToDispose.delete(id);
47
+ }
48
+ });
49
+ }
50
+ async attach(id) {
51
+ const term = this.processManager.get(id);
52
+ if (term && term instanceof node_1.TerminalProcess) {
53
+ return term.id;
54
+ }
55
+ else {
56
+ this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
57
+ return -1;
58
+ }
59
+ }
60
+ async onAttachAttempted(id) {
61
+ const terminal = this.processManager.get(id);
62
+ if (terminal instanceof node_1.TaskTerminalProcess) {
63
+ terminal.attachmentAttempted = true;
64
+ if (terminal.exited) {
65
+ // Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
66
+ // Fixes https://github.com/eclipse-theia/theia/issues/2961
67
+ terminal.unregisterProcess();
68
+ }
69
+ else {
70
+ this.postAttachAttempted(terminal);
71
+ }
72
+ }
73
+ }
74
+ async getProcessId(id) {
75
+ const terminal = this.processManager.get(id);
76
+ if (!(terminal instanceof node_1.TerminalProcess)) {
77
+ throw new Error(`terminal "${id}" does not exist`);
78
+ }
79
+ return terminal.pid;
80
+ }
81
+ async getProcessInfo(id) {
82
+ const terminal = this.processManager.get(id);
83
+ if (!(terminal instanceof node_1.TerminalProcess)) {
84
+ throw new Error(`terminal "${id}" does not exist`);
85
+ }
86
+ return {
87
+ executable: terminal.executable,
88
+ arguments: terminal.arguments,
89
+ };
90
+ }
91
+ async getCwdURI(id) {
92
+ const terminal = this.processManager.get(id);
93
+ if (!(terminal instanceof node_1.TerminalProcess)) {
94
+ throw new Error(`terminal "${id}" does not exist`);
95
+ }
96
+ return terminal.getCwdURI();
97
+ }
98
+ async close(id) {
99
+ const term = this.processManager.get(id);
100
+ if (term instanceof node_1.TerminalProcess) {
101
+ term.kill();
102
+ }
103
+ }
104
+ async getDefaultShell() {
105
+ return shell_process_1.ShellProcess.getShellExecutablePath();
106
+ }
107
+ dispose() {
108
+ // noop
109
+ }
110
+ async resize(id, cols, rows) {
111
+ const term = this.processManager.get(id);
112
+ if (term && term instanceof node_1.TerminalProcess) {
113
+ term.resize(cols, rows);
114
+ }
115
+ else {
116
+ console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
117
+ }
118
+ }
119
+ /* Set the client to receive notifications on. */
120
+ setClient(client) {
121
+ this.client = client;
122
+ if (!this.client) {
123
+ return;
124
+ }
125
+ this.client.updateTerminalEnvVariables();
126
+ }
127
+ notifyClientOnExit(term) {
128
+ const toDispose = new common_1.DisposableCollection();
129
+ toDispose.push(term.onError(error => {
130
+ this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
131
+ if (this.client !== undefined) {
132
+ this.client.onTerminalError({
133
+ terminalId: term.id,
134
+ error: new Error(`Failed to execute terminal process (${error.code})`),
135
+ attached: term instanceof node_1.TaskTerminalProcess && term.attachmentAttempted
136
+ });
137
+ }
138
+ }));
139
+ toDispose.push(term.onExit(event => {
140
+ if (this.client !== undefined) {
141
+ this.client.onTerminalExitChanged({
142
+ terminalId: term.id,
143
+ code: event.code,
144
+ reason: base_terminal_protocol_1.TerminalExitReason.Process,
145
+ signal: event.signal,
146
+ attached: term instanceof node_1.TaskTerminalProcess && term.attachmentAttempted
147
+ });
148
+ }
149
+ }));
150
+ return toDispose;
151
+ }
152
+ postCreate(term) {
153
+ const toDispose = this.notifyClientOnExit(term);
154
+ this.terminalToDispose.set(term.id, toDispose);
155
+ }
156
+ postAttachAttempted(term) {
157
+ const toDispose = this.notifyClientOnExit(term);
158
+ this.terminalToDispose.set(term.id, toDispose);
159
+ }
160
+ };
161
+ BaseTerminalServer = __decorate([
162
+ (0, inversify_1.injectable)(),
163
+ __param(0, (0, inversify_1.inject)(node_1.ProcessManager)),
164
+ __param(1, (0, inversify_1.inject)(common_1.ILogger)),
165
+ __param(1, (0, inversify_1.named)('terminal')),
166
+ __metadata("design:paramtypes", [node_1.ProcessManager, Object])
167
+ ], BaseTerminalServer);
168
+ exports.BaseTerminalServer = BaseTerminalServer;
169
169
  //# sourceMappingURL=base-terminal-server.js.map
@@ -1,40 +1,40 @@
1
- /// <reference types="node" />
2
- import { Emitter, Event } from '@theia/core/lib/common/event';
3
- export interface BufferingStreamOptions {
4
- /**
5
- * Max size in bytes of the chunks being emitted.
6
- */
7
- maxChunkSize?: number;
8
- /**
9
- * Amount of time in milliseconds to wait between the moment we start
10
- * buffering data and when we emit the buffered chunk.
11
- */
12
- emitInterval?: number;
13
- }
14
- /**
15
- * This component will buffer whatever is pushed to it and emit chunks back
16
- * every {@link BufferingStreamOptions.emitInterval}. It will also ensure that
17
- * the emitted chunks never exceed {@link BufferingStreamOptions.maxChunkSize}.
18
- */
19
- export declare class BufferingStream<T> {
20
- protected buffer?: T;
21
- protected timeout?: NodeJS.Timeout;
22
- protected maxChunkSize: number;
23
- protected emitInterval: number;
24
- protected onDataEmitter: Emitter<T>;
25
- protected readonly concat: (left: T, right: T) => T;
26
- protected readonly slice: (what: T, start?: number, end?: number) => T;
27
- protected readonly length: (what: T) => number;
28
- constructor(options: BufferingStreamOptions | undefined, concat: (left: T, right: T) => T, slice: (what: T, start?: number, end?: number) => T, length: (what: T) => number);
29
- get onData(): Event<T>;
30
- push(chunk: T): void;
31
- dispose(): void;
32
- protected emitBufferedChunk(): void;
33
- }
34
- export declare class StringBufferingStream extends BufferingStream<string> {
35
- constructor(options?: BufferingStreamOptions);
36
- }
37
- export declare class BufferBufferingStream extends BufferingStream<Buffer> {
38
- constructor(options?: BufferingStreamOptions);
39
- }
1
+ /// <reference types="node" />
2
+ import { Emitter, Event } from '@theia/core/lib/common/event';
3
+ export interface BufferingStreamOptions {
4
+ /**
5
+ * Max size in bytes of the chunks being emitted.
6
+ */
7
+ maxChunkSize?: number;
8
+ /**
9
+ * Amount of time in milliseconds to wait between the moment we start
10
+ * buffering data and when we emit the buffered chunk.
11
+ */
12
+ emitInterval?: number;
13
+ }
14
+ /**
15
+ * This component will buffer whatever is pushed to it and emit chunks back
16
+ * every {@link BufferingStreamOptions.emitInterval}. It will also ensure that
17
+ * the emitted chunks never exceed {@link BufferingStreamOptions.maxChunkSize}.
18
+ */
19
+ export declare class BufferingStream<T> {
20
+ protected buffer?: T;
21
+ protected timeout?: NodeJS.Timeout;
22
+ protected maxChunkSize: number;
23
+ protected emitInterval: number;
24
+ protected onDataEmitter: Emitter<T>;
25
+ protected readonly concat: (left: T, right: T) => T;
26
+ protected readonly slice: (what: T, start?: number, end?: number) => T;
27
+ protected readonly length: (what: T) => number;
28
+ constructor(options: BufferingStreamOptions | undefined, concat: (left: T, right: T) => T, slice: (what: T, start?: number, end?: number) => T, length: (what: T) => number);
29
+ get onData(): Event<T>;
30
+ push(chunk: T): void;
31
+ dispose(): void;
32
+ protected emitBufferedChunk(): void;
33
+ }
34
+ export declare class StringBufferingStream extends BufferingStream<string> {
35
+ constructor(options?: BufferingStreamOptions);
36
+ }
37
+ export declare class BufferBufferingStream extends BufferingStream<Buffer> {
38
+ constructor(options?: BufferingStreamOptions);
39
+ }
40
40
  //# sourceMappingURL=buffering-stream.d.ts.map
@@ -1,76 +1,76 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2022 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.BufferBufferingStream = exports.StringBufferingStream = exports.BufferingStream = void 0;
19
- const event_1 = require("@theia/core/lib/common/event");
20
- /**
21
- * This component will buffer whatever is pushed to it and emit chunks back
22
- * every {@link BufferingStreamOptions.emitInterval}. It will also ensure that
23
- * the emitted chunks never exceed {@link BufferingStreamOptions.maxChunkSize}.
24
- */
25
- class BufferingStream {
26
- constructor(options = {}, concat, slice, length) {
27
- var _a, _b;
28
- this.onDataEmitter = new event_1.Emitter();
29
- this.emitInterval = (_a = options.emitInterval) !== null && _a !== void 0 ? _a : 16; // ms
30
- this.maxChunkSize = (_b = options.maxChunkSize) !== null && _b !== void 0 ? _b : (256 * 1024); // bytes
31
- this.concat = concat;
32
- this.slice = slice;
33
- this.length = length;
34
- }
35
- get onData() {
36
- return this.onDataEmitter.event;
37
- }
38
- push(chunk) {
39
- if (this.buffer) {
40
- this.buffer = this.concat(this.buffer, chunk);
41
- }
42
- else {
43
- this.buffer = chunk;
44
- this.timeout = setTimeout(() => this.emitBufferedChunk(), this.emitInterval);
45
- }
46
- }
47
- dispose() {
48
- clearTimeout(this.timeout);
49
- this.buffer = undefined;
50
- this.onDataEmitter.dispose();
51
- }
52
- emitBufferedChunk() {
53
- this.onDataEmitter.fire(this.slice(this.buffer, 0, this.maxChunkSize));
54
- if (this.length(this.buffer) <= this.maxChunkSize) {
55
- this.buffer = undefined;
56
- }
57
- else {
58
- this.buffer = this.slice(this.buffer, this.maxChunkSize);
59
- this.timeout = setTimeout(() => this.emitBufferedChunk(), this.emitInterval);
60
- }
61
- }
62
- }
63
- exports.BufferingStream = BufferingStream;
64
- class StringBufferingStream extends BufferingStream {
65
- constructor(options = {}) {
66
- super(options, (left, right) => left.concat(right), (what, start, end) => what.slice(start, end), what => what.length);
67
- }
68
- }
69
- exports.StringBufferingStream = StringBufferingStream;
70
- class BufferBufferingStream extends BufferingStream {
71
- constructor(options = {}) {
72
- super(options, (left, right) => Buffer.concat([left, right]), (what, start, end) => what.slice(start, end), what => what.length);
73
- }
74
- }
75
- exports.BufferBufferingStream = BufferBufferingStream;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2022 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BufferBufferingStream = exports.StringBufferingStream = exports.BufferingStream = void 0;
19
+ const event_1 = require("@theia/core/lib/common/event");
20
+ /**
21
+ * This component will buffer whatever is pushed to it and emit chunks back
22
+ * every {@link BufferingStreamOptions.emitInterval}. It will also ensure that
23
+ * the emitted chunks never exceed {@link BufferingStreamOptions.maxChunkSize}.
24
+ */
25
+ class BufferingStream {
26
+ constructor(options = {}, concat, slice, length) {
27
+ var _a, _b;
28
+ this.onDataEmitter = new event_1.Emitter();
29
+ this.emitInterval = (_a = options.emitInterval) !== null && _a !== void 0 ? _a : 16; // ms
30
+ this.maxChunkSize = (_b = options.maxChunkSize) !== null && _b !== void 0 ? _b : (256 * 1024); // bytes
31
+ this.concat = concat;
32
+ this.slice = slice;
33
+ this.length = length;
34
+ }
35
+ get onData() {
36
+ return this.onDataEmitter.event;
37
+ }
38
+ push(chunk) {
39
+ if (this.buffer) {
40
+ this.buffer = this.concat(this.buffer, chunk);
41
+ }
42
+ else {
43
+ this.buffer = chunk;
44
+ this.timeout = setTimeout(() => this.emitBufferedChunk(), this.emitInterval);
45
+ }
46
+ }
47
+ dispose() {
48
+ clearTimeout(this.timeout);
49
+ this.buffer = undefined;
50
+ this.onDataEmitter.dispose();
51
+ }
52
+ emitBufferedChunk() {
53
+ this.onDataEmitter.fire(this.slice(this.buffer, 0, this.maxChunkSize));
54
+ if (this.length(this.buffer) <= this.maxChunkSize) {
55
+ this.buffer = undefined;
56
+ }
57
+ else {
58
+ this.buffer = this.slice(this.buffer, this.maxChunkSize);
59
+ this.timeout = setTimeout(() => this.emitBufferedChunk(), this.emitInterval);
60
+ }
61
+ }
62
+ }
63
+ exports.BufferingStream = BufferingStream;
64
+ class StringBufferingStream extends BufferingStream {
65
+ constructor(options = {}) {
66
+ super(options, (left, right) => left.concat(right), (what, start, end) => what.slice(start, end), what => what.length);
67
+ }
68
+ }
69
+ exports.StringBufferingStream = StringBufferingStream;
70
+ class BufferBufferingStream extends BufferingStream {
71
+ constructor(options = {}) {
72
+ super(options, (left, right) => Buffer.concat([left, right]), (what, start, end) => what.slice(start, end), what => what.length);
73
+ }
74
+ }
75
+ exports.BufferBufferingStream = BufferBufferingStream;
76
76
  //# sourceMappingURL=buffering-stream.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=buffering-stream.spec.d.ts.map