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

Command aware terminals #20676

Closed
Tyriar opened this issue Feb 15, 2017 · 4 comments
Closed

Command aware terminals #20676

Tyriar opened this issue Feb 15, 2017 · 4 comments
Assignees
Labels
feature-request Request for new features or functionality terminal Integrated terminal issues
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Feb 15, 2017

This is a proposal to improve VS Code's integration with the terminal output. Currently you may have noticed that the names terminals have in the dropdown may not represent the command currently being run, especially on Windows.

Problem

On Linux and macOS the behavior is to use the name of the process executable, this does update when new processes are run but unfortunately there is up to a 200ms delay in doing this as we need to poll for it.

On Windows the behavior is to always use the basename of the shell process executable (eg. powershell.exe, cmd.exe, etc.), this does not change when there is a command run or a shell change.

Due to these limitations we can't reliably tell what process/args are currently being run, and therefore cannot surface this information to integrations.

Potential Solution

A setting something like this could be introduced:

"terminal.integrated.promptMatchers": {
  "bash": "(bash-\d\.\d)?$\s(.*)",
  "cmd.exe": "..."
}

Then depending on the process title we have access to described in the Problem section, we can select the valid item from promptMatchers. This could then be used on every line of output to detect when each command starts and finished.

This would enable, among other things, the ability to register link matchers under certain conexts. For example:

// Linkify \w\.\w in the output of a ls command that will open the file when clicked
// openFile have access to the current working directory from the context
term.registerLinkMatcher(/\w\.\w/, link => openFile(link), 0, /*context*/ 'ls');

Given a shell with the default configuration this would allow us to linkify common commands in a relatively

Edge Cases

  • This wouldn't work for custom shells that are launched within a Windows terminal, for example if cmd.exe is configured and powershell.exe is launched from that terminal, the cmd.exe matcher would be used.
  • This would only work for the certain cases when we have the cwd as part of the prompt, if the prompt doesn't contain the cwd would this just be disabled?
  • What about multiple line prompts?

Questions

Related items

Blocked by

@Tyriar
Copy link
Member Author

Tyriar commented Mar 9, 2017

Related idea that would likely be more reliable on Mac/Linux xtermjs/xterm.js#576

@Tyriar
Copy link
Member Author

Tyriar commented Mar 15, 2017

The current thinking is to inject escape sequences into the prompt for supported shells (xtermjs/xterm.js#576) and fall back to regex matching (this issue), which can be customized by the user

@Tyriar
Copy link
Member Author

Tyriar commented Jul 5, 2017

Getting the cwd on windows using WDK: https://stackoverflow.com/a/25853120/1156119
Getting nested process on Windows: https://github.com/Microsoft/vscode/pull/30070/files#diff-8c4484557359fefa25fe7396aa970c56R831

@Tyriar
Copy link
Member Author

Tyriar commented Oct 7, 2019

This was for the most part done by the command tracking feature (cmd+[shift+]up/down)

@Tyriar Tyriar closed this as completed Oct 7, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality terminal Integrated terminal issues
Projects
None yet
Development

No branches or pull requests

1 participant