@opensumi/ide-terminal-next 3.4.5 → 3.4.6-next-1730347271.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 (79) hide show
  1. package/lib/browser/component/terminal.view.d.ts +1 -1
  2. package/lib/browser/component/terminal.view.d.ts.map +1 -1
  3. package/lib/browser/component/terminal.view.js +1 -1
  4. package/lib/browser/component/terminal.view.js.map +1 -1
  5. package/lib/browser/links/base.d.ts +1 -1
  6. package/lib/browser/links/base.d.ts.map +1 -1
  7. package/lib/browser/links/external-link-provider-adapter.d.ts +1 -1
  8. package/lib/browser/links/external-link-provider-adapter.d.ts.map +1 -1
  9. package/lib/browser/links/helpers.d.ts +1 -1
  10. package/lib/browser/links/helpers.d.ts.map +1 -1
  11. package/lib/browser/links/link-manager.d.ts +1 -1
  12. package/lib/browser/links/link-manager.d.ts.map +1 -1
  13. package/lib/browser/links/link-manager.js +1 -1
  14. package/lib/browser/links/link-manager.js.map +1 -1
  15. package/lib/browser/links/link.d.ts +1 -1
  16. package/lib/browser/links/link.d.ts.map +1 -1
  17. package/lib/browser/links/protocol-link-provider.d.ts +1 -1
  18. package/lib/browser/links/protocol-link-provider.d.ts.map +1 -1
  19. package/lib/browser/links/validated-local-link-provider.d.ts +1 -1
  20. package/lib/browser/links/validated-local-link-provider.d.ts.map +1 -1
  21. package/lib/browser/terminal.addon.d.ts +1 -1
  22. package/lib/browser/terminal.addon.d.ts.map +1 -1
  23. package/lib/browser/terminal.client.d.ts +2 -2
  24. package/lib/browser/terminal.client.d.ts.map +1 -1
  25. package/lib/browser/terminal.controller.js +1 -1
  26. package/lib/browser/terminal.controller.js.map +1 -1
  27. package/lib/browser/terminal.internal.service.d.ts +2 -2
  28. package/lib/browser/terminal.preference.d.ts +1 -1
  29. package/lib/browser/terminal.preference.d.ts.map +1 -1
  30. package/lib/browser/terminal.preference.js.map +1 -1
  31. package/lib/browser/terminal.theme.d.ts +1 -1
  32. package/lib/browser/terminal.theme.d.ts.map +1 -1
  33. package/lib/browser/terminal.typeAhead.addon.d.ts +2 -2
  34. package/lib/browser/terminal.typeAhead.addon.d.ts.map +1 -1
  35. package/lib/browser/xterm.d.ts +1 -1
  36. package/lib/browser/xterm.d.ts.map +1 -1
  37. package/lib/browser/xterm.js +7 -7
  38. package/lib/browser/xterm.js.map +1 -1
  39. package/lib/common/client.d.ts +1 -1
  40. package/lib/common/client.d.ts.map +1 -1
  41. package/lib/common/pty.d.ts +1 -1
  42. package/lib/common/pty.d.ts.map +1 -1
  43. package/lib/common/service.d.ts +1 -1
  44. package/lib/common/service.d.ts.map +1 -1
  45. package/lib/common/theme.d.ts +1 -1
  46. package/lib/common/theme.d.ts.map +1 -1
  47. package/lib/common/xterm.d.ts +1 -1
  48. package/lib/common/xterm.d.ts.map +1 -1
  49. package/lib/node/pty.d.ts.map +1 -1
  50. package/lib/node/pty.js +12 -3
  51. package/lib/node/pty.js.map +1 -1
  52. package/lib/node/shell-integration.service.d.ts +3 -0
  53. package/lib/node/shell-integration.service.d.ts.map +1 -1
  54. package/lib/node/shell-integration.service.js +117 -0
  55. package/lib/node/shell-integration.service.js.map +1 -1
  56. package/package.json +23 -23
  57. package/src/browser/component/terminal.view.tsx +1 -1
  58. package/src/browser/links/base.ts +1 -1
  59. package/src/browser/links/external-link-provider-adapter.ts +1 -1
  60. package/src/browser/links/helpers.ts +1 -1
  61. package/src/browser/links/link-manager.ts +1 -1
  62. package/src/browser/links/link.ts +1 -1
  63. package/src/browser/links/protocol-link-provider.ts +1 -1
  64. package/src/browser/links/validated-local-link-provider.ts +1 -1
  65. package/src/browser/terminal.addon.ts +1 -1
  66. package/src/browser/terminal.controller.ts +1 -1
  67. package/src/browser/terminal.preference.ts +1 -1
  68. package/src/browser/terminal.theme.ts +1 -1
  69. package/src/browser/terminal.typeAhead.addon.ts +1 -1
  70. package/src/browser/xterm-private.d.ts +1 -1
  71. package/src/browser/xterm.ts +7 -7
  72. package/src/common/client.ts +1 -1
  73. package/src/common/pty.ts +1 -1
  74. package/src/common/service.ts +1 -1
  75. package/src/common/theme.ts +1 -1
  76. package/src/common/xterm-private.d.ts +1 -1
  77. package/src/common/xterm.ts +1 -1
  78. package/src/node/pty.ts +14 -2
  79. package/src/node/shell-integration.service.ts +128 -0
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- import { ITerminalOptions, ITheme, Terminal } from 'xterm';
3
- import { FitAddon } from 'xterm-addon-fit';
4
- import { ISearchOptions, SearchAddon } from 'xterm-addon-search';
2
+ import { FitAddon } from '@xterm/addon-fit';
3
+ import { ISearchOptions, SearchAddon } from '@xterm/addon-search';
4
+ import { ITerminalOptions, ITheme, Terminal } from '@xterm/xterm';
5
5
 
6
6
  import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
7
7
  import { IClipboardService } from '@opensumi/ide-core-browser';
@@ -26,8 +26,8 @@ import {
26
26
  TERMINAL_OVERVIEW_RULER_FIND_MATCH_FOREGROUND_COLOR,
27
27
  } from './terminal.color';
28
28
 
29
- import type { CanvasAddon as CanvasAddonType } from 'xterm-addon-canvas';
30
- import type { WebglAddon as WebglAddonType } from 'xterm-addon-webgl';
29
+ import type { CanvasAddon as CanvasAddonType } from '@xterm/addon-canvas';
30
+ import type { WebglAddon as WebglAddonType } from '@xterm/addon-webgl';
31
31
 
32
32
  export interface XTermOptions {
33
33
  cwd?: string;
@@ -85,7 +85,7 @@ export class XTerm extends Disposable implements IXTerm {
85
85
  try {
86
86
  if (!this._canvasAddon) {
87
87
  // @ts-ignore
88
- this._canvasAddon = new (await import('xterm-addon-canvas')).CanvasAddon();
88
+ this._canvasAddon = new (await import('@xterm/addon-canvas')).CanvasAddon();
89
89
  }
90
90
 
91
91
  this.addDispose(this._canvasAddon);
@@ -104,7 +104,7 @@ export class XTerm extends Disposable implements IXTerm {
104
104
  try {
105
105
  if (!this._webglAddon) {
106
106
  // @ts-ignore
107
- this._webglAddon = new (await import('xterm-addon-webgl')).WebglAddon();
107
+ this._webglAddon = new (await import('@xterm/addon-webgl')).WebglAddon();
108
108
  }
109
109
 
110
110
  this.addDispose(this._webglAddon);
@@ -1,4 +1,4 @@
1
- import { Terminal } from 'xterm';
1
+ import { Terminal } from '@xterm/xterm';
2
2
 
3
3
  import { Deferred, Disposable, Event, IDisposable } from '@opensumi/ide-core-common';
4
4
 
package/src/common/pty.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { Terminal as XTerm } from '@xterm/xterm';
1
2
  import { IPty as INodePty } from 'node-pty';
2
3
  import * as pty from 'node-pty';
3
- import { Terminal as XTerm } from 'xterm';
4
4
 
5
5
  import { IThemeColor, MaybePromise, OperatingSystem, Uri } from '@opensumi/ide-core-common';
6
6
 
@@ -1,4 +1,4 @@
1
- import { ITerminalOptions as IXtermTerminalOptions } from 'xterm';
1
+ import { ITerminalOptions as IXtermTerminalOptions } from '@xterm/xterm';
2
2
 
3
3
  import { IDisposable, OperatingSystem } from '@opensumi/ide-core-common';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ITheme } from 'xterm';
1
+ import { ITheme } from '@xterm/xterm';
2
2
 
3
3
  export const ITerminalTheme = Symbol('ITerminalTheme');
4
4
  export interface ITerminalTheme {
@@ -1,4 +1,4 @@
1
- import { IBufferCell } from 'xterm';
1
+ import { IBufferCell } from '@xterm/xterm';
2
2
 
3
3
  export type XTermAttributes = Omit<IBufferCell, 'getWidth' | 'getChars' | 'getCode'> & { clone?(): XTermAttributes };
4
4
 
@@ -1,4 +1,4 @@
1
- import { ITerminalOptions, ITheme, Terminal } from 'xterm';
1
+ import { ITerminalOptions, ITheme, Terminal } from '@xterm/xterm';
2
2
 
3
3
  import { SupportedOptions } from './preference';
4
4
 
package/src/node/pty.ts CHANGED
@@ -186,8 +186,8 @@ export class PtyService extends Disposable implements IPtyService {
186
186
  ) as { [key: string]: string };
187
187
  }
188
188
 
189
- // HACK: 这里的处理逻辑有些黑,后续需要整体去整理下 Shell Intergration,然后整体优化一下
190
- // 如果是启动 bash,则使用 init file 植入 Intergration 能力
189
+ // HACK: 这里的处理逻辑有些黑,后续需要整体去整理下 Shell Integration,然后整体优化一下
190
+ // 如果是启动 bash,则使用 init file 植入 Integration 能力
191
191
  if (options.executable?.includes('bash')) {
192
192
  const bashIntegrationPath = await this.shellIntegrationService.initBashInitFile();
193
193
  if (!options.args) {
@@ -202,6 +202,18 @@ export class PtyService extends Disposable implements IPtyService {
202
202
  }
203
203
  }
204
204
 
205
+ // ZSH 相关的能力注入
206
+ if (options.executable?.includes('zsh')) {
207
+ const zshDotFilesPath = await this.shellIntegrationService.initZshDotFiles();
208
+
209
+ if (!ptyEnv) {
210
+ ptyEnv = {};
211
+ }
212
+
213
+ ptyEnv['USER_ZDOTDIR'] = ptyEnv['ZDOTDIR'] || os.homedir() || '~';
214
+ ptyEnv['ZDOTDIR'] = zshDotFilesPath;
215
+ }
216
+
205
217
  this._ptyOptions['env'] = ptyEnv;
206
218
 
207
219
  const results = await Promise.all([this._validateCwd(), this._validateExecutable()]);
@@ -11,6 +11,9 @@ export interface IShellIntegrationService {
11
11
 
12
12
  // 获取 Bash 注入文件的 Content 内容
13
13
  getBashIntegrationContent(): Promise<string>;
14
+
15
+ // 初始化 zsh 注入的配置,并且返回配置的路径
16
+ initZshDotFiles(): Promise<string>;
14
17
  }
15
18
 
16
19
  // 未来适配 OpenSumi 的时候需要调整
@@ -74,4 +77,129 @@ export class ShellIntegrationService implements IShellIntegrationService {
74
77
  await fs.writeFile(bashIntegrationPath, await this.getBashIntegrationContent());
75
78
  return bashIntegrationPath;
76
79
  }
80
+
81
+ // ZSH 的智能化基于 ZDOTDIR 能力运行
82
+ async initZshDotFiles(): Promise<string> {
83
+ const zDotDir = path.join(os.tmpdir(), 'sumi-integration-zsh');
84
+ await this.writeZshConfigShellScripts(zDotDir);
85
+ return zDotDir;
86
+ }
87
+
88
+ private async writeZshConfigShellScripts(outputDir: string) {
89
+ // 定义文件内容
90
+ const shellIntegrationEnv = String.raw`
91
+ if [[ -f $USER_ZDOTDIR/.zshenv ]]; then
92
+ SUMI_ZDOTDIR=$ZDOTDIR
93
+ ZDOTDIR=$USER_ZDOTDIR
94
+
95
+ # prevent recursion
96
+ if [[ $USER_ZDOTDIR != $SUMI_ZDOTDIR ]]; then
97
+ . $USER_ZDOTDIR/.zshenv
98
+ fi
99
+
100
+ USER_ZDOTDIR=$ZDOTDIR
101
+ ZDOTDIR=$SUMI_ZDOTDIR
102
+ fi
103
+ `;
104
+
105
+ const shellIntegrationLogin = String.raw`
106
+ if [[ -f $USER_ZDOTDIR/.zlogin ]]; then
107
+ ZDOTDIR=$USER_ZDOTDIR
108
+ . $ZDOTDIR/.zlogin
109
+ fi
110
+ `;
111
+
112
+ // 处理 zProfile 的情况,需要临时切回用户的 zshrc 目录配置执行 zProfile,然后记得要切回来,否则 zshrc hack 不生效
113
+ const shellIntegrationProfile = String.raw`
114
+ if [[ -f $USER_ZDOTDIR/.zprofile ]]; then
115
+ SUMI_ZDOTDIR=$ZDOTDIR
116
+ ZDOTDIR=$USER_ZDOTDIR
117
+ . $USER_ZDOTDIR/.zprofile
118
+ ZDOTDIR=$SUMI_ZDOTDIR
119
+ fi
120
+ `;
121
+
122
+ const shellIntegrationRc = `
123
+ builtin autoload -U add-zsh-hook
124
+
125
+ if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
126
+ ZDOTDIR=$USER_ZDOTDIR
127
+ . $USER_ZDOTDIR/.zshrc
128
+ fi
129
+
130
+ __is_prompt_start() {
131
+ builtin printf '\\e]6973;PS\\a'
132
+ }
133
+
134
+ __is_prompt_end() {
135
+ builtin printf '\\e]6973;PE\\a'
136
+ }
137
+
138
+ __is_escape_value() {
139
+ builtin emulate -L zsh
140
+
141
+ # Process text byte by byte, not by codepoint.
142
+ builtin local LC_ALL=C str="$1" i byte token out=''
143
+
144
+ for (( i = 0; i < \${#str}; ++i )); do
145
+ byte="\${str:$i:1}"
146
+
147
+ # Escape backslashes and semi-colons
148
+ if [ "$byte" = "\\\\" ]; then
149
+ token="\\\\\\\\"
150
+ elif [ "$byte" = ";" ]; then
151
+ token="\\\\x3b"
152
+ elif [ "$byte" = $'\\n' ]; then
153
+ token="\\\\x0a"
154
+ elif [ "$byte" = $'\\e' ]; then
155
+ token="\\\\x1b"
156
+ elif [ "$byte" = $'\\a' ]; then
157
+ token="\\\\x07"
158
+ else
159
+ token="$byte"
160
+ fi
161
+
162
+ out+="$token"
163
+ done
164
+
165
+ builtin print -r "$out"
166
+ }
167
+
168
+ __is_update_cwd() {
169
+ builtin printf '\\e]6973;CWD;%s\\a' "$(__is_escape_value "\${PWD}")"
170
+ }
171
+
172
+ __is_update_prompt() {
173
+ __is_prior_prompt="$PS1"
174
+ if [[ $ISTERM_TESTING == "1" ]]; then
175
+ __is_prior_prompt="> "
176
+ fi
177
+ PS1="%{\$(__is_prompt_start)%}\$__is_prior_prompt%{\$(__is_prompt_end)%}"
178
+ }
179
+
180
+ __is_precmd() {
181
+ if [[ $PS1 != *"\$(__is_prompt_start)"* ]]; then
182
+ __is_update_prompt
183
+ fi
184
+ __is_update_cwd
185
+ }
186
+
187
+ __is_update_prompt
188
+ add-zsh-hook precmd __is_precmd
189
+ `;
190
+
191
+ const files = [
192
+ { name: '.zshenv', content: shellIntegrationEnv },
193
+ { name: '.zlogin', content: shellIntegrationLogin },
194
+ { name: '.zprofile', content: shellIntegrationProfile },
195
+ { name: '.zshrc', content: shellIntegrationRc },
196
+ ];
197
+
198
+ await fs.mkdir(outputDir, { recursive: true });
199
+
200
+ for (const file of files) {
201
+ const filePath = path.join(outputDir, file.name);
202
+ await fs.writeFile(filePath, file.content, 'utf-8');
203
+ }
204
+ }
77
205
  }