Skip to content

Commit

Permalink
Allow switching kernel of console prompt cell
Browse files Browse the repository at this point in the history
  • Loading branch information
BoPeng committed Mar 4, 2019
1 parent 97d60f0 commit 5ef2de5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/codemirror-sos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function markExpr(python_mode: any) {
let base_mode : any = null;
if ('base_mode' in parserConf && parserConf.base_mode) {

let mode = findMode(parserConf.base_mode.toLowerCase());
let mode = findMode(parserConf.base_mode);
if (mode) {
base_mode = CodeMirror.getMode(conf, mode);
} else {
Expand Down Expand Up @@ -381,7 +381,7 @@ function markExpr(python_mode: any) {
// switch to submode?
if (stream.eol()) {
// really
let mode = findMode(stream.current().slice(0, -1).toLowerCase());
let mode = findMode(stream.current().slice(0, -1));
if (mode) {
state.sos_state = "entering " + stream.current().slice(0, -1);
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
Manager
} from "./manager"
import { changeCellKernel } from './selectors';

export function wrapExecutor(panel: NotebookPanel) {
let kernel = panel.session.kernel;
Expand Down Expand Up @@ -146,7 +147,14 @@ function my_execute(content: KernelMessage.IExecuteRequest, disposeOnDone: boole
}

// not sure how to handle console cell yet
content.sos['cell_kernel'] = 'SoS';
let labconsole = Manager.currentConsole.console;
let last_cell = labconsole.cells.get(labconsole.cells.length - 1);
let kernel = last_cell.model.metadata.get('kernel').toString();
// use this kernel to set new one.
if (kernel != 'SoS') {
changeCellKernel(labconsole.promptCell, kernel, info);
}
content.sos['cell_kernel'] = kernel;
content.sos['cell_id'] = -1;
content.silent = false;
content.store_history = false;
Expand Down
5 changes: 5 additions & 0 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@jupyterlab/notebook';

import {
ConsolePanel,
IConsoleTracker
} from '@jupyterlab/console';

Expand Down Expand Up @@ -179,6 +180,10 @@ export class Manager {
});
}

static get currentConsole() : ConsolePanel {
return this._console_tracker.currentWidget;
}

static get commands() {
return this._commands;
}
Expand Down
2 changes: 1 addition & 1 deletion src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function changeStyleOnKernel(cell: Cell, kernel: string, info: NotebookIn
// };
// //console.log(`Set cell code mirror mode to ${cell.user_highlight.base_mode}`)
let base_mode : string = info.CodeMirrorMode.get(kernel) || info.LanguageName.get(kernel) || info.KernelName.get(kernel) || kernel;
if (!base_mode || base_mode.toLowerCase() === 'sos') {
if (!base_mode || base_mode === 'sos') {
(cell.inputArea.editorWidget.editor as CodeMirrorEditor).setOption('mode', 'sos');
} else {
(cell.inputArea.editorWidget.editor as CodeMirrorEditor).setOption('mode', {
Expand Down

0 comments on commit 5ef2de5

Please sign in to comment.