@jupyterlab/console 4.0.0-alpha.19 → 4.0.0-alpha.20
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/panel.d.ts +0 -4
- package/lib/panel.js +1 -6
- package/lib/panel.js.map +1 -1
- package/lib/widget.d.ts +14 -22
- package/lib/widget.js +54 -38
- package/lib/widget.js.map +1 -1
- package/package.json +25 -21
- package/src/foreign.ts +194 -0
- package/src/history.ts +370 -0
- package/src/index.ts +12 -0
- package/src/panel.ts +329 -0
- package/src/tokens.ts +18 -0
- package/src/widget.ts +1075 -0
package/src/foreign.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ISessionContext } from '@jupyterlab/apputils';
|
|
5
|
+
import { CodeCell } from '@jupyterlab/cells';
|
|
6
|
+
import * as nbformat from '@jupyterlab/nbformat';
|
|
7
|
+
import { KernelMessage } from '@jupyterlab/services';
|
|
8
|
+
import { IDisposable } from '@lumino/disposable';
|
|
9
|
+
import { Signal } from '@lumino/signaling';
|
|
10
|
+
|
|
11
|
+
const FOREIGN_CELL_CLASS = 'jp-CodeConsole-foreignCell';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A handler for capturing API messages from other sessions that should be
|
|
15
|
+
* rendered in a given parent.
|
|
16
|
+
*/
|
|
17
|
+
export class ForeignHandler implements IDisposable {
|
|
18
|
+
/**
|
|
19
|
+
* Construct a new foreign message handler.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: ForeignHandler.IOptions) {
|
|
22
|
+
this.sessionContext = options.sessionContext;
|
|
23
|
+
this.sessionContext.iopubMessage.connect(this.onIOPubMessage, this);
|
|
24
|
+
this._parent = options.parent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set whether the handler is able to inject foreign cells into a console.
|
|
29
|
+
*/
|
|
30
|
+
get enabled(): boolean {
|
|
31
|
+
return this._enabled;
|
|
32
|
+
}
|
|
33
|
+
set enabled(value: boolean) {
|
|
34
|
+
this._enabled = value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The client session used by the foreign handler.
|
|
39
|
+
*/
|
|
40
|
+
readonly sessionContext: ISessionContext;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The foreign handler's parent receiver.
|
|
44
|
+
*/
|
|
45
|
+
get parent(): ForeignHandler.IReceiver {
|
|
46
|
+
return this._parent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Test whether the handler is disposed.
|
|
51
|
+
*/
|
|
52
|
+
get isDisposed(): boolean {
|
|
53
|
+
return this._isDisposed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Dispose the resources held by the handler.
|
|
58
|
+
*/
|
|
59
|
+
dispose(): void {
|
|
60
|
+
if (this.isDisposed) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._isDisposed = true;
|
|
64
|
+
Signal.clearData(this);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Handler IOPub messages.
|
|
69
|
+
*
|
|
70
|
+
* @returns `true` if the message resulted in a new cell injection or a
|
|
71
|
+
* previously injected cell being updated and `false` for all other messages.
|
|
72
|
+
*/
|
|
73
|
+
protected onIOPubMessage(
|
|
74
|
+
sender: ISessionContext,
|
|
75
|
+
msg: KernelMessage.IIOPubMessage
|
|
76
|
+
): boolean {
|
|
77
|
+
// Only process messages if foreign cell injection is enabled.
|
|
78
|
+
if (!this._enabled) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const kernel = this.sessionContext.session?.kernel;
|
|
82
|
+
if (!kernel) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Check whether this message came from an external session.
|
|
87
|
+
const parent = this._parent;
|
|
88
|
+
const session = (msg.parent_header as KernelMessage.IHeader).session;
|
|
89
|
+
if (session === kernel.clientId) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const msgType = msg.header.msg_type;
|
|
93
|
+
const parentHeader = msg.parent_header as KernelMessage.IHeader;
|
|
94
|
+
const parentMsgId = parentHeader.msg_id as string;
|
|
95
|
+
let cell: CodeCell | undefined;
|
|
96
|
+
switch (msgType) {
|
|
97
|
+
case 'execute_input': {
|
|
98
|
+
const inputMsg = msg as KernelMessage.IExecuteInputMsg;
|
|
99
|
+
cell = this._newCell(parentMsgId);
|
|
100
|
+
const model = cell.model;
|
|
101
|
+
model.executionCount = inputMsg.content.execution_count;
|
|
102
|
+
model.sharedModel.setSource(inputMsg.content.code);
|
|
103
|
+
model.trusted = true;
|
|
104
|
+
parent.update();
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
case 'execute_result':
|
|
108
|
+
case 'display_data':
|
|
109
|
+
case 'stream':
|
|
110
|
+
case 'error': {
|
|
111
|
+
cell = this._parent.getCell(parentMsgId);
|
|
112
|
+
if (!cell) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const output: nbformat.IOutput = {
|
|
116
|
+
...msg.content,
|
|
117
|
+
output_type: msgType
|
|
118
|
+
};
|
|
119
|
+
cell.model.outputs.add(output);
|
|
120
|
+
parent.update();
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
case 'clear_output': {
|
|
124
|
+
const wait = (msg as KernelMessage.IClearOutputMsg).content.wait;
|
|
125
|
+
cell = this._parent.getCell(parentMsgId);
|
|
126
|
+
if (cell) {
|
|
127
|
+
cell.model.outputs.clear(wait);
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
default:
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create a new code cell for an input originated from a foreign session.
|
|
138
|
+
*/
|
|
139
|
+
private _newCell(parentMsgId: string): CodeCell {
|
|
140
|
+
const cell = this.parent.createCodeCell();
|
|
141
|
+
cell.addClass(FOREIGN_CELL_CLASS);
|
|
142
|
+
this._parent.addCell(cell, parentMsgId);
|
|
143
|
+
return cell;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private _enabled = false;
|
|
147
|
+
private _parent: ForeignHandler.IReceiver;
|
|
148
|
+
private _isDisposed = false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A namespace for `ForeignHandler` statics.
|
|
153
|
+
*/
|
|
154
|
+
export namespace ForeignHandler {
|
|
155
|
+
/**
|
|
156
|
+
* The instantiation options for a foreign handler.
|
|
157
|
+
*/
|
|
158
|
+
export interface IOptions {
|
|
159
|
+
/**
|
|
160
|
+
* The client session used by the foreign handler.
|
|
161
|
+
*/
|
|
162
|
+
sessionContext: ISessionContext;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The parent into which the handler will inject code cells.
|
|
166
|
+
*/
|
|
167
|
+
parent: IReceiver;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A receiver of newly created foreign cells.
|
|
172
|
+
*/
|
|
173
|
+
export interface IReceiver {
|
|
174
|
+
/**
|
|
175
|
+
* Create a cell.
|
|
176
|
+
*/
|
|
177
|
+
createCodeCell(): CodeCell;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Add a newly created cell.
|
|
181
|
+
*/
|
|
182
|
+
addCell(cell: CodeCell, msgId: string): void;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Trigger a rendering update on the receiver.
|
|
186
|
+
*/
|
|
187
|
+
update(): void;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get a cell associated with a message id.
|
|
191
|
+
*/
|
|
192
|
+
getCell(msgId: string): CodeCell | undefined;
|
|
193
|
+
}
|
|
194
|
+
}
|
package/src/history.ts
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ISessionContext } from '@jupyterlab/apputils';
|
|
5
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
6
|
+
import { KernelMessage } from '@jupyterlab/services';
|
|
7
|
+
import { IDisposable } from '@lumino/disposable';
|
|
8
|
+
import { Signal } from '@lumino/signaling';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The definition of a console history manager object.
|
|
12
|
+
*/
|
|
13
|
+
export interface IConsoleHistory extends IDisposable {
|
|
14
|
+
/**
|
|
15
|
+
* The session context used by the foreign handler.
|
|
16
|
+
*/
|
|
17
|
+
readonly sessionContext: ISessionContext | null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The current editor used by the history widget.
|
|
21
|
+
*/
|
|
22
|
+
editor: CodeEditor.IEditor | null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The placeholder text that a history session began with.
|
|
26
|
+
*/
|
|
27
|
+
readonly placeholder: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the previous item in the console history.
|
|
31
|
+
*
|
|
32
|
+
* @param placeholder - The placeholder string that gets temporarily added
|
|
33
|
+
* to the history only for the duration of one history session. If multiple
|
|
34
|
+
* placeholders are sent within a session, only the first one is accepted.
|
|
35
|
+
*
|
|
36
|
+
* @returns A Promise for console command text or `undefined` if unavailable.
|
|
37
|
+
*/
|
|
38
|
+
back(placeholder: string): Promise<string>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the next item in the console history.
|
|
42
|
+
*
|
|
43
|
+
* @param placeholder - The placeholder string that gets temporarily added
|
|
44
|
+
* to the history only for the duration of one history session. If multiple
|
|
45
|
+
* placeholders are sent within a session, only the first one is accepted.
|
|
46
|
+
*
|
|
47
|
+
* @returns A Promise for console command text or `undefined` if unavailable.
|
|
48
|
+
*/
|
|
49
|
+
forward(placeholder: string): Promise<string>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Add a new item to the bottom of history.
|
|
53
|
+
*
|
|
54
|
+
* @param item The item being added to the bottom of history.
|
|
55
|
+
*
|
|
56
|
+
* #### Notes
|
|
57
|
+
* If the item being added is undefined or empty, it is ignored. If the item
|
|
58
|
+
* being added is the same as the last item in history, it is ignored as well
|
|
59
|
+
* so that the console's history will consist of no contiguous repetitions.
|
|
60
|
+
*/
|
|
61
|
+
push(item: string): void;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Reset the history navigation state, i.e., start a new history session.
|
|
65
|
+
*/
|
|
66
|
+
reset(): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A console history manager object.
|
|
71
|
+
*/
|
|
72
|
+
export class ConsoleHistory implements IConsoleHistory {
|
|
73
|
+
/**
|
|
74
|
+
* Construct a new console history object.
|
|
75
|
+
*/
|
|
76
|
+
constructor(options: ConsoleHistory.IOptions) {
|
|
77
|
+
const { sessionContext } = options;
|
|
78
|
+
if (sessionContext) {
|
|
79
|
+
this.sessionContext = sessionContext;
|
|
80
|
+
void this._handleKernel();
|
|
81
|
+
this.sessionContext.kernelChanged.connect(this._handleKernel, this);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The client session used by the foreign handler.
|
|
87
|
+
*/
|
|
88
|
+
readonly sessionContext: ISessionContext | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The current editor used by the history manager.
|
|
92
|
+
*/
|
|
93
|
+
get editor(): CodeEditor.IEditor | null {
|
|
94
|
+
return this._editor;
|
|
95
|
+
}
|
|
96
|
+
set editor(value: CodeEditor.IEditor | null) {
|
|
97
|
+
if (this._editor === value) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const prev = this._editor;
|
|
102
|
+
if (prev) {
|
|
103
|
+
prev.edgeRequested.disconnect(this.onEdgeRequest, this);
|
|
104
|
+
prev.model.sharedModel.changed.disconnect(this.onTextChange, this);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this._editor = value;
|
|
108
|
+
|
|
109
|
+
if (value) {
|
|
110
|
+
value.edgeRequested.connect(this.onEdgeRequest, this);
|
|
111
|
+
value.model.sharedModel.changed.connect(this.onTextChange, this);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The placeholder text that a history session began with.
|
|
117
|
+
*/
|
|
118
|
+
get placeholder(): string {
|
|
119
|
+
return this._placeholder;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get whether the console history manager is disposed.
|
|
124
|
+
*/
|
|
125
|
+
get isDisposed(): boolean {
|
|
126
|
+
return this._isDisposed;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Dispose of the resources held by the console history manager.
|
|
131
|
+
*/
|
|
132
|
+
dispose(): void {
|
|
133
|
+
this._isDisposed = true;
|
|
134
|
+
this._history.length = 0;
|
|
135
|
+
Signal.clearData(this);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get the previous item in the console history.
|
|
140
|
+
*
|
|
141
|
+
* @param placeholder - The placeholder string that gets temporarily added
|
|
142
|
+
* to the history only for the duration of one history session. If multiple
|
|
143
|
+
* placeholders are sent within a session, only the first one is accepted.
|
|
144
|
+
*
|
|
145
|
+
* @returns A Promise for console command text or `undefined` if unavailable.
|
|
146
|
+
*/
|
|
147
|
+
back(placeholder: string): Promise<string> {
|
|
148
|
+
if (!this._hasSession) {
|
|
149
|
+
this._hasSession = true;
|
|
150
|
+
this._placeholder = placeholder;
|
|
151
|
+
// Filter the history with the placeholder string.
|
|
152
|
+
this.setFilter(placeholder);
|
|
153
|
+
this._cursor = this._filtered.length - 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
--this._cursor;
|
|
157
|
+
this._cursor = Math.max(0, this._cursor);
|
|
158
|
+
const content = this._filtered[this._cursor];
|
|
159
|
+
return Promise.resolve(content);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get the next item in the console history.
|
|
164
|
+
*
|
|
165
|
+
* @param placeholder - The placeholder string that gets temporarily added
|
|
166
|
+
* to the history only for the duration of one history session. If multiple
|
|
167
|
+
* placeholders are sent within a session, only the first one is accepted.
|
|
168
|
+
*
|
|
169
|
+
* @returns A Promise for console command text or `undefined` if unavailable.
|
|
170
|
+
*/
|
|
171
|
+
forward(placeholder: string): Promise<string> {
|
|
172
|
+
if (!this._hasSession) {
|
|
173
|
+
this._hasSession = true;
|
|
174
|
+
this._placeholder = placeholder;
|
|
175
|
+
// Filter the history with the placeholder string.
|
|
176
|
+
this.setFilter(placeholder);
|
|
177
|
+
this._cursor = this._filtered.length;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
++this._cursor;
|
|
181
|
+
this._cursor = Math.min(this._filtered.length - 1, this._cursor);
|
|
182
|
+
const content = this._filtered[this._cursor];
|
|
183
|
+
return Promise.resolve(content);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Add a new item to the bottom of history.
|
|
188
|
+
*
|
|
189
|
+
* @param item The item being added to the bottom of history.
|
|
190
|
+
*
|
|
191
|
+
* #### Notes
|
|
192
|
+
* If the item being added is undefined or empty, it is ignored. If the item
|
|
193
|
+
* being added is the same as the last item in history, it is ignored as well
|
|
194
|
+
* so that the console's history will consist of no contiguous repetitions.
|
|
195
|
+
*/
|
|
196
|
+
push(item: string): void {
|
|
197
|
+
if (item && item !== this._history[this._history.length - 1]) {
|
|
198
|
+
this._history.push(item);
|
|
199
|
+
}
|
|
200
|
+
this.reset();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Reset the history navigation state, i.e., start a new history session.
|
|
205
|
+
*/
|
|
206
|
+
reset(): void {
|
|
207
|
+
this._cursor = this._history.length;
|
|
208
|
+
this._hasSession = false;
|
|
209
|
+
this._placeholder = '';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Populate the history collection on history reply from a kernel.
|
|
214
|
+
*
|
|
215
|
+
* @param value The kernel message history reply.
|
|
216
|
+
*
|
|
217
|
+
* #### Notes
|
|
218
|
+
* History entries have the shape:
|
|
219
|
+
* [session: number, line: number, input: string]
|
|
220
|
+
* Contiguous duplicates are stripped out of the API response.
|
|
221
|
+
*/
|
|
222
|
+
protected onHistory(value: KernelMessage.IHistoryReplyMsg): void {
|
|
223
|
+
this._history.length = 0;
|
|
224
|
+
let last = '';
|
|
225
|
+
let current = '';
|
|
226
|
+
if (value.content.status === 'ok') {
|
|
227
|
+
for (let i = 0; i < value.content.history.length; i++) {
|
|
228
|
+
current = (value.content.history[i] as string[])[2];
|
|
229
|
+
if (current !== last) {
|
|
230
|
+
this._history.push((last = current));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Reset the history navigation cursor back to the bottom.
|
|
235
|
+
this._cursor = this._history.length;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Handle a text change signal from the editor.
|
|
240
|
+
*/
|
|
241
|
+
protected onTextChange(): void {
|
|
242
|
+
if (this._setByHistory) {
|
|
243
|
+
this._setByHistory = false;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.reset();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Handle an edge requested signal.
|
|
251
|
+
*/
|
|
252
|
+
protected onEdgeRequest(
|
|
253
|
+
editor: CodeEditor.IEditor,
|
|
254
|
+
location: CodeEditor.EdgeLocation
|
|
255
|
+
): void {
|
|
256
|
+
const sharedModel = editor.model.sharedModel;
|
|
257
|
+
const source = sharedModel.getSource();
|
|
258
|
+
|
|
259
|
+
if (location === 'top' || location === 'topLine') {
|
|
260
|
+
void this.back(source).then(value => {
|
|
261
|
+
if (this.isDisposed || !value) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (sharedModel.getSource() === value) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
this._setByHistory = true;
|
|
268
|
+
sharedModel.setSource(value);
|
|
269
|
+
let columnPos = 0;
|
|
270
|
+
columnPos = value.indexOf('\n');
|
|
271
|
+
if (columnPos < 0) {
|
|
272
|
+
columnPos = value.length;
|
|
273
|
+
}
|
|
274
|
+
editor.setCursorPosition({ line: 0, column: columnPos });
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
void this.forward(source).then(value => {
|
|
278
|
+
if (this.isDisposed) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const text = value || this.placeholder;
|
|
282
|
+
if (sharedModel.getSource() === text) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
this._setByHistory = true;
|
|
286
|
+
sharedModel.setSource(text);
|
|
287
|
+
const pos = editor.getPositionAt(text.length);
|
|
288
|
+
if (pos) {
|
|
289
|
+
editor.setCursorPosition(pos);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Handle the current kernel changing.
|
|
297
|
+
*/
|
|
298
|
+
private async _handleKernel(): Promise<void> {
|
|
299
|
+
const kernel = this.sessionContext?.session?.kernel;
|
|
300
|
+
if (!kernel) {
|
|
301
|
+
this._history.length = 0;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return kernel.requestHistory(Private.initialRequest).then(v => {
|
|
306
|
+
this.onHistory(v);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Set the filter data.
|
|
312
|
+
*
|
|
313
|
+
* @param filterStr - The string to use when filtering the data.
|
|
314
|
+
*/
|
|
315
|
+
protected setFilter(filterStr: string = ''): void {
|
|
316
|
+
// Apply the new filter and remove contiguous duplicates.
|
|
317
|
+
this._filtered.length = 0;
|
|
318
|
+
|
|
319
|
+
let last = '';
|
|
320
|
+
let current = '';
|
|
321
|
+
|
|
322
|
+
for (let i = 0; i < this._history.length; i++) {
|
|
323
|
+
current = this._history[i];
|
|
324
|
+
if (
|
|
325
|
+
current !== last &&
|
|
326
|
+
filterStr === current.slice(0, filterStr.length)
|
|
327
|
+
) {
|
|
328
|
+
this._filtered.push((last = current));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
this._filtered.push(filterStr);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private _cursor = 0;
|
|
336
|
+
private _hasSession = false;
|
|
337
|
+
private _history: string[] = [];
|
|
338
|
+
private _placeholder: string = '';
|
|
339
|
+
private _setByHistory = false;
|
|
340
|
+
private _isDisposed = false;
|
|
341
|
+
private _editor: CodeEditor.IEditor | null = null;
|
|
342
|
+
private _filtered: string[] = [];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A namespace for ConsoleHistory statics.
|
|
347
|
+
*/
|
|
348
|
+
export namespace ConsoleHistory {
|
|
349
|
+
/**
|
|
350
|
+
* The initialization options for a console history object.
|
|
351
|
+
*/
|
|
352
|
+
export interface IOptions {
|
|
353
|
+
/**
|
|
354
|
+
* The client session used by the foreign handler.
|
|
355
|
+
*/
|
|
356
|
+
sessionContext?: ISessionContext;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* A namespace for private data.
|
|
362
|
+
*/
|
|
363
|
+
namespace Private {
|
|
364
|
+
export const initialRequest: KernelMessage.IHistoryRequestMsg['content'] = {
|
|
365
|
+
output: false,
|
|
366
|
+
raw: true,
|
|
367
|
+
hist_access_type: 'tail',
|
|
368
|
+
n: 500
|
|
369
|
+
};
|
|
370
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module console
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export * from './foreign';
|
|
9
|
+
export * from './history';
|
|
10
|
+
export * from './panel';
|
|
11
|
+
export * from './tokens';
|
|
12
|
+
export * from './widget';
|