Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async push + pause #949

Open
jcubic opened this issue May 17, 2024 · 0 comments
Open

Async push + pause #949

jcubic opened this issue May 17, 2024 · 0 comments

Comments

@jcubic
Copy link
Owner

jcubic commented May 17, 2024

There is odd behavior when using the following code:

const term = $('body').terminal({}, {
    exit: false
});

function ask(message) {
    return new Promise(resolve => {
        term.push(async result => {
            term.pop();
            resolve(result);
        }, {
            prompt: message
        });
    });
}

(async function loop() {
    const command = await ask('>>> ');
    if (command === 'exit' || command === 'pause') {
        term.echo('exit');
        term.pause();
    } else {
        loop();
    }
})();

Demo.

The ask async function reads from the user but term.pause() has no effect (when you type "exit"). I'm not sure if anything can be done from the library's perspective. Other than not using async code in terminal::push(). This should be documented.

term::read() has no issue like the above code but there is a flash of the prompt before the pause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant