toitware / ide-tools

Tools for working with Toit in different IDEs
MIT License
2 stars 2 forks source link

Running 'Jaguar: Flash' action while having an open 'Jaguar: Monitor' terminal misbehaves #187

Open kasperl opened 2 years ago

kasperl commented 2 years ago

Looks like we just try to issue the command 'jag flash ...' in the same terminal without stopping the running program. I would expect this to run in another terminal and fail instead.

lask commented 2 years ago

It is exactly what we do. You can only have one thing running on each port at a time which is why we reuse the terminal. If we run it in a new terminal, then you can end up with many terminals and will have to manually close all the terminals. I am not convinced that is better.

lask commented 2 years ago

We can send a Ctrl-C to make sure that everything is actually sent. Would that be better?

kasperl commented 2 years ago

Do we know that we're reusing the terminal (if it is already running)? If so, we could also just abandon the operation because it is not going to work and tell the user.

lask commented 2 years ago

We could know whether the terminal is already running (right now we don't), but we do not know whether the previous command has exited. I think there are two way to do this but neither is optimal.

Using VS Code output We could use an output instead of a terminal. In this case, we would use the node child_process lib to execute the commands and just forward the output to the appropriate output window.

The advantage would be that we can use the child process to keep track of the state of the command. In other words, we could know whether the previous command is still running.

The disadvantage here is that there is no good way to cancel a running command. We cannot extend the output view with buttons for interrupting the child process which I assume is to prevent extension developers to use outputs for other things than output. This issue extends to commands that require user interaction where we have no way of doing the interaction (we try to not use commands that require user interaction, but we have had changes to the CTL that would have been breaking for the VS Code extension if we were using output). If a command that uses a port doesn't terminate, then we have blocked that port (until it is reconnected) which is not great.

Using VS Code terminal This is what we use. We open a terminal and send commands to it.

The advantage is that it is simple and a user can always interact with the terminal. The disadvantage is that it is simple, so we cannot know whether commands are running.