Commit 0bb5f3a0 authored by Jakob Moser's avatar Jakob Moser
Browse files

Clear verification commands after they were run

Closes #42
parent 450c434d
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -162,6 +162,18 @@ class ExerciseExecutionContext {
     * @param {boolean} keepVisible
     */
    prepareWith(command, keepVisible) {
        return this.#prepareWith(command, keepVisible)
    }

    /**
     * Private method actually doing all the work of prepareWith.
     * 
     * Needed because the prepareWith public API is disabled in retry contexts, but we still need
     * it internally.
     * @param {string} command
     * @param {boolean} keepVisible
     */
    #prepareWith(command, keepVisible) {
        return new Promise((resolve, _) => {

            async function prepareAndResolve() {
@@ -194,7 +206,15 @@ class ExerciseExecutionContext {
     * Clear the terminal. Shorthand for prepareWith(null, false)
     */
    async clear() {
        await this.prepareWith(null, false)
        await this.#clear()
    }

    /**
     * Private method actually clearing the terminal. Again, this is needed because the clear() public API
     * method is disabled in retry contexts, but we still need it internally.
     */
    async #clear() {
        await this.#prepareWith(null, false)
    }

    /**
@@ -246,8 +266,7 @@ class ExerciseExecutionContext {
        // if no command is provided, directly start with a resolved promise.
        const commandPromise = command ? runCommand(command) : Promise.resolve()
        const verifyHandler = this._verifyHandler
        // TODO This won't work if the user is already retrying the exercise, because then the public clear API is disabled
        const clear = this.clear.bind(this)
        const clear = this.#clear.bind(this)

        return {
            /**