UNPKG

@jupyterlite/terminal

Version:
49 lines (48 loc) 1.61 kB
import { BaseShell } from '@jupyterlite/cockle'; import { DriveContentsProcessor } from '@jupyterlite/services'; /** * Shell class that uses web worker that plugs into a DriveFS via the service worker or shared * array buffer. */ export class TerminalShell extends BaseShell { /** * Instantiate a new Shell * * @param options The instantiation options for a new shell */ constructor(options) { super(options); this._contentsManager = options.contentsManager; } /** * Override base class createRemote to add handler for SharedArrayBuffer DriveFS request. */ createRemote(options) { const remote = super.createRemote(options); if (this.workerType === 'coincident') { remote.processDriveRequest = async (data) => { if (this._contentsProcessor === undefined) { this._contentsProcessor = new DriveContentsProcessor({ contentsManager: this._contentsManager }); } return await this._contentsProcessor.processDriveRequest(data); }; } return remote; } /** * Load the correct web worker. */ initWorker(options) { if (this.workerType === 'coincident') { return new Worker(new URL('./coincident.worker.js', import.meta.url), { type: 'module' }); } else { return new Worker(new URL('./comlink.worker.js', import.meta.url), { type: 'module' }); } } socket; _contentsManager; _contentsProcessor; }