import { CodeConsole , ConsolePanel } from '@jupyterlab/console' ; import { Cell , CodeCell } from '@jupyterlab/cells' ; import { IObservableMap , ObservableMap } from '@jupyterlab/observables' ; import { each } from '@lumino/algorithm' ; import { IDisposable } from '@lumino/disposable' ; import { Signal } from '@lumino/signaling' ; import { EditorHandler } from '../handlers/editor' ; import { IDebugger } from '../tokens' ; /**
 * A handler for consoles.
 */ export class ConsoleHandler implements IDisposable { param options constructor ( options ) { this . _debuggerService = options . debuggerService ; this . _consolePanel = options . widget ; this . _cellMap = new ObservableMap < EditorHandler > ( ) ; const codeConsole = this . _consolePanel . console ; this . _addEditorHandler ( codeConsole . promptCell ) ; codeConsole . promptCellCreated . connect ( ( _ , cell ) => { this . _addEditorHandler ( cell ) ; } ) ; const addHandlers = ( ) : void => { each ( codeConsole . cells , cell => this . _addEditorHandler ( cell ) ) ; } ; addHandlers ( ) ; this . _consolePanel . console . cells . changed . connect ( addHandlers ) ; } /**
     * Whether the handler is disposed.
     */ isDisposed : boolean ; /**
     * Dispose the handler.
     */ dispose ( ) { if ( this . isDisposed ) { return ; } this . isDisposed = true ; this . _cellMap . values ( ) . forEach ( handler => handler . dispose ( ) ) ; this . _cellMap . dispose ( ) ; Signal . clearData ( this ) ; } param cell private _addEditorHandler ( cell ) { const modelId = cell . model . id ; if ( cell . model . type !== 'code' || this . _cellMap . has ( modelId ) ) { return ; } const codeCell = cell as CodeCell ; const editorHandler = new EditorHandler ( { debuggerService : this . _debuggerService , editor : codeCell . editor } ) ; codeCell . disposed . connect ( ( ) => { this . _cellMap . delete ( modelId ) ; editorHandler . dispose ( ) ; } ) ; this . _cellMap . set ( modelId , editorHandler ) ; } private _consolePanel : ConsolePanel ; private _debuggerService : IDebugger ; private _cellMap : IObservableMap < EditorHandler > = null ; } /**
 * A namespace for ConsoleHandler `statics`.
 */ export namespace ConsoleHandler { /**
     * Instantiation options for `ConsoleHandler`.
     */ export interface IOptions { /**
         * The debugger service.
         */ debuggerService : IDebugger ; /**
         * The widget to handle.
         */ widget : ConsolePanel ; } }