@jupyterlite/terminal
Version:
A terminal for JupyterLite
38 lines (35 loc) • 1.3 kB
text/typescript
import type { IDriveFSOptions } from '@jupyterlite/cockle';
import { ComlinkShellWorker } from '@jupyterlite/cockle';
import { DriveFS } from '@jupyterlite/services';
import { expose } from 'comlink';
/**
* Shell web worker that uses DriveFS via service worker.
* Note that this is not exported as it is accessed from Shell via the filename.
*/
class ComlinkTerminalShellWorker extends ComlinkShellWorker {
/**
* Initialize the DriveFS to mount an external file system, if available.
*/
protected override initDriveFS(options: IDriveFSOptions): void {
const { baseUrl, browsingContextId, fileSystem, mountpoint } = options;
console.log('Terminal comlink initDriveFS', baseUrl, mountpoint, browsingContextId);
if (mountpoint !== '' && baseUrl !== undefined && browsingContextId !== undefined) {
const { FS, ERRNO_CODES, PATH } = fileSystem;
const driveFS = new DriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName: '',
mountpoint,
browsingContextId
});
FS.mount(driveFS, {}, mountpoint);
console.log('Terminal connected to shared drive');
} else {
console.warn('Terminal not connected to shared drive');
}
}
}
const worker = new ComlinkTerminalShellWorker();
expose(worker);