Verified Commit 754f232a authored by Jakob Moser's avatar Jakob Moser
Browse files

Try Ctrl+C to get to a prompt, if necessary

parent 95d88882
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
/** API to create exercises */

import { getTerminalContents, getRawTerminalContents, runCommand, runUnexecutedCommand } from "./jslinux.api.mjs"
import { getTerminalContents, getRawTerminalContents, runCommand, runUnexecutedCommand, abort, isVmLoading } from "./jslinux.api.mjs"
import { arrayEquals } from "./util.mjs"
import { getHandInToken } from "./snakeoil.mjs"
import { State } from "./state.mjs"
@@ -190,16 +190,20 @@ class ExerciseExecutionContext {
            if (getTerminalContents().length > 0) {
                // We have a prompt, so we can immediately run a command
                prepareAndResolve()
            } else {
                // We don't have a prompt, so wait until we do (by repeatedly checking)
                // TODO It might be that we never get a prompt, if an editor or pager is open. In this case, we should attempt to close the editor or pager.
                return
            }

            // We don't have a prompt, so wait until we do (by repeatedly checking).           
            const intervalId = setInterval(() => {
                if (getTerminalContents().length > 0) {
                    clearInterval(intervalId)
                    prepareAndResolve()
                } else if(!isVmLoading()) {
                    // If the vm is not loading, and we don't have a prompt, maybe the user has opened an editor or a pager.
                    // Let's try Ctrl+C, maybe that will help us get out of this.
                    abort()
                }
            }, 500)
            }
        })
    }