|
@@ -1,7 +1,7 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import { ISessionContext } from '@jupyterlab/apputils';
|
|
|
+import { Dialog, ISessionContext } from '@jupyterlab/apputils';
|
|
|
import * as nbformat from '@jupyterlab/nbformat';
|
|
|
import { IOutputModel, IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
|
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
|
@@ -381,6 +381,40 @@ export class OutputArea extends Widget {
|
|
|
const layout = this.layout as PanelLayout;
|
|
|
layout.addWidget(panel);
|
|
|
|
|
|
+ const buttons = [
|
|
|
+ Dialog.cancelButton({ label: 'Cancel' }),
|
|
|
+ Dialog.okButton({ label: 'Select' })
|
|
|
+ ];
|
|
|
+
|
|
|
+ const modalInput = factory.createStdin({
|
|
|
+ prompt: stdinPrompt,
|
|
|
+ password,
|
|
|
+ future
|
|
|
+ });
|
|
|
+
|
|
|
+ const dialog = new Dialog<Promise<string>>({
|
|
|
+ title: 'Your input is requested',
|
|
|
+ body: modalInput,
|
|
|
+ buttons
|
|
|
+ });
|
|
|
+
|
|
|
+ void dialog.launch().then(result => {
|
|
|
+ if (result.button.accept) {
|
|
|
+ const value = result.value;
|
|
|
+ if (value) {
|
|
|
+ void value.then(v => {
|
|
|
+ // Use stdin as the stream so it does not get combined with stdout.
|
|
|
+ this.model.add({
|
|
|
+ output_type: 'stream',
|
|
|
+ name: 'stdin',
|
|
|
+ text: v + '\n'
|
|
|
+ });
|
|
|
+ panel.dispose();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
/**
|
|
|
* Wait for the stdin to complete, add it to the model (so it persists)
|
|
|
* and remove the stdin widget.
|
|
@@ -859,10 +893,19 @@ export class Stdin extends Widget implements IStdin {
|
|
|
/**
|
|
|
* The value of the widget.
|
|
|
*/
|
|
|
- get value() {
|
|
|
+ get value(): Promise<string> {
|
|
|
return this._promise.promise.then(() => this._value);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Submit and get the value of the Stdin widget.
|
|
|
+ */
|
|
|
+ getValue(): Promise<string> {
|
|
|
+ console.log('WHAT THE FUCK!');
|
|
|
+ this.submit();
|
|
|
+ return this.value;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Handle the DOM events for the widget.
|
|
|
*
|
|
@@ -874,24 +917,31 @@ export class Stdin extends Widget implements IStdin {
|
|
|
* not be called directly by user code.
|
|
|
*/
|
|
|
handleEvent(event: Event): void {
|
|
|
- const input = this._input;
|
|
|
if (event.type === 'keydown') {
|
|
|
if ((event as KeyboardEvent).keyCode === 13) {
|
|
|
// Enter
|
|
|
- this._future.sendInputReply({
|
|
|
- status: 'ok',
|
|
|
- value: input.value
|
|
|
- });
|
|
|
- if (input.type === 'password') {
|
|
|
- this._value += Array(input.value.length + 1).join('·');
|
|
|
- } else {
|
|
|
- this._value += input.value;
|
|
|
- }
|
|
|
- this._promise.resolve(void 0);
|
|
|
+ this.submit();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * Submit input value.
|
|
|
+ */
|
|
|
+ submit() {
|
|
|
+ const input = this._input;
|
|
|
+ this._future.sendInputReply({
|
|
|
+ status: 'ok',
|
|
|
+ value: input.value
|
|
|
+ });
|
|
|
+ if (input.type === 'password') {
|
|
|
+ this._value += Array(input.value.length + 1).join('·');
|
|
|
+ } else {
|
|
|
+ this._value += input.value;
|
|
|
+ }
|
|
|
+ this._promise.resolve(void 0);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Handle `after-attach` messages sent to the widget.
|
|
|
*/
|