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

Terminal API: 'sendText' should be more specific #11214

Closed
egamma opened this issue Aug 30, 2016 · 8 comments
Closed

Terminal API: 'sendText' should be more specific #11214

egamma opened this issue Aug 30, 2016 · 8 comments
Assignees
Labels
terminal General terminal issues that don't fall under another label
Milestone

Comments

@egamma
Copy link
Member

egamma commented Aug 30, 2016

The documentation describes it as Send text to the terminal.

The text is actually a command that is then executed by the terminal (once terminated by a new line).

I would suggest something like this without an addNewLine parameter:

executeCommand(command: string): void;

What is a scenario where you want to append raw text to terminal? If there is one then I would suggest a separate function append.

@egamma egamma added the terminal General terminal issues that don't fall under another label label Aug 30, 2016
@egamma egamma added this to the August 2016 milestone Aug 30, 2016
@jrieken
Copy link
Member

jrieken commented Aug 31, 2016

@Tyriar Suggestions? Reactions? The confusion about sendText that it's unclear if that is like write or not. For instance is term.sendText('\x1b[31mWelcome to term.js!\x1b[m\r\n'); supposed to insert control sequences (which it doesn't) and allow arbitrary 'drawing' or is really just to a execute command?

@jrieken
Copy link
Member

jrieken commented Sep 1, 2016

@Tyriar ping

@jrieken
Copy link
Member

jrieken commented Sep 1, 2016

So, after some talks with @weinand I am getting a better understanding of this. We might along with some improved jsdoc around the topic

@weinand
Copy link
Contributor

weinand commented Sep 1, 2016

I think the sendText makes sense as a low level API (and needs good documentation to explain what it does what it doesn't).

For the next release I suggest to add some runInTerminal API on top of this. In debug land we already provide this to debug adapters:

https://github.com/Microsoft/vscode-debugadapter-node/blob/master/protocol/src/debugProtocol.ts#L175

The VS Code implementation of runInTerminal massages the arguments for the three platforms and then calls sendText:

https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts#L352

@jrieken
Copy link
Member

jrieken commented Sep 1, 2016

closing as dupe of #11276

@jrieken jrieken closed this as completed Sep 1, 2016
@Tyriar Tyriar reopened this Sep 1, 2016
@Tyriar
Copy link
Member

Tyriar commented Sep 1, 2016

Sorry for not seeing this, I took Tuesday off and didn't get through all my issues yesterday.

Terminal.sendText sends the text/data to the underlying pseudo terminal (shell), note that the text is not processed by the terminal (xterm.js) which means that it can't handle ANSI escape codes such as clearing the terminal display or @jrieken's example of printing a formatted string directly to the terminal. sendText(text, false) is essentially write to stdin for the shell process.

The typical usage should be something like this:

let someCommand = 'echo -e "abc"';
terminal.sendText(someCommand);

My concerns with @weinand's runInTerminal wrapper is that it may give the impression that it will always run some command but in actuality it may send the text to the shell while it is running something (which would queue it up in most shells) or it could send it to the program that the shell is currently running such as a command line text editor.

Also any shell could be running at the time, if Ubuntu bash or git bash is running in the Windows integrated terminal then prepareCommand will probably fail. This could even happen if the configured shell is cmd if the user ran another shell inside cmd. This was one of the reasons behind my last minute change the createTerminal to accept a configuration object (#11332), as #10917 will be essential for many consumers (I've already had 2 requests to add it).

@weinand
Copy link
Contributor

weinand commented Sep 1, 2016

@Tyriar yes, my prepareCommand might not handle all cases, but if it handles 95% of them it is still much better than your low level sendText which places the burden of implementing a runInTerminal that works on all platforms and for all shells completely on the extension author.

Can you imagine how many prepareCommand versions will be written for all the extensions that have a need for it? If one of them fixes a bug for the 'bash on Windows' problem, can you imagine how long it takes until that fix has rippled to all the copies of the prepareCommand floating around?

I believe it is preferable to have the promise of a prepareCommand that works in 99.9% of all cases in the core of VS Code, and have all the bugs reported against this coming to the same central place.

We in debug land are looking forward to the first bug filed against prepareCommand because we know that from the corresponding fix all clients will profit automatically.

The problem with commands being stuck in a queue of not yet processed commands could be solved if you would surface whether a terminal is 'busy' executing a command or whether it is 'available'. Or you could automatically launch a new instance of a terminal if the current one is busy.

@Tyriar
Copy link
Member

Tyriar commented Sep 1, 2016

I agree, just pointing out some holes 😃 #10917 will help in alleviating most of the issues.

We went over a few of the hurdles in getting the status of the command in #9957, the most damning of which is the fact that the shell could be running any number of background processes for the life the terminal. So there may not be a way of reliably reporting whether it's truly busy or just idling with a background process. I just created #11422 and referenced these discussions so we don't lose track.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
terminal General terminal issues that don't fall under another label
Projects
None yet
Development

No branches or pull requests

4 participants