@difizen/libro-terminal 0.1.0 → 0.1.2
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.
- package/es/configuration.d.ts +33 -0
- package/es/configuration.d.ts.map +1 -0
- package/es/connection.d.ts +3 -2
- package/es/connection.d.ts.map +1 -1
- package/es/connection.js +40 -40
- package/es/index.d.ts +9 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +10 -1
- package/es/index.less +9 -0
- package/es/manager.d.ts +3 -2
- package/es/manager.d.ts.map +1 -1
- package/es/manager.js +7 -2
- package/es/module.d.ts +1 -0
- package/es/module.d.ts.map +1 -1
- package/es/module.js +10 -4
- package/es/protocol.d.ts +1 -1
- package/es/protocol.d.ts.map +1 -1
- package/es/restapi.d.ts.map +1 -1
- package/es/restapi.js +1 -1
- package/es/stateful-view.d.ts +9 -0
- package/es/stateful-view.d.ts.map +1 -0
- package/es/stateful-view.js +35 -0
- package/es/theme-service.d.ts +21 -0
- package/es/theme-service.d.ts.map +1 -0
- package/es/theme-service.js +37 -2
- package/es/view.d.ts +77 -25
- package/es/view.d.ts.map +1 -1
- package/es/view.js +417 -120
- package/package.json +12 -7
- package/src/connection.ts +9 -3
- package/src/index.less +9 -0
- package/src/index.spec.ts +2 -2
- package/src/index.ts +10 -0
- package/src/manager.ts +7 -3
- package/src/module.ts +22 -4
- package/src/protocol.ts +2 -1
- package/src/restapi.ts +2 -1
- package/src/stateful-view.ts +20 -0
- package/src/theme-service.ts +34 -2
- package/src/view.tsx +358 -82
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-terminal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro"
|
|
@@ -31,14 +31,19 @@
|
|
|
31
31
|
"src"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@difizen/libro-core": "^0.1.
|
|
35
|
-
"@difizen/libro-common": "^0.1.
|
|
36
|
-
"@difizen/libro-kernel": "^0.1.
|
|
34
|
+
"@difizen/libro-core": "^0.1.2",
|
|
35
|
+
"@difizen/libro-common": "^0.1.2",
|
|
36
|
+
"@difizen/libro-kernel": "^0.1.2",
|
|
37
37
|
"@difizen/mana-app": "latest",
|
|
38
38
|
"@ant-design/icons": "^5.1.0",
|
|
39
|
-
"xterm": "^
|
|
40
|
-
"xterm
|
|
41
|
-
"xterm-addon-
|
|
39
|
+
"xterm-addon-search": "^0.13.0",
|
|
40
|
+
"xterm": "~5.1.0",
|
|
41
|
+
"xterm-addon-canvas": "~0.3.0",
|
|
42
|
+
"xterm-addon-fit": "~0.7.0",
|
|
43
|
+
"xterm-addon-web-links": "~0.8.0",
|
|
44
|
+
"xterm-addon-webgl": "~0.14.0",
|
|
45
|
+
"@types/lodash.throttle": "^4.1.1",
|
|
46
|
+
"lodash.throttle": "^4.1.1"
|
|
42
47
|
},
|
|
43
48
|
"peerDependencies": {
|
|
44
49
|
"antd": "^5.8.6",
|
package/src/connection.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JSONPrimitive } from '@difizen/libro-common';
|
|
2
2
|
import { URL } from '@difizen/libro-common';
|
|
3
3
|
import type { ISettings } from '@difizen/libro-kernel';
|
|
4
|
+
import { ServerConnection } from '@difizen/libro-kernel';
|
|
4
5
|
import type { Disposable, Disposed, Event } from '@difizen/mana-app';
|
|
5
6
|
import { transient } from '@difizen/mana-app';
|
|
6
7
|
import { Deferred } from '@difizen/mana-app';
|
|
@@ -38,7 +39,11 @@ export class TerminalConnection implements Disposable, Disposed {
|
|
|
38
39
|
/**
|
|
39
40
|
* Construct a new terminal session.
|
|
40
41
|
*/
|
|
41
|
-
constructor(
|
|
42
|
+
constructor(
|
|
43
|
+
@inject(TerminalOption) options: TerminalOption & { name: string },
|
|
44
|
+
@inject(ServerConnection) serverConnection: ServerConnection,
|
|
45
|
+
) {
|
|
46
|
+
this.serverSettings = serverConnection.settings;
|
|
42
47
|
this._name = options.name;
|
|
43
48
|
this._createSocket();
|
|
44
49
|
}
|
|
@@ -81,6 +86,7 @@ export class TerminalConnection implements Disposable, Disposed {
|
|
|
81
86
|
return;
|
|
82
87
|
}
|
|
83
88
|
this.disposed = true;
|
|
89
|
+
this.shutdown().catch(console.error);
|
|
84
90
|
this._updateConnectionStatus('disconnected');
|
|
85
91
|
this._clearSocket();
|
|
86
92
|
}
|
|
@@ -135,7 +141,7 @@ export class TerminalConnection implements Disposable, Disposed {
|
|
|
135
141
|
/**
|
|
136
142
|
* Reconnect to a terminal.
|
|
137
143
|
*/
|
|
138
|
-
reconnect(): Promise<void> {
|
|
144
|
+
reconnect = (): Promise<void> => {
|
|
139
145
|
this._errorIfDisposed();
|
|
140
146
|
const result = new Deferred<void>();
|
|
141
147
|
|
|
@@ -162,7 +168,7 @@ export class TerminalConnection implements Disposable, Disposed {
|
|
|
162
168
|
// Return the promise that should resolve on connection or reject if the
|
|
163
169
|
// retries don't work.
|
|
164
170
|
return result.promise;
|
|
165
|
-
}
|
|
171
|
+
};
|
|
166
172
|
|
|
167
173
|
/**
|
|
168
174
|
* Attempt a connection if we have not exhausted connection attempts.
|
package/src/index.less
ADDED
package/src/index.spec.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
+
export * from './manager.js';
|
|
2
|
+
export * from './view.js';
|
|
3
|
+
export * from './theme-service.js';
|
|
4
|
+
export * from './restapi.js';
|
|
5
|
+
export * from './configuration.js';
|
|
6
|
+
|
|
1
7
|
export * from './module.js';
|
|
8
|
+
export * from './view.js';
|
|
9
|
+
export * from './manager.js';
|
|
10
|
+
export * from './protocol.js';
|
|
11
|
+
export * from './configuration.js';
|
package/src/manager.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { Poll } from '@difizen/libro-common';
|
|
5
5
|
import type { ISettings } from '@difizen/libro-kernel';
|
|
6
|
-
import { NetworkError } from '@difizen/libro-kernel';
|
|
6
|
+
import { NetworkError, ServerConnection } from '@difizen/libro-kernel';
|
|
7
7
|
import type { Disposable, Disposed, Event } from '@difizen/mana-app';
|
|
8
8
|
import { singleton } from '@difizen/mana-app';
|
|
9
9
|
import { Emitter, inject } from '@difizen/mana-app';
|
|
@@ -31,12 +31,16 @@ export class TerminalManager implements Disposable, Disposed {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
@inject(TerminalRestAPI) terminalRestAPI: TerminalRestAPI;
|
|
34
|
+
// @inject(ServerConnection) serverConnection: ServerConnection;
|
|
34
35
|
@inject(TerminalConnectionFactory)
|
|
35
36
|
terminalConnectionFactory: TerminalConnectionFactory;
|
|
36
37
|
/**
|
|
37
38
|
* Construct a new terminal manager.
|
|
38
39
|
*/
|
|
39
|
-
constructor() {
|
|
40
|
+
constructor(@inject(ServerConnection) serverConnection: ServerConnection) {
|
|
41
|
+
this.serverSettings = serverConnection.settings;
|
|
42
|
+
|
|
43
|
+
//
|
|
40
44
|
// Start polling with exponential backoff.
|
|
41
45
|
this._pollModels = new Poll({
|
|
42
46
|
auto: false,
|
|
@@ -198,7 +202,7 @@ export class TerminalManager implements Disposable, Disposed {
|
|
|
198
202
|
/**
|
|
199
203
|
* Execute a request to the server to poll running terminals and update state.
|
|
200
204
|
*/
|
|
201
|
-
|
|
205
|
+
async requestRunning(): Promise<void> {
|
|
202
206
|
let models: TerminalModel[];
|
|
203
207
|
try {
|
|
204
208
|
models = await this.terminalRestAPI.listRunning(this.serverSettings);
|
package/src/module.ts
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KernelSpecRestAPI,
|
|
3
|
+
ServerConnection,
|
|
4
|
+
ServerManager,
|
|
5
|
+
} from '@difizen/libro-kernel';
|
|
1
6
|
import { ManaModule } from '@difizen/mana-app';
|
|
2
7
|
|
|
3
8
|
import { TerminalConfiguration } from './configuration.js';
|
|
4
9
|
import { TerminalConnection } from './connection.js';
|
|
10
|
+
import './index.less';
|
|
5
11
|
import { TerminalManager } from './manager.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
12
|
+
import {
|
|
13
|
+
TerminalConnectionFactory,
|
|
14
|
+
TerminalOption,
|
|
15
|
+
TerminalViewOption,
|
|
16
|
+
} from './protocol.js';
|
|
8
17
|
import { TerminalRestAPI } from './restapi.js';
|
|
9
18
|
import { TerminalThemeService } from './theme-service.js';
|
|
10
19
|
import { LibroTerminalView } from './view.js';
|
|
11
20
|
|
|
12
21
|
export const TerminalModule = ManaModule.create().register(
|
|
22
|
+
TerminalConfiguration,
|
|
13
23
|
TerminalConnection,
|
|
14
24
|
TerminalManager,
|
|
15
25
|
TerminalRestAPI,
|
|
26
|
+
LibroTerminalView,
|
|
27
|
+
ServerConnection,
|
|
28
|
+
ServerManager,
|
|
29
|
+
KernelSpecRestAPI,
|
|
16
30
|
{
|
|
17
31
|
token: TerminalConnectionFactory,
|
|
18
32
|
useFactory: (ctx) => {
|
|
@@ -23,7 +37,11 @@ export const TerminalModule = ManaModule.create().register(
|
|
|
23
37
|
};
|
|
24
38
|
},
|
|
25
39
|
},
|
|
26
|
-
|
|
40
|
+
{
|
|
41
|
+
token: TerminalViewOption,
|
|
42
|
+
useValue: {
|
|
43
|
+
// initialCommand: '',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
27
46
|
TerminalThemeService,
|
|
28
|
-
LibroTerminalView,
|
|
29
47
|
);
|
package/src/protocol.ts
CHANGED
|
@@ -85,8 +85,9 @@ export interface TerminalViewOption extends TerminalOption {
|
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* Whether it is a pseudo terminal where an extension controls its input and output.
|
|
88
|
+
* 在jupyter中默认用的pseudo terminal
|
|
88
89
|
*/
|
|
89
|
-
readonly isPseudoTerminal?: boolean;
|
|
90
|
+
// readonly isPseudoTerminal?: boolean;
|
|
90
91
|
|
|
91
92
|
/**
|
|
92
93
|
* Terminal attributes. Can be useful to apply some implementation specific information.
|
package/src/restapi.ts
CHANGED
|
@@ -24,7 +24,8 @@ export class TerminalRestAPI {
|
|
|
24
24
|
};
|
|
25
25
|
const response = await this.serverConnection.makeRequest(url, init, settings);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// 后端返回200
|
|
28
|
+
if (response.status !== 200) {
|
|
28
29
|
const err = await createResponseError(response);
|
|
29
30
|
throw err;
|
|
30
31
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StatefulView } from '@difizen/mana-app';
|
|
2
|
+
import { BaseView } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export abstract class BaseStatefulView extends BaseView implements StatefulView {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
// setImmediate(() => {});
|
|
8
|
+
Promise.resolve()
|
|
9
|
+
.then(() => {
|
|
10
|
+
return this.afterRestore();
|
|
11
|
+
})
|
|
12
|
+
.catch(console.error);
|
|
13
|
+
}
|
|
14
|
+
abstract storeState(): Record<string, any>;
|
|
15
|
+
abstract restoreState(oldState: Record<string, any>): void;
|
|
16
|
+
|
|
17
|
+
afterRestore() {
|
|
18
|
+
// do nothing
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/theme-service.ts
CHANGED
|
@@ -157,7 +157,7 @@ export class TerminalThemeService {
|
|
|
157
157
|
const cursorAccentColor =
|
|
158
158
|
this.colorRegistry.getCurrentColor('terminalCursor.background') ||
|
|
159
159
|
backgroundColor;
|
|
160
|
-
const
|
|
160
|
+
const selectionBackground = this.colorRegistry.getCurrentColor(
|
|
161
161
|
'terminal.selectionBackground',
|
|
162
162
|
);
|
|
163
163
|
|
|
@@ -166,7 +166,8 @@ export class TerminalThemeService {
|
|
|
166
166
|
foreground: foregroundColor,
|
|
167
167
|
cursor: cursorColor,
|
|
168
168
|
cursorAccent: cursorAccentColor,
|
|
169
|
-
|
|
169
|
+
selectionBackground: selectionBackground,
|
|
170
|
+
// selection: selectionColor,
|
|
170
171
|
};
|
|
171
172
|
// eslint-disable-next-line guard-for-in
|
|
172
173
|
for (const id in terminalAnsiColorMap) {
|
|
@@ -177,4 +178,35 @@ export class TerminalThemeService {
|
|
|
177
178
|
}
|
|
178
179
|
return theme;
|
|
179
180
|
}
|
|
181
|
+
|
|
182
|
+
getTheme(type: 'light' | 'dark' | 'default' = 'light'): ITheme {
|
|
183
|
+
switch (type) {
|
|
184
|
+
case 'light':
|
|
185
|
+
return this.lightTheme;
|
|
186
|
+
case 'dark':
|
|
187
|
+
return this.darkTheme;
|
|
188
|
+
case 'default':
|
|
189
|
+
default:
|
|
190
|
+
return this.theme;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// jupyter terminal theme
|
|
195
|
+
lightTheme: ITheme = {
|
|
196
|
+
foreground: '#000',
|
|
197
|
+
background: '#fff',
|
|
198
|
+
cursor: '#616161', // md-grey-700
|
|
199
|
+
cursorAccent: '#F5F5F5', // md-grey-100
|
|
200
|
+
selectionBackground: 'rgba(97, 97, 97, 0.3)', // md-grey-700
|
|
201
|
+
selectionInactiveBackground: 'rgba(189, 189, 189, 0.3)', // md-grey-400
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
darkTheme: ITheme = {
|
|
205
|
+
foreground: '#fff',
|
|
206
|
+
background: '#000',
|
|
207
|
+
cursor: '#fff',
|
|
208
|
+
cursorAccent: '#000',
|
|
209
|
+
selectionBackground: 'rgba(255, 255, 255, 0.3)',
|
|
210
|
+
selectionInactiveBackground: 'rgba(238, 238, 238, 0.3)', // md-grey-200
|
|
211
|
+
};
|
|
180
212
|
}
|