You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allowing richer integration with integrated terminal (co-processes) #13337
*duplicateIssue identified as a duplicate of another issue(s)apifeature-requestRequest for new features or functionalityterminalGeneral terminal issues that don't fall under another label
Popular terminal emulators such as iTerm2 and ConEmu allow for user defined interaction with the content being displayed. For instance there are coprocesses and triggers in iTerm2 which allow for very powerful interactions. For instance I have a coprocess that automagically make diagnostics in VS Code when running tsc -w in iTerm2.
I think VS Code would greatly benefit from such rich interaction capabilities between the terminal and the outside-world
changed the title [-]Allowing richer integration with integrated terminal[/-][+]Allowing richer integration with integrated terminal (co-processes)[/+]on Nov 16, 2016
So triggers seem to be mainly used for syntax highlighting based on some Googling. Moving the tasks framework to an extension built on top of the integrated terminal (#15584) could probably be done using some form of triggers that run a callback as it allows matching on a particular line.
It also doesn't expose the potential security holes that coprocesses do as it doesn't touch stdin.
Johannes Rieken (@jrieken) can you go into a little more detail for your particular co-process? Could this be done with a trigger if you could grab stdout and listen for a line matching a regex?
It gets started by iTerm and simply pipes stdin to another socket. That socket is read from an extensions and marker are created for whatever comes in (a very simplifies version of the task logic).
The interesting bit is that stdin change when a new line is send but also when an existing line is modified, like a progress spinner renders etc.
The trigger bit in this is more that the trigger can be used to start a process. Like so
Have a trigger that regexes for tsc -w and then start a specific co-process
Make the co-process read and process stdin (which mirrors the terminal contents)
I'm concerned about extensions listening to stdin (eg. credentials) without the users knowledge. We could always do something like this not as part of an extension without worrying about that though.
All output in a terminal window (that is, what you see on the screen) is also input to the coprocess. All output from the coprocess acts like text that the user is typing at the keyboard.
Ah I was thinking the wrong thing for some reason. Is there anything else other than a Terminal.addTrigger(string, callback) and some way of grabbing the terminal's data stream that would be needed for your use case? Here's an example:
varcoprocessNotRunning=false;vart=window.createTerminal();t.addTrigger(/tsc-w/,line=>{console.log('tsc -w started: '+data);if(coprocessNotRunning){coprocessNotRunning=true;t.on('data',data=>coprocess(data));}});functioncoprocess(data){// Do something with the data sent from the pty process// Terminate at some point?// t.off('data', coprocess);}
I was looking at problemMatcher.ts yesterday for Dirk Bäumer (@dbaeumer)'s use case which is similar (if not the same) to yours which scans for "problems" and registers them as problems in the product. This is what I was leaning towards for the solution for that:
consttscMatcher=/^([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\):\s+(error|warning|info)\s+(TS\d+)\s*:\s*(.*)$/;t.addTrigger(tscMatcher,lineMatch=>{constfile=lineMatch[1];constlocation=lineMatch[2];constseverity=lineMatch[3];constcode=lineMatch[4];constmessage=lineMatch[5];// register as a problem});
It's not critical to turn the trigger on and off here as the tasks framework would launch the process and add the trigger immediately, when the process closes the terminal will no longer accept input.
It sends whatever is sent to the terminal including escape sequences. This is being changed though to what is printed to the terminal, something like onData(listener: (line: string) => void), see #18453
I'm not sure we can differentiate between stderr from stdout as the process is not being called directly but being run within a pseudoterminal.
Daniel Imms (@Tyriar),
What if I would like to have a way to process stdout and stderr separately? onStdoutData and onStderrData will be good enough.
How hard is it to add support for this feature?
I think it's a limitation of the library we use to only have a single fd for stderr and stdout. But anyway it's probably some time out before something like this manifests itself in the terminal api. I would need to investigate more deeply at that point.
Daniel Imms (@Tyriar) so i understand security issues that could occur if extension was able to access Terminal's stdin/stdout.
But how about changing createTerminal function so it could pass stdin/stdout as a parameter.
This way extension could create its own process, or SSH connection or whatever, and then create custom terminal for that connection.
*duplicateIssue identified as a duplicate of another issue(s)apifeature-requestRequest for new features or functionalityterminalGeneral terminal issues that don't fall under another label
Activity
[-]Allowing richer integration with integrated terminal[/-][+]Allowing richer integration with integrated terminal (co-processes)[/+]Tyriar commentedon Jan 5, 2017
So triggers seem to be mainly used for syntax highlighting based on some Googling. Moving the tasks framework to an extension built on top of the integrated terminal (#15584) could probably be done using some form of triggers that run a callback as it allows matching on a particular line.
It also doesn't expose the potential security holes that coprocesses do as it doesn't touch
stdin.Tyriar commentedon Jan 5, 2017
Johannes Rieken (@jrieken) can you go into a little more detail for your particular co-process? Could this be done with a trigger if you could grab stdout and listen for a line matching a regex?
jrieken commentedon Jan 6, 2017
My co-process goes like this:
It gets started by iTerm and simply pipes
stdinto another socket. That socket is read from an extensions and marker are created for whatever comes in (a very simplifies version of the task logic).The interesting bit is that
stdinchange when a new line is send but also when an existing line is modified, like a progress spinner renders etc.The trigger bit in this is more that the trigger can be used to start a process. Like so
tsc -wand then start a specific co-processstdin(which mirrors the terminal contents)Tyriar commentedon Jan 6, 2017
I'm concerned about extensions listening to stdin (eg. credentials) without the users knowledge. We could always do something like this not as part of an extension without worrying about that though.
jrieken commentedon Jan 6, 2017
It's not
stdinof the process that runs. iTerm takes whenever is on the screen and sends it the co-process, by that becomingstdin. That is literally the characters (including control-sequences) that are rendered. From https://www.iterm2.com/documentation-coprocesses.html:Tyriar commentedon Jan 6, 2017
Ah I was thinking the wrong thing for some reason. Is there anything else other than a
Terminal.addTrigger(string, callback)and some way of grabbing the terminal's data stream that would be needed for your use case? Here's an example:Tyriar commentedon Jan 6, 2017
I was looking at problemMatcher.ts yesterday for Dirk Bäumer (@dbaeumer)'s use case which is similar (if not the same) to yours which scans for "problems" and registers them as problems in the product. This is what I was leaning towards for the solution for that:
It's not critical to turn the trigger on and off here as the tasks framework would launch the process and add the trigger immediately, when the process closes the terminal will no longer accept input.
3 remaining items
dbaeumer commentedon Jan 10, 2017
Daniel Imms (@Tyriar) yes, that would be sufficient for me.
Add ITerminalInstance.onData internal API
KalitaAlexey commentedon Jan 16, 2017
How to use
.on('data', callback)to separate stdout and stderr?I'd like to have that.
Tyriar commentedon Jan 16, 2017
Alexey (@KalitaAlexey) right now this is only an internal api, good to know though.
KalitaAlexey commentedon Jan 16, 2017
Daniel Imms (@Tyriar),
Have you tried it already?
Does it invoke
callbackfor both stdout and stderr data?Tyriar commentedon Jan 16, 2017
It sends whatever is sent to the terminal including escape sequences. This is being changed though to what is printed to the terminal, something like
onData(listener: (line: string) => void), see #18453I'm not sure we can differentiate between stderr from stdout as the process is not being called directly but being run within a pseudoterminal.
KalitaAlexey commentedon Jan 16, 2017
Daniel Imms (@Tyriar),
What if I would like to have a way to process stdout and stderr separately?
onStdoutDataandonStderrDatawill be good enough.How hard is it to add support for this feature?
Tyriar commentedon Jan 16, 2017
I think it's a limitation of the library we use to only have a single fd for stderr and stdout. But anyway it's probably some time out before something like this manifests itself in the terminal api. I would need to investigate more deeply at that point.
BartNetJS commentedon Nov 27, 2017
Daniel Imms (@Tyriar) you mentioned this thread on #18453 (comment)
So I continue here.
What I try to do is to get the response from the commands in the terminal window into an extension (to evaluate the result and give suggestions).
You said that the ondata will not be exposed to extensions.
Is there another way to grab the command result into an extension.
Or is it possible to create a custom xterm.js integrated terminal?
Tyriar commentedon Dec 22, 2017
Bart (@BartNetJS) no it's not possible to get the data right now and needs this or a similar feature to be implemented.
zikalino commentedon Mar 19, 2018
Daniel Imms (@Tyriar) so i understand security issues that could occur if extension was able to access Terminal's stdin/stdout.
But how about changing createTerminal function so it could pass stdin/stdout as a parameter.
This way extension could create its own process, or SSH connection or whatever, and then create custom terminal for that connection.
Tyriar commentedon Apr 5, 2018
This case should be covered by #46192, merging into that