@opensumi/ide-terminal-next 3.7.2-next-1740052080.0 → 3.7.2-next-1740054042.0

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 (244) hide show
  1. package/LICENSE +21 -0
  2. package/lib/browser/component/resize.delegate.d.ts +14 -0
  3. package/lib/browser/component/resize.delegate.d.ts.map +1 -0
  4. package/lib/browser/component/resize.delegate.js +46 -0
  5. package/lib/browser/component/resize.delegate.js.map +1 -0
  6. package/lib/browser/component/resize.module.less +77 -0
  7. package/lib/browser/component/resize.view.d.ts +16 -0
  8. package/lib/browser/component/resize.view.d.ts.map +1 -0
  9. package/lib/browser/component/resize.view.js +55 -0
  10. package/lib/browser/component/resize.view.js.map +1 -0
  11. package/lib/browser/component/search.module.less +61 -0
  12. package/lib/browser/component/search.view.d.ts +3 -0
  13. package/lib/browser/component/search.view.d.ts.map +1 -0
  14. package/lib/browser/component/search.view.js +89 -0
  15. package/lib/browser/component/search.view.js.map +1 -0
  16. package/lib/browser/component/tab.item.d.ts +7 -0
  17. package/lib/browser/component/tab.item.d.ts.map +1 -0
  18. package/lib/browser/component/tab.item.js +121 -0
  19. package/lib/browser/component/tab.item.js.map +1 -0
  20. package/lib/browser/component/tab.module.less +174 -0
  21. package/lib/browser/component/tab.view.d.ts +4 -0
  22. package/lib/browser/component/tab.view.d.ts.map +1 -0
  23. package/lib/browser/component/tab.view.js +65 -0
  24. package/lib/browser/component/tab.view.js.map +1 -0
  25. package/lib/browser/component/terminal.module.less +50 -0
  26. package/lib/browser/component/terminal.variable.d.ts +8 -0
  27. package/lib/browser/component/terminal.variable.d.ts.map +1 -0
  28. package/lib/browser/component/terminal.variable.js +44 -0
  29. package/lib/browser/component/terminal.variable.js.map +1 -0
  30. package/lib/browser/component/terminal.view.d.ts +5 -0
  31. package/lib/browser/component/terminal.view.d.ts.map +1 -0
  32. package/lib/browser/component/terminal.view.js +63 -0
  33. package/lib/browser/component/terminal.view.js.map +1 -0
  34. package/lib/browser/component/terminal.widget.d.ts +10 -0
  35. package/lib/browser/component/terminal.widget.d.ts.map +1 -0
  36. package/lib/browser/component/terminal.widget.js +65 -0
  37. package/lib/browser/component/terminal.widget.js.map +1 -0
  38. package/lib/browser/component/variable.module.less +15 -0
  39. package/lib/browser/contribution/index.d.ts.map +1 -0
  40. package/lib/browser/contribution/index.js +11 -0
  41. package/lib/browser/contribution/index.js.map +1 -0
  42. package/lib/browser/contribution/terminal.command.js +328 -0
  43. package/lib/browser/contribution/terminal.keybinding.js +87 -0
  44. package/lib/browser/contribution/terminal.lifecycle.js +52 -0
  45. package/lib/browser/contribution/terminal.menu.js +168 -0
  46. package/lib/browser/contribution/terminal.network.js +44 -0
  47. package/lib/browser/contribution/terminal.preference.js +43 -0
  48. package/lib/browser/contribution/terminal.view.js +57 -0
  49. package/lib/browser/index.js +124 -0
  50. package/lib/browser/links/base.d.ts +8 -0
  51. package/lib/browser/links/base.d.ts.map +1 -0
  52. package/lib/browser/links/base.js +13 -0
  53. package/lib/browser/links/base.js.map +1 -0
  54. package/lib/browser/links/external-link-provider-adapter.d.ts +21 -0
  55. package/lib/browser/links/external-link-provider-adapter.d.ts.map +1 -0
  56. package/lib/browser/links/external-link-provider-adapter.js +74 -0
  57. package/lib/browser/links/external-link-provider-adapter.js.map +1 -0
  58. package/lib/browser/links/helpers.d.ts +7 -0
  59. package/lib/browser/links/helpers.d.ts.map +1 -0
  60. package/lib/browser/links/helpers.js +128 -0
  61. package/lib/browser/links/helpers.js.map +1 -0
  62. package/lib/browser/links/link-manager.d.ts +92 -0
  63. package/lib/browser/links/link-manager.d.ts.map +1 -0
  64. package/lib/browser/links/link-manager.js +342 -0
  65. package/lib/browser/links/link-manager.js.map +1 -0
  66. package/lib/browser/links/link.d.ts +31 -0
  67. package/lib/browser/links/link.d.ts.map +1 -0
  68. package/lib/browser/links/link.js +136 -0
  69. package/lib/browser/links/link.js.map +1 -0
  70. package/lib/browser/links/protocol-link-provider.d.ts +14 -0
  71. package/lib/browser/links/protocol-link-provider.d.ts.map +1 -0
  72. package/lib/browser/links/protocol-link-provider.js +71 -0
  73. package/lib/browser/links/protocol-link-provider.js.map +1 -0
  74. package/lib/browser/links/validated-local-link-provider.d.ts +41 -0
  75. package/lib/browser/links/validated-local-link-provider.d.ts.map +1 -0
  76. package/lib/browser/links/validated-local-link-provider.js +235 -0
  77. package/lib/browser/links/validated-local-link-provider.js.map +1 -0
  78. package/lib/browser/links/word-link-provider.d.ts +29 -0
  79. package/lib/browser/links/word-link-provider.d.ts.map +1 -0
  80. package/lib/browser/links/word-link-provider.js +153 -0
  81. package/lib/browser/links/word-link-provider.js.map +1 -0
  82. package/lib/browser/terminal.addon.js +83 -0
  83. package/lib/browser/terminal.api.js +162 -0
  84. package/lib/browser/terminal.client.js +680 -0
  85. package/lib/browser/terminal.color.js +240 -0
  86. package/lib/browser/terminal.context-key.js +29 -0
  87. package/lib/browser/terminal.context-menu.js +96 -0
  88. package/lib/browser/terminal.controller.js +669 -0
  89. package/lib/browser/terminal.environment.service.js +153 -0
  90. package/lib/browser/terminal.error.js +61 -0
  91. package/lib/browser/terminal.ext.host.proxy.js +108 -0
  92. package/lib/browser/terminal.hover.manager.js +85 -0
  93. package/lib/browser/terminal.input.js +32 -0
  94. package/lib/browser/terminal.internal.service.js +107 -0
  95. package/lib/browser/terminal.network.js +150 -0
  96. package/lib/browser/terminal.preference.js +136 -0
  97. package/lib/browser/terminal.profile.internal.js +104 -0
  98. package/lib/browser/terminal.profile.js +211 -0
  99. package/lib/browser/terminal.render.js +25 -0
  100. package/lib/browser/terminal.restore.js +49 -0
  101. package/lib/browser/terminal.search.js +109 -0
  102. package/lib/browser/terminal.service.js +163 -0
  103. package/lib/common/api.d.ts +22 -0
  104. package/lib/common/api.d.ts.map +1 -0
  105. package/lib/common/api.js +5 -0
  106. package/lib/common/api.js.map +1 -0
  107. package/lib/common/client.d.ts +199 -0
  108. package/lib/common/client.d.ts.map +1 -0
  109. package/lib/common/client.js +6 -0
  110. package/lib/common/client.js.map +1 -0
  111. package/lib/common/controller.d.ts +149 -0
  112. package/lib/common/controller.d.ts.map +1 -0
  113. package/lib/common/controller.js +8 -0
  114. package/lib/common/controller.js.map +1 -0
  115. package/lib/common/environmentVariable.d.ts +116 -0
  116. package/lib/common/environmentVariable.d.ts.map +1 -0
  117. package/lib/common/environmentVariable.js +30 -0
  118. package/lib/common/environmentVariable.js.map +1 -0
  119. package/lib/common/environmentVariableCollection.d.ts +9 -0
  120. package/lib/common/environmentVariableCollection.d.ts.map +1 -0
  121. package/lib/common/environmentVariableCollection.js +140 -0
  122. package/lib/common/environmentVariableCollection.js.map +1 -0
  123. package/lib/common/error.d.ts +41 -0
  124. package/lib/common/error.d.ts.map +1 -0
  125. package/lib/common/error.js +13 -0
  126. package/lib/common/error.js.map +1 -0
  127. package/lib/common/extension.d.ts +139 -0
  128. package/lib/common/extension.d.ts.map +1 -0
  129. package/lib/common/extension.js +57 -0
  130. package/lib/common/extension.js.map +1 -0
  131. package/lib/common/index.d.ts +17 -0
  132. package/lib/common/index.d.ts.map +1 -0
  133. package/lib/common/index.js +20 -0
  134. package/lib/common/index.js.map +1 -0
  135. package/lib/common/link-computer.d.ts +56 -0
  136. package/lib/common/link-computer.d.ts.map +1 -0
  137. package/lib/common/link-computer.js +282 -0
  138. package/lib/common/link-computer.js.map +1 -0
  139. package/lib/common/network.d.ts +48 -0
  140. package/lib/common/network.d.ts.map +1 -0
  141. package/lib/common/network.js +10 -0
  142. package/lib/common/network.js.map +1 -0
  143. package/lib/common/preference.d.ts +134 -0
  144. package/lib/common/preference.d.ts.map +1 -0
  145. package/lib/common/preference.js +199 -0
  146. package/lib/common/preference.js.map +1 -0
  147. package/lib/common/process.d.ts +8 -0
  148. package/lib/common/process.d.ts.map +1 -0
  149. package/lib/common/process.js +3 -0
  150. package/lib/common/process.js.map +1 -0
  151. package/lib/common/profile.d.ts +99 -0
  152. package/lib/common/profile.d.ts.map +1 -0
  153. package/lib/common/profile.js +27 -0
  154. package/lib/common/profile.js.map +1 -0
  155. package/lib/common/pty.d.ts +525 -0
  156. package/lib/common/pty.d.ts.map +1 -0
  157. package/lib/common/pty.js +28 -0
  158. package/lib/common/pty.js.map +1 -0
  159. package/lib/common/render.d.ts +29 -0
  160. package/lib/common/render.d.ts.map +1 -0
  161. package/lib/common/render.js +10 -0
  162. package/lib/common/render.js.map +1 -0
  163. package/lib/common/resize.d.ts +43 -0
  164. package/lib/common/resize.d.ts.map +1 -0
  165. package/lib/common/resize.js +3 -0
  166. package/lib/common/resize.js.map +1 -0
  167. package/lib/common/restore.d.ts +6 -0
  168. package/lib/common/restore.d.ts.map +1 -0
  169. package/lib/common/restore.js +5 -0
  170. package/lib/common/restore.js.map +1 -0
  171. package/lib/common/service.d.ts +96 -0
  172. package/lib/common/service.d.ts.map +1 -0
  173. package/lib/common/service.js +6 -0
  174. package/lib/common/service.js.map +1 -0
  175. package/lib/common/shell.d.ts +11 -0
  176. package/lib/common/shell.d.ts.map +1 -0
  177. package/lib/common/shell.js +14 -0
  178. package/lib/common/shell.js.map +1 -0
  179. package/lib/common/theme.d.ts +6 -0
  180. package/lib/common/theme.d.ts.map +1 -0
  181. package/lib/common/theme.js +5 -0
  182. package/lib/common/theme.js.map +1 -0
  183. package/lib/common/utils.d.ts +4 -0
  184. package/lib/common/utils.d.ts.map +1 -0
  185. package/lib/common/utils.js +15 -0
  186. package/lib/common/utils.js.map +1 -0
  187. package/lib/common/xterm.d.ts +27 -0
  188. package/lib/common/xterm.d.ts.map +1 -0
  189. package/lib/common/xterm.js +10 -0
  190. package/lib/common/xterm.js.map +1 -0
  191. package/lib/index.js +5 -0
  192. package/lib/node/data-store.d.ts +13 -0
  193. package/lib/node/data-store.d.ts.map +1 -0
  194. package/lib/node/data-store.js +6 -0
  195. package/lib/node/data-store.js.map +1 -0
  196. package/lib/node/index.d.ts +10 -0
  197. package/lib/node/index.d.ts.map +1 -0
  198. package/lib/node/index.js +64 -0
  199. package/lib/node/index.js.map +1 -0
  200. package/lib/node/pty.d.ts +42 -0
  201. package/lib/node/pty.d.ts.map +1 -0
  202. package/lib/node/pty.js +277 -0
  203. package/lib/node/pty.js.map +1 -0
  204. package/lib/node/pty.manager.d.ts +52 -0
  205. package/lib/node/pty.manager.d.ts.map +1 -0
  206. package/lib/node/pty.manager.js +157 -0
  207. package/lib/node/pty.manager.js.map +1 -0
  208. package/lib/node/pty.manager.remote.d.ts +23 -0
  209. package/lib/node/pty.manager.remote.d.ts.map +1 -0
  210. package/lib/node/pty.manager.remote.js +124 -0
  211. package/lib/node/pty.manager.remote.js.map +1 -0
  212. package/lib/node/pty.proxy.d.ts +45 -0
  213. package/lib/node/pty.proxy.d.ts.map +1 -0
  214. package/lib/node/pty.proxy.js +277 -0
  215. package/lib/node/pty.proxy.js.map +1 -0
  216. package/lib/node/pty.proxy.remote.exec.d.ts +2 -0
  217. package/lib/node/pty.proxy.remote.exec.d.ts.map +1 -0
  218. package/lib/node/pty.proxy.remote.exec.js +7 -0
  219. package/lib/node/pty.proxy.remote.exec.js.map +1 -0
  220. package/lib/node/shell-integration.service.d.ts +24 -0
  221. package/lib/node/shell-integration.service.d.ts.map +1 -0
  222. package/lib/node/shell-integration.service.js +187 -0
  223. package/lib/node/shell-integration.service.js.map +1 -0
  224. package/lib/node/shell.d.ts +20 -0
  225. package/lib/node/shell.d.ts.map +1 -0
  226. package/lib/node/shell.js +199 -0
  227. package/lib/node/shell.js.map +1 -0
  228. package/lib/node/terminal.process.service.d.ts +5 -0
  229. package/lib/node/terminal.process.service.d.ts.map +1 -0
  230. package/lib/node/terminal.process.service.js +15 -0
  231. package/lib/node/terminal.process.service.js.map +1 -0
  232. package/lib/node/terminal.profile.service.d.ts +19 -0
  233. package/lib/node/terminal.profile.service.d.ts.map +1 -0
  234. package/lib/node/terminal.profile.service.js +228 -0
  235. package/lib/node/terminal.profile.service.js.map +1 -0
  236. package/lib/node/terminal.service.client.d.ts +51 -0
  237. package/lib/node/terminal.service.client.d.ts.map +1 -0
  238. package/lib/node/terminal.service.client.js +159 -0
  239. package/lib/node/terminal.service.client.js.map +1 -0
  240. package/lib/node/terminal.service.d.ts +30 -0
  241. package/lib/node/terminal.service.d.ts.map +1 -0
  242. package/lib/node/terminal.service.js +246 -0
  243. package/lib/node/terminal.service.js.map +1 -0
  244. package/package.json +18 -18
@@ -0,0 +1,680 @@
1
+ "use strict";
2
+ var TerminalClient_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createTerminalClientFactory2 = exports.TerminalClientFactory = exports.TerminalClient = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const di_1 = require("@opensumi/di");
7
+ const ide_core_browser_1 = require("@opensumi/ide-core-browser");
8
+ const types_1 = require("@opensumi/ide-core-browser/lib/preferences/types");
9
+ const ide_core_common_1 = require("@opensumi/ide-core-common");
10
+ const common_1 = require("@opensumi/ide-editor/lib/common");
11
+ const common_2 = require("@opensumi/ide-file-service/lib/common");
12
+ const observable_1 = require("@opensumi/ide-monaco/lib/common/observable");
13
+ const ide_overlay_1 = require("@opensumi/ide-overlay");
14
+ const common_3 = require("@opensumi/ide-variable/lib/common");
15
+ const common_4 = require("@opensumi/ide-workspace/lib/common");
16
+ const common_5 = require("../common");
17
+ const environmentVariable_1 = require("../common/environmentVariable");
18
+ const preference_1 = require("../common/preference");
19
+ const link_manager_1 = require("./links/link-manager");
20
+ const terminal_addon_1 = require("./terminal.addon");
21
+ const terminal_ext_host_proxy_1 = require("./terminal.ext.host.proxy");
22
+ const terminal_input_1 = require("./terminal.input");
23
+ const terminal_typeAhead_addon_1 = require("./terminal.typeAhead.addon");
24
+ const xterm_1 = require("./xterm");
25
+ let TerminalClient = TerminalClient_1 = class TerminalClient extends ide_core_common_1.Disposable {
26
+ constructor() {
27
+ super();
28
+ /** end */
29
+ this.isTaskExecutor = false;
30
+ /** status */
31
+ this._ready = false;
32
+ this._hasOutput = false;
33
+ this._areLinksReady = false;
34
+ this._onInput = new ide_core_common_1.Emitter();
35
+ this.onInput = this._onInput.event;
36
+ this._onOutput = new ide_core_common_1.Emitter();
37
+ this.onOutput = this._onOutput.event;
38
+ this._onExit = new ide_core_common_1.Emitter();
39
+ this.onExit = this._onExit.event;
40
+ this._onTitleChange = new ide_core_common_1.Emitter();
41
+ this.onTitleChange = this._onTitleChange.event;
42
+ this._onLinksReady = new ide_core_common_1.Emitter();
43
+ this.onLinksReady = this._onLinksReady.event;
44
+ this._onResponseTime = new ide_core_common_1.Emitter();
45
+ this.onResponseTime = this._onResponseTime.event;
46
+ this._onNameChangeEmitter = new ide_core_common_1.Emitter();
47
+ this.onNameChange = this._onNameChangeEmitter.event;
48
+ this._name = '';
49
+ this.init();
50
+ }
51
+ async init() {
52
+ this.xterm = this.injector.get(xterm_1.XTerm, [
53
+ {
54
+ xtermOptions: {
55
+ theme: this.theme.terminalTheme,
56
+ ...this.internalService.getOptions(),
57
+ ...this.terminalPreference.toJSON(),
58
+ },
59
+ },
60
+ ]);
61
+ this.addDispose(this.xterm);
62
+ this.addDispose(this.internalService.onError((error) => {
63
+ var _a;
64
+ this.messageService.error(error.message);
65
+ if ((_a = error.launchConfig) === null || _a === void 0 ? void 0 : _a.executable) {
66
+ this.updateTerminalName({
67
+ name: 'error: ' + error.launchConfig.executable,
68
+ });
69
+ }
70
+ else {
71
+ this.updateTerminalName({
72
+ name: 'error',
73
+ });
74
+ }
75
+ }));
76
+ this.addDispose(this.internalService.onProcessChange((e) => {
77
+ if (e.sessionId === this.id) {
78
+ (0, observable_1.transaction)((tx) => {
79
+ this.widget.processName.set(e.processName, tx);
80
+ });
81
+ }
82
+ }));
83
+ }
84
+ onWidgetShow() {
85
+ if (this._show) {
86
+ this._show.resolve();
87
+ this._show = null;
88
+ }
89
+ this._layout();
90
+ }
91
+ async setupWidget(widget) {
92
+ this._widget = widget;
93
+ this._prepare();
94
+ this.addDispose(ide_core_common_1.Disposable.create(() => {
95
+ TerminalClient_1.WORKSPACE_PATH_CACHED.delete(widget.group.id);
96
+ }));
97
+ this.addDispose(this.terminalPreference.onChange(async ({ name, value }) => {
98
+ if (!widget.show && !this._show) {
99
+ this._show = new ide_core_common_1.Deferred();
100
+ }
101
+ if (this._show) {
102
+ await this._show.promise;
103
+ }
104
+ this._setOption(name, value);
105
+ this.xterm.updatePreferences({
106
+ [name]: value,
107
+ });
108
+ }));
109
+ // 在拆分终端时,widget 渲染的时机会比较早
110
+ // 如果 widget show 已经为 true,确保
111
+ // Deferred 已经 resolve, 否则无法监听
112
+ // 到后续的事件
113
+ if (widget.show) {
114
+ this.onWidgetShow();
115
+ }
116
+ else {
117
+ this.addDispose(widget.onShow((status) => {
118
+ if (status) {
119
+ this.onWidgetShow();
120
+ }
121
+ }));
122
+ }
123
+ this.addDispose(widget.onError((status) => {
124
+ var _a;
125
+ if (status) {
126
+ // fit 操作在对比行列没有发送变化的时候不会做任何操作,
127
+ // 但是实际上是设置为 display none 了,所以手动 resize 一下
128
+ // this._term.resize(1, 1);
129
+ }
130
+ else {
131
+ (_a = this._error) === null || _a === void 0 ? void 0 : _a.resolve();
132
+ this._layout();
133
+ }
134
+ }));
135
+ this.addDispose(widget.onResize(async () => {
136
+ this._debounceResize();
137
+ }));
138
+ }
139
+ async init2(widget, options) {
140
+ var _a, _b, _c, _d;
141
+ this._uid = (options === null || options === void 0 ? void 0 : options.id) || widget.id;
142
+ this.setupWidget(widget);
143
+ if (!options || Object.keys(options).length === 0) {
144
+ // Must be able to resolve a profile
145
+ const defaultProfile = await this.terminalProfileInternalService.resolveDefaultProfile();
146
+ options = {
147
+ id: this._uid,
148
+ config: defaultProfile,
149
+ };
150
+ }
151
+ if (!options.cwd) {
152
+ // resolve cwd from the group first widget
153
+ const group = widget.group;
154
+ const widgets = group.widgets.get();
155
+ if (widgets.length > 1 && widgets[0]) {
156
+ const cwd = await this.internalService.getCwd(widgets[0].id);
157
+ if (cwd) {
158
+ options.cwd = cwd;
159
+ }
160
+ }
161
+ }
162
+ await this._checkWorkspace();
163
+ const cwd = (_c = (_a = options.cwd) !== null && _a !== void 0 ? _a : (_b = options === null || options === void 0 ? void 0 : options.config) === null || _b === void 0 ? void 0 : _b.cwd) !== null && _c !== void 0 ? _c : this._workspacePath;
164
+ const launchConfig = this.controller.convertProfileToLaunchConfig(options.config, cwd);
165
+ this._launchConfig = launchConfig;
166
+ if (this._launchConfig.__fromTerminalOptions) {
167
+ this._terminalOptions = this._launchConfig.__fromTerminalOptions;
168
+ }
169
+ this.name = launchConfig.name || '';
170
+ if (launchConfig.initialText) {
171
+ this.xterm.raw.writeln(launchConfig.initialText);
172
+ }
173
+ if (!launchConfig.env) {
174
+ launchConfig.env = {};
175
+ }
176
+ (_d = this.environmentService.mergedCollection) === null || _d === void 0 ? void 0 : _d.applyToProcessEnvironment(launchConfig.env, this.applicationService.backendOS, this.variableResolver.resolve.bind(this.variableResolver));
177
+ this.addDispose(this.environmentService.onDidChangeCollections((collection) => {
178
+ // 环境变量更新只会在新建的终端中生效,已有的终端需要重启才可以生效
179
+ collection.applyToProcessEnvironment(launchConfig.env, this.applicationService.backendOS, this.variableResolver.resolve.bind(this.variableResolver));
180
+ }));
181
+ this._attachXterm();
182
+ this._attachAfterRender();
183
+ }
184
+ get name() {
185
+ return this._name;
186
+ }
187
+ set name(name) {
188
+ if (this._name !== name) {
189
+ this._name = name;
190
+ this._onNameChangeEmitter.fire(name);
191
+ }
192
+ }
193
+ get term() {
194
+ return this.xterm.raw;
195
+ }
196
+ get pid() {
197
+ return this.internalService.getProcessId(this.id);
198
+ }
199
+ get launchConfig() {
200
+ return this._launchConfig;
201
+ }
202
+ get createOptions() {
203
+ return;
204
+ }
205
+ get container() {
206
+ return this.xterm.container;
207
+ }
208
+ get id() {
209
+ return this._uid;
210
+ }
211
+ get widget() {
212
+ return this._widget;
213
+ }
214
+ get ready() {
215
+ return this._ready;
216
+ }
217
+ get attached() {
218
+ return this._attached;
219
+ }
220
+ get firstOutput() {
221
+ return this._firstStdout;
222
+ }
223
+ get show() {
224
+ return this._show;
225
+ }
226
+ get areLinksReady() {
227
+ return this._areLinksReady;
228
+ }
229
+ get os() {
230
+ return this._os;
231
+ }
232
+ _prepareAddons() {
233
+ this._attachAddon = new terminal_addon_1.AttachAddon();
234
+ const onBeforeProcessEvent = this._attachAddon.onBeforeProcessData;
235
+ if (this.preferenceService.get("terminal.integrated.localEchoEnabled" /* CodeTerminalSettingId.LocalEchoEnabled */)) {
236
+ // 某些奇怪的情况下,用户会把这个字段设置成字符串,导致终端crash
237
+ const exclueProgramConfig = this.preferenceService.get("terminal.integrated.localEchoExcludePrograms" /* CodeTerminalSettingId.LocalEchoExcludePrograms */, terminal_typeAhead_addon_1.DEFAULT_LOCAL_ECHO_EXCLUDE);
238
+ const typeAheadAddon = new terminal_typeAhead_addon_1.TypeAheadAddon(onBeforeProcessEvent, {
239
+ localEchoExcludePrograms: Array.isArray(exclueProgramConfig)
240
+ ? exclueProgramConfig
241
+ : terminal_typeAhead_addon_1.DEFAULT_LOCAL_ECHO_EXCLUDE,
242
+ localEchoLatencyThreshold: this.preferenceService.get("terminal.integrated.localEchoLatencyThreshold" /* CodeTerminalSettingId.LocalEchoLatencyThreshold */, 30),
243
+ localEchoStyle: this.preferenceService.get("terminal.integrated.localEchoStyle" /* CodeTerminalSettingId.LocalEchoStyle */, 'dim'),
244
+ }, this.preferenceService.onPreferenceChanged);
245
+ this.addDispose(typeAheadAddon);
246
+ this.xterm.raw.loadAddon(typeAheadAddon);
247
+ }
248
+ this.addDispose([
249
+ this._attachAddon,
250
+ this._attachAddon.onData((data) => {
251
+ this._onOutput.fire({ id: this.id, data });
252
+ }),
253
+ this._attachAddon.onExit((code) => {
254
+ var _a, _b;
255
+ this.logger.warn(`${this.id} ${this.name} exit with ${code}`);
256
+ if (code !== 0) {
257
+ this.messageService.error(`terminal ${this.name}(${(_b = (_a = this._attachAddon.connection) === null || _a === void 0 ? void 0 : _a.ptyInstance) === null || _b === void 0 ? void 0 : _b.shellPath}) exited with non-zero code ${code}`);
258
+ }
259
+ this._onExit.fire({ id: this.id, code });
260
+ }),
261
+ this._attachAddon.onTime((delta) => {
262
+ this._onResponseTime.fire(delta);
263
+ this.reporter.performance(ide_core_common_1.REPORT_NAME.TERMINAL_MEASURE, {
264
+ duration: delta,
265
+ msg: 'terminal.response',
266
+ });
267
+ }),
268
+ ]);
269
+ this.xterm.raw.loadAddon(this._attachAddon);
270
+ }
271
+ _xtermEvents() {
272
+ this.addDispose(this.xterm.raw.onResize((_event) => {
273
+ if (this._hasOutput) {
274
+ this._doResize();
275
+ }
276
+ }));
277
+ }
278
+ _attachXterm() {
279
+ this._prepareAddons();
280
+ this._xtermEvents();
281
+ this._linkManager = this.injector.get(link_manager_1.TerminalLinkManager, [this.xterm.raw, this]);
282
+ this._linkManager.processCwd = this._workspacePath;
283
+ this.addDispose(this._linkManager);
284
+ this._areLinksReady = true;
285
+ this._onLinksReady.fire(this);
286
+ }
287
+ _doResize() {
288
+ // TODO: debounce
289
+ this.internalService.resize(this.id, this.xterm.raw.cols, this.xterm.raw.rows);
290
+ }
291
+ _prepare() {
292
+ var _a, _b, _c, _d, _f;
293
+ (_a = this._attached) === null || _a === void 0 ? void 0 : _a.reject('TerminalClient is Re-initialization');
294
+ (_b = this._firstStdout) === null || _b === void 0 ? void 0 : _b.reject('TerminalClient is Re-initialization');
295
+ (_c = this._error) === null || _c === void 0 ? void 0 : _c.reject('TerminalClient is Re-initialization');
296
+ (_d = this._show) === null || _d === void 0 ? void 0 : _d.reject('TerminalClient is Re-initialization');
297
+ this._ready = false;
298
+ this._hasOutput = false;
299
+ this._attached = new ide_core_common_1.Deferred();
300
+ this._show = new ide_core_common_1.Deferred();
301
+ this._error = new ide_core_common_1.Deferred();
302
+ this._firstStdout = new ide_core_common_1.Deferred();
303
+ (_f = this._attachAddon) === null || _f === void 0 ? void 0 : _f.setConnection(undefined);
304
+ this.internalService.getOS().then((os) => {
305
+ this._os = os;
306
+ });
307
+ const { dispose } = this.onOutput(() => {
308
+ dispose();
309
+ this._hasOutput = true;
310
+ this._firstStdout.resolve();
311
+ });
312
+ }
313
+ _attachAfterRender() {
314
+ // 等待 widget 渲染后再 attach,尽可能在创建时获取到准确的宽高
315
+ // requestAnimationFrame 在不可见状态下会丢失,所以一定要用 queueMicrotask
316
+ queueMicrotask(() => {
317
+ var _a;
318
+ this._layout();
319
+ this.attach();
320
+ this.focus();
321
+ if (!this.widget.show) {
322
+ (_a = this._show) === null || _a === void 0 ? void 0 : _a.promise.then(async () => {
323
+ this._show = new ide_core_common_1.Deferred();
324
+ });
325
+ }
326
+ });
327
+ }
328
+ async _pickWorkspace() {
329
+ var _a;
330
+ if (this.workspace.isMultiRootWorkspaceOpened && !this._widget.recovery) {
331
+ // 工作区模式下每次新建终端都需要用户手动进行一次路径选择
332
+ const roots = this.workspace.tryGetRoots();
333
+ const choose = await this.quickPick.show(roots.map((file) => new ide_core_common_1.URI(file.uri).codeUri.fsPath), { placeholder: (0, ide_core_browser_1.localize)('terminal.selectCWDForNewTerminal') });
334
+ return choose;
335
+ }
336
+ else if (this.workspace.workspace) {
337
+ return new ide_core_common_1.URI((_a = this.workspace.workspace) === null || _a === void 0 ? void 0 : _a.uri).codeUri.fsPath;
338
+ }
339
+ else {
340
+ return undefined;
341
+ }
342
+ }
343
+ /**
344
+ * if we want open a terminal, we need a parameter: `cwd`
345
+ * we don't care whether it valid. our backend service will check it.
346
+ *
347
+ * 如果当前工作区不存在,这里就会获得空,后端的逻辑中终端会打开用户的家目录。
348
+ * 多工作区模式下用户没有选中任何一个工作区,也是会打开用户的家目录。
349
+ */
350
+ async _checkWorkspace() {
351
+ const widget = this._widget;
352
+ if (TerminalClient_1.WORKSPACE_PATH_CACHED.has(widget.group.id)) {
353
+ this._workspacePath = TerminalClient_1.WORKSPACE_PATH_CACHED.get(widget.group.id);
354
+ }
355
+ else {
356
+ const choose = await this._pickWorkspace();
357
+ if (choose) {
358
+ this._workspacePath = choose;
359
+ TerminalClient_1.WORKSPACE_PATH_CACHED.set(widget.group.id, this._workspacePath);
360
+ }
361
+ }
362
+ }
363
+ // 检查 Terminal Client 对应的后端 Shell 进程是否存活
364
+ async checkHealthy() {
365
+ return await this.internalService.check([this.id]);
366
+ }
367
+ // 输出终端已经被 Kill 的提醒
368
+ displayUnHealthyMessage() {
369
+ const xtermRaw = this.term;
370
+ // 基于 Xterm Theme 的颜色来输出用户提示
371
+ const currentTheme = xtermRaw.options.theme;
372
+ // 根据当前主题设置输出样式的函数
373
+ const printStyledMessage = (message, foreground, background) => {
374
+ const padding = ' '; // 四个空格作为左右边距
375
+ const paddedMessage = message
376
+ .split('\n')
377
+ .map((line) => padding + line + padding)
378
+ .join('\n');
379
+ const styledMessage = `\x1b[48;2;${hexToRgb(foreground)};38;2;${hexToRgb(background)}m${paddedMessage}\x1b[0m`;
380
+ xtermRaw.writeln('\n');
381
+ xtermRaw.writeln('\n' + styledMessage + '\n'); // 在输出前后添加空行
382
+ };
383
+ // 辅助函数:将十六进制颜色转换为 RGB 字符串
384
+ const hexToRgb = (hex) => {
385
+ const r = parseInt(hex.slice(1, 3), 16);
386
+ const g = parseInt(hex.slice(3, 5), 16);
387
+ const b = parseInt(hex.slice(5, 7), 16);
388
+ return `${r};${g};${b}`;
389
+ };
390
+ printStyledMessage((0, ide_core_browser_1.localize)('terminal.process.unHealthy'), (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.foreground) || '#d7dbdeff', (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.background) || '#151b21ff');
391
+ }
392
+ reset() {
393
+ this._prepare();
394
+ this._attachAfterRender();
395
+ }
396
+ async attach() {
397
+ if (!this._ready) {
398
+ return this._doAttach();
399
+ }
400
+ }
401
+ async _doAttach() {
402
+ var _a;
403
+ const sessionId = this.id;
404
+ const { rows = terminal_addon_1.DEFAULT_ROW, cols = terminal_addon_1.DEFAULT_COL } = this.xterm.raw;
405
+ let connection;
406
+ const finalLaunchConfig = {
407
+ ...this._launchConfig,
408
+ cwd: ((_a = this._launchConfig) === null || _a === void 0 ? void 0 : _a.cwd) || this._workspacePath,
409
+ };
410
+ if (finalLaunchConfig.isExtensionOwnedTerminal) {
411
+ finalLaunchConfig.customPtyImplementation = (sessionId, cols, rows) => new terminal_ext_host_proxy_1.TerminalProcessExtHostProxy(sessionId, cols, rows, this.controller);
412
+ }
413
+ this._launchConfig = finalLaunchConfig;
414
+ this.logger.log('attach terminal by launchConfig: ', this._launchConfig);
415
+ try {
416
+ connection = await this.internalService.attachByLaunchConfig(sessionId, cols, rows, this._launchConfig, this.xterm);
417
+ }
418
+ catch (e) {
419
+ this.logger.error(`attach ${sessionId} terminal failed, _launchConfig`, JSON.stringify(this._launchConfig), e);
420
+ }
421
+ this.resolveConnection(connection);
422
+ }
423
+ resolveConnection(connection) {
424
+ if (!connection) {
425
+ this._attached.reject('no connection while attaching terminal client');
426
+ return;
427
+ }
428
+ this._attachAddon.setConnection(connection);
429
+ const name = this.name || this._launchConfig.name || connection.name;
430
+ if (name !== this.name) {
431
+ this.name = name;
432
+ this._onTitleChange.fire({ id: this.id, name });
433
+ }
434
+ this._ready = true;
435
+ this._attached.resolve();
436
+ this._widget.rename(this.name);
437
+ this.eventBus.fire(new ide_core_browser_1.TerminalClientAttachEvent({ clientId: this.id }));
438
+ this._firstStdout.promise.then(() => {
439
+ this._doResize();
440
+ });
441
+ }
442
+ _setOption(name, value) {
443
+ /**
444
+ * 有可能 preference 引起的修改并不是对应终端的 option,
445
+ * 这种情况可能会报错
446
+ */
447
+ try {
448
+ this.xterm.raw.options[name] = value;
449
+ this._layout();
450
+ }
451
+ catch (_e) {
452
+ /** nothing */
453
+ }
454
+ }
455
+ _checkReady() {
456
+ if (!this._ready) {
457
+ throw new Error('terminal client not ready');
458
+ }
459
+ }
460
+ _layout() {
461
+ // 如果 xterm 视图还没初始化,则先尝试初始化
462
+ try {
463
+ this._renderOnDemand();
464
+ if (this.xterm.raw.element) {
465
+ this.xterm.fit();
466
+ }
467
+ }
468
+ catch (e) {
469
+ // noop
470
+ }
471
+ }
472
+ _renderOnDemand() {
473
+ var _a;
474
+ // 避免重复创建 xterm 视图,后果是终端实例和视图不匹配,表现为整个卡住
475
+ if (this.xterm.raw.element) {
476
+ return;
477
+ }
478
+ // xterm 视图容器没准备好,取消渲染 xterm 视图
479
+ if (!((_a = this._widget.element) === null || _a === void 0 ? void 0 : _a.clientHeight)) {
480
+ return;
481
+ }
482
+ this._widget.element.appendChild(this.xterm.container);
483
+ this.xterm.open();
484
+ // 首次渲染且为当前选中的 client 时,聚焦
485
+ // 等待数据更新、terminal 渲染完成,但是无需等待连接成功,体验上会更快一些
486
+ setTimeout(() => {
487
+ var _a;
488
+ if (((_a = this.controller.activeClient) === null || _a === void 0 ? void 0 : _a.id) === this.id) {
489
+ this.focus();
490
+ }
491
+ });
492
+ }
493
+ _debounceResize() {
494
+ this._layout();
495
+ }
496
+ focus() {
497
+ return this.xterm.raw.focus();
498
+ }
499
+ clear() {
500
+ this._checkReady();
501
+ return this.xterm.raw.clear();
502
+ }
503
+ selectAll() {
504
+ this._checkReady();
505
+ return this.xterm.raw.selectAll();
506
+ }
507
+ paste(text) {
508
+ this._checkReady();
509
+ return this.xterm.raw.paste(text);
510
+ }
511
+ findNext(text, searchOptions = {}) {
512
+ this._checkReady();
513
+ return this.xterm.findNext(text, searchOptions);
514
+ }
515
+ findPrevious(text, searchOptions = {}) {
516
+ this._checkReady();
517
+ return this.xterm.findPrevious(text, searchOptions);
518
+ }
519
+ get onSearchResultsChange() {
520
+ return this.xterm.onSearchResultsChange;
521
+ }
522
+ closeSearch() {
523
+ this.xterm.closeSearch();
524
+ }
525
+ getSelection() {
526
+ this._checkReady();
527
+ if (this.xterm.raw.hasSelection()) {
528
+ return this.xterm.raw.getSelection();
529
+ }
530
+ else {
531
+ this.logger.warn('The terminal has no selection to copy');
532
+ return '';
533
+ }
534
+ }
535
+ updateTheme() {
536
+ return this.xterm.updateTheme(this.theme.terminalTheme);
537
+ }
538
+ updateLaunchConfig(launchConfig) {
539
+ this._launchConfig = {
540
+ ...this._launchConfig,
541
+ ...launchConfig,
542
+ };
543
+ }
544
+ updateTerminalName(options) {
545
+ if (!this.name && !this._widget.name.get()) {
546
+ this._widget.rename(options.name || this.name);
547
+ }
548
+ }
549
+ async sendText(message) {
550
+ await this.internalService.sendText(this.id, message);
551
+ this._onInput.fire({ id: this.id, data: message });
552
+ }
553
+ registerLinkProvider(provider) {
554
+ if (!this._linkManager) {
555
+ throw new Error('TerminalInstance.registerLinkProvider before link manager was ready');
556
+ }
557
+ return this._linkManager.registerExternalLinkProvider(this, provider);
558
+ }
559
+ dispose(clear = true) {
560
+ super.dispose();
561
+ if (clear) {
562
+ this.internalService.disposeById(this.id);
563
+ }
564
+ }
565
+ };
566
+ exports.TerminalClient = TerminalClient;
567
+ TerminalClient.WORKSPACE_PATH_CACHED = new Map();
568
+ tslib_1.__decorate([
569
+ (0, di_1.Autowired)(di_1.INJECTOR_TOKEN),
570
+ tslib_1.__metadata("design:type", di_1.Injector)
571
+ ], TerminalClient.prototype, "injector", void 0);
572
+ tslib_1.__decorate([
573
+ (0, di_1.Autowired)(common_5.ITerminalInternalService),
574
+ tslib_1.__metadata("design:type", Object)
575
+ ], TerminalClient.prototype, "internalService", void 0);
576
+ tslib_1.__decorate([
577
+ (0, di_1.Autowired)(common_4.IWorkspaceService),
578
+ tslib_1.__metadata("design:type", Object)
579
+ ], TerminalClient.prototype, "workspace", void 0);
580
+ tslib_1.__decorate([
581
+ (0, di_1.Autowired)(common_1.WorkbenchEditorService),
582
+ tslib_1.__metadata("design:type", common_1.WorkbenchEditorService)
583
+ ], TerminalClient.prototype, "editorService", void 0);
584
+ tslib_1.__decorate([
585
+ (0, di_1.Autowired)(common_2.IFileServiceClient),
586
+ tslib_1.__metadata("design:type", Object)
587
+ ], TerminalClient.prototype, "fileService", void 0);
588
+ tslib_1.__decorate([
589
+ (0, di_1.Autowired)(ide_overlay_1.IMessageService),
590
+ tslib_1.__metadata("design:type", Object)
591
+ ], TerminalClient.prototype, "messageService", void 0);
592
+ tslib_1.__decorate([
593
+ (0, di_1.Autowired)(common_5.ITerminalTheme),
594
+ tslib_1.__metadata("design:type", Object)
595
+ ], TerminalClient.prototype, "theme", void 0);
596
+ tslib_1.__decorate([
597
+ (0, di_1.Autowired)(common_5.ITerminalController),
598
+ tslib_1.__metadata("design:type", Object)
599
+ ], TerminalClient.prototype, "controller", void 0);
600
+ tslib_1.__decorate([
601
+ (0, di_1.Autowired)(types_1.PreferenceService),
602
+ tslib_1.__metadata("design:type", Object)
603
+ ], TerminalClient.prototype, "preferenceService", void 0);
604
+ tslib_1.__decorate([
605
+ (0, di_1.Autowired)(common_5.ITerminalGroupViewService),
606
+ tslib_1.__metadata("design:type", Object)
607
+ ], TerminalClient.prototype, "view", void 0);
608
+ tslib_1.__decorate([
609
+ (0, di_1.Autowired)(preference_1.ITerminalPreference),
610
+ tslib_1.__metadata("design:type", Object)
611
+ ], TerminalClient.prototype, "terminalPreference", void 0);
612
+ tslib_1.__decorate([
613
+ (0, di_1.Autowired)(terminal_input_1.TerminalKeyBoardInputService),
614
+ tslib_1.__metadata("design:type", terminal_input_1.TerminalKeyBoardInputService)
615
+ ], TerminalClient.prototype, "keyboard", void 0);
616
+ tslib_1.__decorate([
617
+ (0, di_1.Autowired)(ide_core_browser_1.QuickPickService),
618
+ tslib_1.__metadata("design:type", Object)
619
+ ], TerminalClient.prototype, "quickPick", void 0);
620
+ tslib_1.__decorate([
621
+ (0, di_1.Autowired)(ide_core_common_1.ILogger),
622
+ tslib_1.__metadata("design:type", Object)
623
+ ], TerminalClient.prototype, "logger", void 0);
624
+ tslib_1.__decorate([
625
+ (0, di_1.Autowired)(ide_core_common_1.IReporter),
626
+ tslib_1.__metadata("design:type", Object)
627
+ ], TerminalClient.prototype, "reporter", void 0);
628
+ tslib_1.__decorate([
629
+ (0, di_1.Autowired)(environmentVariable_1.EnvironmentVariableServiceToken),
630
+ tslib_1.__metadata("design:type", Object)
631
+ ], TerminalClient.prototype, "environmentService", void 0);
632
+ tslib_1.__decorate([
633
+ (0, di_1.Autowired)(ide_core_common_1.IApplicationService),
634
+ tslib_1.__metadata("design:type", Object)
635
+ ], TerminalClient.prototype, "applicationService", void 0);
636
+ tslib_1.__decorate([
637
+ (0, di_1.Autowired)(common_5.ITerminalProfileInternalService),
638
+ tslib_1.__metadata("design:type", Object)
639
+ ], TerminalClient.prototype, "terminalProfileInternalService", void 0);
640
+ tslib_1.__decorate([
641
+ (0, di_1.Autowired)(common_3.IVariableResolverService),
642
+ tslib_1.__metadata("design:type", Object)
643
+ ], TerminalClient.prototype, "variableResolver", void 0);
644
+ tslib_1.__decorate([
645
+ (0, di_1.Autowired)(ide_core_browser_1.IEventBus),
646
+ tslib_1.__metadata("design:type", Object)
647
+ ], TerminalClient.prototype, "eventBus", void 0);
648
+ tslib_1.__decorate([
649
+ (0, ide_core_common_1.debounce)(100),
650
+ tslib_1.__metadata("design:type", Function),
651
+ tslib_1.__metadata("design:paramtypes", []),
652
+ tslib_1.__metadata("design:returntype", void 0)
653
+ ], TerminalClient.prototype, "_debounceResize", null);
654
+ exports.TerminalClient = TerminalClient = TerminalClient_1 = tslib_1.__decorate([
655
+ (0, di_1.Injectable)(),
656
+ tslib_1.__metadata("design:paramtypes", [])
657
+ ], TerminalClient);
658
+ let TerminalClientFactory = class TerminalClientFactory {
659
+ /**
660
+ * 创建 terminal 实例最终都会调用该方法
661
+ */
662
+ static async createClient2(injector, widget, options) {
663
+ const child = injector.createChild([
664
+ {
665
+ token: TerminalClient,
666
+ useClass: TerminalClient,
667
+ },
668
+ ]);
669
+ const client = child.get(TerminalClient);
670
+ await client.init2(widget, options);
671
+ return client;
672
+ }
673
+ };
674
+ exports.TerminalClientFactory = TerminalClientFactory;
675
+ exports.TerminalClientFactory = TerminalClientFactory = tslib_1.__decorate([
676
+ (0, di_1.Injectable)()
677
+ ], TerminalClientFactory);
678
+ const createTerminalClientFactory2 = (injector) => (widget, options) => TerminalClientFactory.createClient2(injector, widget, options);
679
+ exports.createTerminalClientFactory2 = createTerminalClientFactory2;
680
+ //# sourceMappingURL=terminal.client.js.map