UNPKG

@dodona/papyros

Version:

Scratchpad for multiple programming languages in the browser.

130 lines (129 loc) 3.92 kB
import { SyncClient } from "comsync"; import { Backend, RunMode, WorkerDiagnostic } from "../../backend/Backend"; import { State } from "@dodona/lit-state"; import { Papyros } from "./Papyros"; import { ProgrammingLanguage } from "../../ProgrammingLanguage"; /** * Enum representing the possible states while processing code */ export declare enum RunState { Loading = "loading", Running = "running", AwaitingInput = "awaiting_input", Stopping = "stopping", Ready = "ready" } /** * Interface to represent information required when handling loading events */ export interface LoadingData { /** * List of module names that are being loaded */ modules: Array<string>; /** * The status of the import */ status: "loading" | "loaded" | "failed"; } /** * Helper component to manage and visualize the current RunState */ export declare class Runner extends State { /** * The currently used programming language */ private _programmingLanguage; get programmingLanguage(): ProgrammingLanguage; set programmingLanguage(value: ProgrammingLanguage); /** * The backend that executes the code asynchronously */ backend: Promise<SyncClient<Backend>>; /** * Current state of the program */ state: RunState; /** * An explanatory message about the current state */ stateMessage: string; /** * Previous state to restore when loading is done */ private previousState; /** * Array of packages that are being installed */ loadingPackages: Array<string>; /** * Time at which the setState call occurred */ runStartTime: number; /** * The code we are working with */ _code: string; get code(): string; set code(value: string); static CODE_SEPARATOR: string; get effectiveCode(): string; set effectiveCode(value: string); /** * Async getter for the linting diagnostics of the current code */ lintSource(): Promise<WorkerDiagnostic[]>; /** * available run modes for the current code */ runModes: Array<RunMode>; /** * The global state where we are part of */ private papyros; constructor(papyros: Papyros); /** * Stops the current run and resets the state of the program * Regular and debug output is cleared * @return {Promise<void>} Returns when the program has been reset */ reset(): Promise<void>; /** * Start the backend to enable running code */ launch(): Promise<void>; /** * Execute the code in the editor * @param {RunMode} mode The mode to run with * @return {Promise<void>} Promise of running the code */ start(mode?: RunMode): Promise<void>; /** * Interrupt the currently running code * @return {Promise<void>} Returns when the code has been interrupted */ stop(): Promise<void>; provideInput(input: string): Promise<void>; deleteFile(name: string): Promise<void>; updateFile(name: string, content: string, binary: boolean): Promise<void>; renameFile(oldName: string, newName: string): Promise<void>; upsertFile(name: string, content: string, binary: boolean): void; fetchAndAddUrl(rawUrl: string): Promise<void>; private filenameFromUrl; provideFiles(inlinedFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void>; /** * Show the current state of the program to the user * @param {RunState} state The current state of the run * @param {string} message Optional message to indicate the state */ setState(state: RunState, message?: string): void; /** * Callback to handle loading events * @param {BackendEvent} e The loading event */ private onLoad; private onStart; private onEnd; private onError; private updateRunModes; }