forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
130 lines (104 loc) · 3.4 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
CommandRegistry
} from '@phosphor/commands';
import {
CommandPalette, SplitPanel, Widget
} from '@phosphor/widgets';
import {
Session
} from '@jupyterlab/services';
import {
editorServices
} from 'jupyterlab/lib/codemirror';
import {
ConsolePanel
} from 'jupyterlab/lib/console';
import {
RenderMime
} from 'jupyterlab/lib/rendermime';
import 'jupyterlab/lib/default-theme/index.css';
import '../index.css';
let TITLE = 'Console';
function main(): void {
let path = 'dummy_path';
let query: { [key: string]: string } = Object.create(null);
window.location.search.substr(1).split('&').forEach(item => {
let pair = item.split('=');
if (pair[0]) {
query[pair[0]] = pair[1];
}
});
if (!query['path']) {
Session.startNew({ path }).then(session => { startApp(session); });
return;
}
Session.findByPath(query['path'])
.then(model => { return Session.connectTo(model.id); })
.then(session => { startApp(session); })
.catch(error => {
console.warn(`path="${query['path']}"`, error);
Session.startNew({ path }).then(session => { startApp(session); });
});
}
function startApp(session: Session.ISession) {
// Initialize the command registry with the key bindings.
let commands = new CommandRegistry();
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
commands.processKeydownEvent(event);
});
let rendermime = new RenderMime({ items: RenderMime.getDefaultItems() });
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new ConsolePanel.ContentFactory({ editorFactory });
let consolePanel = new ConsolePanel({
rendermime,
session,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
consolePanel.title.label = TITLE;
let palette = new CommandPalette({ commands });
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = 'horizontal';
panel.spacing = 0;
SplitPanel.setStretch(palette, 0);
SplitPanel.setStretch(consolePanel, 1);
Widget.attach(panel, document.body);
panel.addWidget(palette);
panel.addWidget(consolePanel);
window.onresize = () => { panel.update(); };
let selector = '.jp-ConsolePanel';
let category = 'Console';
let command: string;
command = 'console:clear';
commands.addCommand(command, {
label: 'Clear',
execute: () => { consolePanel.console.clear(); }
});
palette.addItem({ command, category });
command = 'console:execute';
commands.addCommand(command, {
label: 'Execute Prompt',
execute: () => { consolePanel.console.execute(); }
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Enter'] });
command = 'console:execute-forced';
commands.addCommand(command, {
label: 'Execute Cell (forced)',
execute: () => { consolePanel.console.execute(true); }
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Shift Enter'] });
command = 'console:linebreak';
commands.addCommand(command, {
label: 'Insert Line Break',
execute: () => { consolePanel.console.insertLinebreak(); }
});
palette.addItem({ command, category });
commands.addKeyBinding({ command, selector, keys: ['Ctrl Enter'] });
}
window.onload = main;