Verified Commit dcebc01e authored by Jakob Moser's avatar Jakob Moser
Browse files

Add abort function

parent b0079876
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -206,6 +206,23 @@ async function pressEnter() {
    await prompt()
}

/**
 * Simulates pressing Ctrl+C to send a SIGINT command to the currently running process
 * 
 * @param {boolean} waitForPrompt If true, wait until a prompt is shown, if false, exit immediately
 */
export async function abort(waitForPrompt) {
    const textarea = document.querySelector(".term_textarea")
    textarea.dispatchEvent(new KeyboardEvent("keydown", {
        keyCode: 67,
        ctrlKey: true
    }))

    if(waitForPrompt) {
        await prompt()
    }
}

/**
 * Types the given command into the terminal and simulates an Enter press
 * The command will then be executed, and the output will be shown in the terminal