@jupyterlite/repl-extension 0.6.0-alpha.0 → 0.6.0-alpha.10
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/lib/index.js +61 -82
- package/lib/index.js.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +72 -97
package/lib/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { ILabStatus, IRouter, JupyterFrontEnd, Router, } from '@jupyterlab/application';
|
|
4
|
-
import {
|
|
4
|
+
import { IThemeManager, IToolbarWidgetRegistry } from '@jupyterlab/apputils';
|
|
5
5
|
import { IConsoleTracker } from '@jupyterlab/console';
|
|
6
6
|
import { ITranslator } from '@jupyterlab/translation';
|
|
7
|
-
import { clearIcon, refreshIcon, runIcon } from '@jupyterlab/ui-components';
|
|
8
7
|
import { SingleWidgetApp } from '@jupyterlite/application';
|
|
9
8
|
import { liteIcon } from '@jupyterlite/ui-components';
|
|
10
9
|
import { Widget } from '@lumino/widgets';
|
|
@@ -16,75 +15,32 @@ const I18N_BUNDLE = 'jupyterlite';
|
|
|
16
15
|
* A plugin to add buttons to the console toolbar.
|
|
17
16
|
*/
|
|
18
17
|
const buttons = {
|
|
19
|
-
id: '@jupyterlite/
|
|
18
|
+
id: '@jupyterlite/repl-extension:buttons',
|
|
20
19
|
autoStart: true,
|
|
21
20
|
requires: [ITranslator],
|
|
22
|
-
optional: [
|
|
23
|
-
activate: (app, translator,
|
|
24
|
-
if (!tracker) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const { commands } = app;
|
|
21
|
+
optional: [IToolbarWidgetRegistry],
|
|
22
|
+
activate: (app, translator, toolbarRegistry) => {
|
|
28
23
|
const trans = translator.load(I18N_BUNDLE);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return commands.execute('console:restart-kernel');
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const restartButton = new CommandToolbarButton({
|
|
51
|
-
commands,
|
|
52
|
-
id: restartCommand,
|
|
53
|
-
});
|
|
54
|
-
const clearCommand = 'repl:clear';
|
|
55
|
-
commands.addCommand(clearCommand, {
|
|
56
|
-
caption: trans.__('Clear'),
|
|
57
|
-
icon: clearIcon,
|
|
58
|
-
execute: () => {
|
|
59
|
-
return commands.execute('console:clear');
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
const clearButton = new CommandToolbarButton({
|
|
63
|
-
commands,
|
|
64
|
-
id: clearCommand,
|
|
65
|
-
});
|
|
66
|
-
tracker.widgetAdded.connect((_, console) => {
|
|
67
|
-
const { toolbar } = console;
|
|
68
|
-
console.toolbar.addItem('run', runButton);
|
|
69
|
-
console.toolbar.addItem('restart', restartButton);
|
|
70
|
-
console.toolbar.addItem('clear', clearButton);
|
|
71
|
-
toolbar.addItem('spacer', Toolbar.createSpacerItem());
|
|
72
|
-
const node = document.createElement('a');
|
|
73
|
-
node.title = trans.__('Powered by JupyterLite');
|
|
74
|
-
node.href = 'https://github.com/jupyterlite/jupyterlite';
|
|
75
|
-
node.target = '_blank';
|
|
76
|
-
node.rel = 'noopener noreferrer';
|
|
77
|
-
const poweredBy = new Widget({ node });
|
|
78
|
-
liteIcon.element({
|
|
79
|
-
container: node,
|
|
80
|
-
elementPosition: 'center',
|
|
81
|
-
margin: '2px 2px 2px 8px',
|
|
82
|
-
height: 'auto',
|
|
83
|
-
width: '16px',
|
|
24
|
+
if (toolbarRegistry) {
|
|
25
|
+
const factory = 'ConsolePanel';
|
|
26
|
+
toolbarRegistry.addFactory(factory, 'liteIcon', (panel) => {
|
|
27
|
+
const node = document.createElement('a');
|
|
28
|
+
node.title = trans.__('Powered by JupyterLite');
|
|
29
|
+
node.href = 'https://github.com/jupyterlite/jupyterlite';
|
|
30
|
+
node.target = '_blank';
|
|
31
|
+
node.rel = 'noopener noreferrer';
|
|
32
|
+
const poweredBy = new Widget({ node });
|
|
33
|
+
liteIcon.element({
|
|
34
|
+
container: node,
|
|
35
|
+
elementPosition: 'center',
|
|
36
|
+
margin: '2px',
|
|
37
|
+
height: 'auto',
|
|
38
|
+
width: '16px',
|
|
39
|
+
});
|
|
40
|
+
poweredBy.addClass('jp-PoweredBy');
|
|
41
|
+
return poweredBy;
|
|
84
42
|
});
|
|
85
|
-
|
|
86
|
-
toolbar.insertAfter('spacer', 'powered-by', poweredBy);
|
|
87
|
-
});
|
|
43
|
+
}
|
|
88
44
|
},
|
|
89
45
|
};
|
|
90
46
|
/**
|
|
@@ -96,11 +52,11 @@ const consolePlugin = {
|
|
|
96
52
|
autoStart: true,
|
|
97
53
|
optional: [IConsoleTracker, IThemeManager],
|
|
98
54
|
activate: (app, tracker, themeManager) => {
|
|
99
|
-
var _a;
|
|
55
|
+
var _a, _b;
|
|
100
56
|
if (!tracker) {
|
|
101
57
|
return;
|
|
102
58
|
}
|
|
103
|
-
const { commands,
|
|
59
|
+
const { commands, started } = app;
|
|
104
60
|
const search = window.location.search;
|
|
105
61
|
const urlParams = new URLSearchParams(search);
|
|
106
62
|
const code = urlParams.getAll('code');
|
|
@@ -108,30 +64,53 @@ const consolePlugin = {
|
|
|
108
64
|
const kernel = urlParams.get('kernel') || undefined;
|
|
109
65
|
const theme = (_a = urlParams.get('theme')) === null || _a === void 0 ? void 0 : _a.trim();
|
|
110
66
|
const toolbar = urlParams.get('toolbar');
|
|
111
|
-
|
|
112
|
-
|
|
67
|
+
// normalize config options
|
|
68
|
+
const clearCellsOnExecute = urlParams.get('clearCellsOnExecute') === '1' || undefined;
|
|
69
|
+
const clearCodeContentOnExecute = urlParams.get('clearCodeContentOnExecute') === '0' ? false : undefined;
|
|
70
|
+
const hideCodeInput = urlParams.get('hideCodeInput') === '1' || undefined;
|
|
71
|
+
const showBanner = urlParams.get('showBanner') === '0' ? false : undefined;
|
|
72
|
+
const position = (_b = urlParams.get('promptCellPosition')) !== null && _b !== void 0 ? _b : '';
|
|
73
|
+
const validPositions = ['top', 'bottom', 'left', 'right'];
|
|
74
|
+
const promptCellPosition = validPositions.includes(position)
|
|
75
|
+
? position
|
|
76
|
+
: undefined;
|
|
77
|
+
started.then(async () => {
|
|
78
|
+
// create a new console at application startup
|
|
79
|
+
void commands.execute('console:create', {
|
|
80
|
+
kernelPreference: { name: kernel },
|
|
81
|
+
});
|
|
113
82
|
});
|
|
114
|
-
|
|
115
|
-
const themeName = decodeURIComponent(theme);
|
|
116
|
-
themeManager.setTheme(themeName);
|
|
117
|
-
}
|
|
118
|
-
tracker.widgetAdded.connect(async (_, widget) => {
|
|
119
|
-
const { console } = widget;
|
|
83
|
+
tracker.widgetAdded.connect(async (_, panel) => {
|
|
120
84
|
if (!toolbar) {
|
|
121
85
|
// hide the toolbar by default if not specified
|
|
122
|
-
|
|
86
|
+
panel.toolbar.dispose();
|
|
123
87
|
}
|
|
124
|
-
|
|
125
|
-
|
|
88
|
+
const { console: widget } = panel;
|
|
89
|
+
const { sessionContext } = widget;
|
|
90
|
+
await sessionContext.ready;
|
|
91
|
+
widget.setConfig({
|
|
92
|
+
clearCellsOnExecute,
|
|
93
|
+
clearCodeContentOnExecute,
|
|
94
|
+
hideCodeInput,
|
|
95
|
+
promptCellPosition,
|
|
96
|
+
showBanner,
|
|
97
|
+
});
|
|
98
|
+
// TODO: find a better way to make sure the banner is removed if showBanner is false
|
|
99
|
+
widget['_onKernelChanged']();
|
|
100
|
+
if (code.length > 0) {
|
|
126
101
|
if (execute === '0') {
|
|
127
102
|
const codeContent = code.join('\n');
|
|
128
|
-
|
|
103
|
+
widget.replaceSelection(codeContent);
|
|
129
104
|
}
|
|
130
105
|
else {
|
|
131
|
-
code.forEach((line) =>
|
|
106
|
+
code.forEach((line) => widget.inject(line));
|
|
132
107
|
}
|
|
133
108
|
}
|
|
134
109
|
});
|
|
110
|
+
if (theme && themeManager) {
|
|
111
|
+
const themeName = decodeURIComponent(theme);
|
|
112
|
+
themeManager.setTheme(themeName);
|
|
113
|
+
}
|
|
135
114
|
},
|
|
136
115
|
};
|
|
137
116
|
/**
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EACL,UAAU,EACV,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EACL,UAAU,EACV,OAAO,EACP,eAAe,EAEf,MAAM,GACP,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAA6B,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,GAAgC;IAC3C,EAAE,EAAE,qCAAqC;IACzC,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,CAAC,WAAW,CAAC;IACvB,QAAQ,EAAE,CAAC,sBAAsB,CAAC;IAClC,QAAQ,EAAE,CACR,GAAoB,EACpB,UAAuB,EACvB,eAA8C,EAC9C,EAAE;QACF,MAAM,K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I,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9C,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YACzB,wCAAwC;YACxC,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;YAEpB,8BAA8B;YAC9B,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;gBACvC,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC;AAEF,MAAM,OAAO,GAAiC;IAC5C,OAAO;IACP,aAAa;IACb,KAAK;IACL,MAAM;IACN,MAAM;CACP,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/repl-extension",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.10",
|
|
4
4
|
"description": "JupyterLite - Console Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -38,14 +38,13 @@
|
|
|
38
38
|
"watch": "tsc -b --watch"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@jupyterlab/application": "~4.4.
|
|
42
|
-
"@jupyterlab/apputils": "~4.5.
|
|
43
|
-
"@jupyterlab/console": "~4.4.
|
|
44
|
-
"@jupyterlab/translation": "~4.4.
|
|
45
|
-
"@jupyterlab/ui-components": "~4.4.
|
|
46
|
-
"@jupyterlite/application": "^0.6.0-alpha.
|
|
47
|
-
"@
|
|
48
|
-
"@lumino/widgets": "^2.5.0"
|
|
41
|
+
"@jupyterlab/application": "~4.4.2",
|
|
42
|
+
"@jupyterlab/apputils": "~4.5.2",
|
|
43
|
+
"@jupyterlab/console": "~4.4.2",
|
|
44
|
+
"@jupyterlab/translation": "~4.4.2",
|
|
45
|
+
"@jupyterlab/ui-components": "~4.4.2",
|
|
46
|
+
"@jupyterlite/application": "^0.6.0-alpha.10",
|
|
47
|
+
"@lumino/widgets": "^2.7.1"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@babel/core": "^7.11.6",
|
|
@@ -54,13 +53,14 @@
|
|
|
54
53
|
"jest": "^29.6.2",
|
|
55
54
|
"rimraf": "~5.0.1",
|
|
56
55
|
"ts-jest": "^29.1.1",
|
|
57
|
-
"typescript": "~5.
|
|
56
|
+
"typescript": "~5.5.4"
|
|
58
57
|
},
|
|
59
58
|
"publishConfig": {
|
|
60
59
|
"access": "public"
|
|
61
60
|
},
|
|
62
61
|
"jupyterlab": {
|
|
63
|
-
"extension": true
|
|
62
|
+
"extension": true,
|
|
63
|
+
"schemaDir": "schema"
|
|
64
64
|
},
|
|
65
65
|
"styleModule": "style/index.js"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,19 +4,17 @@
|
|
|
4
4
|
import {
|
|
5
5
|
ILabStatus,
|
|
6
6
|
IRouter,
|
|
7
|
-
JupyterFrontEndPlugin,
|
|
8
7
|
JupyterFrontEnd,
|
|
8
|
+
JupyterFrontEndPlugin,
|
|
9
9
|
Router,
|
|
10
10
|
} from '@jupyterlab/application';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { IThemeManager, IToolbarWidgetRegistry } from '@jupyterlab/apputils';
|
|
13
13
|
|
|
14
|
-
import { IConsoleTracker } from '@jupyterlab/console';
|
|
14
|
+
import { CodeConsole, ConsolePanel, IConsoleTracker } from '@jupyterlab/console';
|
|
15
15
|
|
|
16
16
|
import { ITranslator } from '@jupyterlab/translation';
|
|
17
17
|
|
|
18
|
-
import { clearIcon, refreshIcon, runIcon } from '@jupyterlab/ui-components';
|
|
19
|
-
|
|
20
18
|
import { SingleWidgetApp } from '@jupyterlite/application';
|
|
21
19
|
|
|
22
20
|
import { liteIcon } from '@jupyterlite/ui-components';
|
|
@@ -32,91 +30,38 @@ const I18N_BUNDLE = 'jupyterlite';
|
|
|
32
30
|
* A plugin to add buttons to the console toolbar.
|
|
33
31
|
*/
|
|
34
32
|
const buttons: JupyterFrontEndPlugin<void> = {
|
|
35
|
-
id: '@jupyterlite/
|
|
33
|
+
id: '@jupyterlite/repl-extension:buttons',
|
|
36
34
|
autoStart: true,
|
|
37
35
|
requires: [ITranslator],
|
|
38
|
-
optional: [
|
|
36
|
+
optional: [IToolbarWidgetRegistry],
|
|
39
37
|
activate: (
|
|
40
38
|
app: JupyterFrontEnd,
|
|
41
39
|
translator: ITranslator,
|
|
42
|
-
|
|
40
|
+
toolbarRegistry: IToolbarWidgetRegistry | null,
|
|
43
41
|
) => {
|
|
44
|
-
if (!tracker) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { commands } = app;
|
|
49
42
|
const trans = translator.load(I18N_BUNDLE);
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
execute: () => {
|
|
71
|
-
return commands.execute('console:restart-kernel');
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const restartButton = new CommandToolbarButton({
|
|
76
|
-
commands,
|
|
77
|
-
id: restartCommand,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const clearCommand = 'repl:clear';
|
|
81
|
-
commands.addCommand(clearCommand, {
|
|
82
|
-
caption: trans.__('Clear'),
|
|
83
|
-
icon: clearIcon,
|
|
84
|
-
execute: () => {
|
|
85
|
-
return commands.execute('console:clear');
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const clearButton = new CommandToolbarButton({
|
|
90
|
-
commands,
|
|
91
|
-
id: clearCommand,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
tracker.widgetAdded.connect((_, console) => {
|
|
95
|
-
const { toolbar } = console;
|
|
96
|
-
|
|
97
|
-
console.toolbar.addItem('run', runButton);
|
|
98
|
-
console.toolbar.addItem('restart', restartButton);
|
|
99
|
-
console.toolbar.addItem('clear', clearButton);
|
|
100
|
-
|
|
101
|
-
toolbar.addItem('spacer', Toolbar.createSpacerItem());
|
|
102
|
-
|
|
103
|
-
const node = document.createElement('a');
|
|
104
|
-
node.title = trans.__('Powered by JupyterLite');
|
|
105
|
-
node.href = 'https://github.com/jupyterlite/jupyterlite';
|
|
106
|
-
node.target = '_blank';
|
|
107
|
-
node.rel = 'noopener noreferrer';
|
|
108
|
-
const poweredBy = new Widget({ node });
|
|
109
|
-
liteIcon.element({
|
|
110
|
-
container: node,
|
|
111
|
-
elementPosition: 'center',
|
|
112
|
-
margin: '2px 2px 2px 8px',
|
|
113
|
-
height: 'auto',
|
|
114
|
-
width: '16px',
|
|
44
|
+
if (toolbarRegistry) {
|
|
45
|
+
const factory = 'ConsolePanel';
|
|
46
|
+
toolbarRegistry.addFactory<ConsolePanel>(factory, 'liteIcon', (panel) => {
|
|
47
|
+
const node = document.createElement('a');
|
|
48
|
+
node.title = trans.__('Powered by JupyterLite');
|
|
49
|
+
node.href = 'https://github.com/jupyterlite/jupyterlite';
|
|
50
|
+
node.target = '_blank';
|
|
51
|
+
node.rel = 'noopener noreferrer';
|
|
52
|
+
const poweredBy = new Widget({ node });
|
|
53
|
+
liteIcon.element({
|
|
54
|
+
container: node,
|
|
55
|
+
elementPosition: 'center',
|
|
56
|
+
margin: '2px',
|
|
57
|
+
height: 'auto',
|
|
58
|
+
width: '16px',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
poweredBy.addClass('jp-PoweredBy');
|
|
62
|
+
return poweredBy;
|
|
115
63
|
});
|
|
116
|
-
|
|
117
|
-
poweredBy.addClass('jp-PoweredBy');
|
|
118
|
-
toolbar.insertAfter('spacer', 'powered-by', poweredBy);
|
|
119
|
-
});
|
|
64
|
+
}
|
|
120
65
|
},
|
|
121
66
|
};
|
|
122
67
|
|
|
@@ -136,7 +81,7 @@ const consolePlugin: JupyterFrontEndPlugin<void> = {
|
|
|
136
81
|
if (!tracker) {
|
|
137
82
|
return;
|
|
138
83
|
}
|
|
139
|
-
const { commands,
|
|
84
|
+
const { commands, started } = app;
|
|
140
85
|
|
|
141
86
|
const search = window.location.search;
|
|
142
87
|
const urlParams = new URLSearchParams(search);
|
|
@@ -146,33 +91,63 @@ const consolePlugin: JupyterFrontEndPlugin<void> = {
|
|
|
146
91
|
const theme = urlParams.get('theme')?.trim();
|
|
147
92
|
const toolbar = urlParams.get('toolbar');
|
|
148
93
|
|
|
149
|
-
|
|
150
|
-
|
|
94
|
+
// normalize config options
|
|
95
|
+
const clearCellsOnExecute =
|
|
96
|
+
urlParams.get('clearCellsOnExecute') === '1' || undefined;
|
|
97
|
+
const clearCodeContentOnExecute =
|
|
98
|
+
urlParams.get('clearCodeContentOnExecute') === '0' ? false : undefined;
|
|
99
|
+
const hideCodeInput = urlParams.get('hideCodeInput') === '1' || undefined;
|
|
100
|
+
const showBanner = urlParams.get('showBanner') === '0' ? false : undefined;
|
|
101
|
+
|
|
102
|
+
const position = urlParams.get('promptCellPosition') ?? '';
|
|
103
|
+
const validPositions = ['top', 'bottom', 'left', 'right'];
|
|
104
|
+
const promptCellPosition = validPositions.includes(position)
|
|
105
|
+
? (position as CodeConsole.PromptCellPosition)
|
|
106
|
+
: undefined;
|
|
107
|
+
|
|
108
|
+
started.then(async () => {
|
|
109
|
+
// create a new console at application startup
|
|
110
|
+
void commands.execute('console:create', {
|
|
111
|
+
kernelPreference: { name: kernel },
|
|
112
|
+
});
|
|
151
113
|
});
|
|
152
114
|
|
|
153
|
-
|
|
154
|
-
const themeName = decodeURIComponent(theme);
|
|
155
|
-
themeManager.setTheme(themeName);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
tracker.widgetAdded.connect(async (_, widget) => {
|
|
159
|
-
const { console } = widget;
|
|
160
|
-
|
|
115
|
+
tracker.widgetAdded.connect(async (_, panel) => {
|
|
161
116
|
if (!toolbar) {
|
|
162
117
|
// hide the toolbar by default if not specified
|
|
163
|
-
|
|
118
|
+
panel.toolbar.dispose();
|
|
164
119
|
}
|
|
165
120
|
|
|
166
|
-
|
|
167
|
-
|
|
121
|
+
const { console: widget } = panel;
|
|
122
|
+
const { sessionContext } = widget;
|
|
123
|
+
|
|
124
|
+
await sessionContext.ready;
|
|
125
|
+
|
|
126
|
+
widget.setConfig({
|
|
127
|
+
clearCellsOnExecute,
|
|
128
|
+
clearCodeContentOnExecute,
|
|
129
|
+
hideCodeInput,
|
|
130
|
+
promptCellPosition,
|
|
131
|
+
showBanner,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// TODO: find a better way to make sure the banner is removed if showBanner is false
|
|
135
|
+
widget['_onKernelChanged']();
|
|
136
|
+
|
|
137
|
+
if (code.length > 0) {
|
|
168
138
|
if (execute === '0') {
|
|
169
139
|
const codeContent = code.join('\n');
|
|
170
|
-
|
|
140
|
+
widget.replaceSelection(codeContent);
|
|
171
141
|
} else {
|
|
172
|
-
code.forEach((line) =>
|
|
142
|
+
code.forEach((line) => widget.inject(line));
|
|
173
143
|
}
|
|
174
144
|
}
|
|
175
145
|
});
|
|
146
|
+
|
|
147
|
+
if (theme && themeManager) {
|
|
148
|
+
const themeName = decodeURIComponent(theme);
|
|
149
|
+
themeManager.setTheme(themeName);
|
|
150
|
+
}
|
|
176
151
|
},
|
|
177
152
|
};
|
|
178
153
|
|