Commit a6b208ed authored by Jakob Moser's avatar Jakob Moser
Browse files

Extract getCurrentPrompt method, fix a bug

The promise was resolved with "prompt" as parameter, but that
was the function itself and therefore pretty useless.

Now it correctly returns the value of the current prompt (string)
parent deb8cd1d
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -136,6 +136,18 @@ export function getTerminalContents(includeLastInteraction) {
    return contents
}

/**
 * Return the current prompt, or null, if no prompt is currently shown
 */
function getCurrentPrompt() {
    const lastInteraction = getTerminalContents(true).at(-1)
    if(lastInteraction.prompt && !lastInteraction.input?.trim()) {
        return lastInteraction.prompt
    } else {
        return null
    }
}

/**
 * Returns the current prompt as soon as one is shown
 */
@@ -144,11 +156,10 @@ function prompt() {
        const intervalId = setInterval(checkAndResolve, 100)
    
        function checkAndResolve() {
            const lastInteraction = getTerminalContents(true).at(-1)

            if(lastInteraction.prompt && !lastInteraction.input?.trim()) {
            const currentPrompt = getCurrentPrompt()
            if(currentPrompt !== null) {
                clearInterval(intervalId)
                resolve(prompt)
                resolve(currentPrompt)
            }
        }
    })