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

Provide a Callback for terminal.execute Function #107

Closed
nikitaeverywhere opened this issue Jul 6, 2017 · 7 comments
Closed

Provide a Callback for terminal.execute Function #107

nikitaeverywhere opened this issue Jul 6, 2017 · 7 comments
Assignees

Comments

@nikitaeverywhere
Copy link
Member

This issue is a result of the discussion with @wcjphoenix #106.

It would be nice to have an optional callback in terminal.execute API function, execute(command, options, callback). The callback will receive the output after command execution is done. Example:

window.onTerminalInit((terminal) => {
    terminal.execute("write $namespace", (outputChunks) => { // by default, execute does not echo output onto the user's screen
        const result = outputChunks.join("");
        if (result !== "USER") {
            terminal.print("\r\n\nPlease, change your namespace to "USER" by executing \x1b[31mzn "USER"\x1b[0m\r\n");
        }
    });
});
@nikitaeverywhere
Copy link
Member Author

Done by 19dea61.

@wcjphoenix
Copy link

Fantastic, thanks!

@nikitaeverywhere
Copy link
Member Author

Please let me know if it works as expected! :)

@wcjphoenix
Copy link

It works well as long as there is not an Error in the code that is being executed. However when there is an error, it overrides the echo=false, and prints to terminal then reprompts the user which triggers the OnOutput function which runs the execute and then causes the error to happen again causing an infinite loop. Is there a reason that errors need to be echoed all the time and if so is it possible to have an option to turn that off?

Thanks,
Walter Jaskowiak

@nikitaeverywhere
Copy link
Member Author

nikitaeverywhere commented Jul 7, 2017 via email

@wcjphoenix
Copy link

Not at all, I just threw a try catch block around it.

Have a nice weekend!

@nikitaeverywhere
Copy link
Member Author

I've fixed the error by c914b9f (v4.6.1). Now the error message should go to the outputChunks array.

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

2 participants