Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ForeignHandler by default and add command console:toggle-echo to enable ForeighHandler through context menu #4503

Merged
merged 11 commits into from May 2, 2018
18 changes: 18 additions & 0 deletions packages/console-extension/src/index.ts
Expand Up @@ -86,6 +86,9 @@ namespace CommandIDs {

export
const changeKernel = 'console:change-kernel';

export
const toggleShowAllActivity = 'console:toggle-show-all-kernel-activity';
}


Expand Down Expand Up @@ -399,6 +402,19 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
isEnabled
});

commands.addCommand(CommandIDs.toggleShowAllActivity, {
label: args => args['isPalette'] ? 'Toggle Show All Kernel Activity' : 'Show All Kernel Activity',

execute: args => {
let current = getCurrent(args);
if (!current) {
return;
}
current.console.showAllActivity = !current.console.showAllActivity;
},
isToggled: () => tracker.currentWidget ? tracker.currentWidget.console.showAllActivity : false,
isEnabled
});
// Add command palette items
[
CommandIDs.create,
Expand All @@ -410,6 +426,7 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand
CommandIDs.interrupt,
CommandIDs.changeKernel,
CommandIDs.closeAndShutdown,
CommandIDs.toggleShowAllActivity,
].forEach(command => {
palette.addItem({ command, category, args: { 'isPalette': true } });
});
Expand Down Expand Up @@ -487,6 +504,7 @@ function activateConsole(app: JupyterLab, mainMenu: IMainMenu, palette: ICommand

app.contextMenu.addItem({command: CommandIDs.clear, selector: '.jp-CodeConsole-content'});
app.contextMenu.addItem({command: CommandIDs.restart, selector: '.jp-CodeConsole'});
app.contextMenu.addItem({command: CommandIDs.toggleShowAllActivity, selector: '.jp-CodeConsole'});

return tracker;
}
2 changes: 1 addition & 1 deletion packages/console/src/foreign.ts
Expand Up @@ -160,7 +160,7 @@ class ForeignHandler implements IDisposable {
}

private _cells = new Map<string, CodeCell>();
private _enabled = true;
private _enabled = false;
private _parent: ForeignHandler.IReceiver;
private _factory: () => CodeCell;
private _isDisposed = false;
Expand Down
11 changes: 11 additions & 0 deletions packages/console/src/widget.ts
Expand Up @@ -274,6 +274,17 @@ class CodeConsole extends Widget {
super.dispose();
}

/**
* Set whether the foreignHandler is able to inject foreign cells into a
* console.
*/
get showAllActivity(): boolean {
return this._foreignHandler.enabled;
}
set showAllActivity(value: boolean) {
this._foreignHandler.enabled = value;
}

/**
* Execute the current prompt.
*
Expand Down
7 changes: 5 additions & 2 deletions tests/test-console/src/foreign.spec.ts
Expand Up @@ -147,12 +147,13 @@ describe('@jupyterlab/console', () => {

describe('#enabled', () => {

it('should default to `true`', () => {
expect(handler.enabled).to.be(true);
it('should default to `false`', () => {
expect(handler.enabled).to.be(false);
});

it('should allow foreign cells to be injected if `true`', done => {
let code = 'print("#enabled:true")';
handler.enabled = true;
handler.injected.connect(() => { done(); });
foreign.kernel.requestExecute({ code, stop_on_error: true });
});
Expand Down Expand Up @@ -224,6 +225,7 @@ describe('@jupyterlab/console', () => {

it('should inject relevant cells into the parent', done => {
let code = 'print("#onIOPubMessage:enabled")';
handler.enabled = true;
let parent = handler.parent as TestParent;
expect(parent.widgets.length).to.be(0);
handler.injected.connect(() => {
Expand All @@ -236,6 +238,7 @@ describe('@jupyterlab/console', () => {
it('should not reject relevant iopub messages', done => {
let code = 'print("#onIOPubMessage:relevant")';
let called = 0;
handler.enabled = true;
handler.rejected.connect(() => {
done(new Error('rejected relevant iopub message'));
});
Expand Down
1 change: 1 addition & 0 deletions tests/test-console/src/widget.spec.ts
Expand Up @@ -104,6 +104,7 @@ describe('console/widget', () => {

it('should reflect the contents of the widget', () => {
let force = true;
widget.showAllActivity = true;
Widget.attach(widget, document.body);
return (widget.session as ClientSession).initialize().then(() => {
return widget.execute(force);
Expand Down