-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Added new command for sending custom sequence to terminal #56962
Conversation
public static readonly ID = TERMINAL_COMMAND_ID.SEND_SEQUENCE; | ||
public static readonly LABEL = nls.localize('workbench.action.terminal.sendSequence', "Send Custom Sequence To Terminal"); | ||
|
||
public runCommand(accessor: ServicesAccessor, args: any): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we type args
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
?
const text = args.text.split(' '); | ||
var terminalText; | ||
for (let i = 0; i < text.length; i++) { | ||
terminalText = ' ' + prepareTerminaText(text[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the extra space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a space at the end or at the beginning (to separate text or any command).
If we keep a space at the end, it will have an extra space(near terminal prompt) in the new line after execution is over.
return; | ||
} | ||
const text = args.text.split(' '); | ||
var terminalText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer let
to var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
} | ||
} | ||
|
||
function prepareTerminaText(text: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Termina typo, also let's make this a private member of SendSequenceTerminalCommand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Outdated
Show resolved
Hide resolved
|
||
function prepareTerminaText(text: string): string { | ||
// Hexcodes and excape char | ||
if (text.substring(0, 2).toLowerCase() === '\\x') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to happen for every character, I suggest an algorithm like this:
for each char
detect if it's hex. if so translate and "consume" the characters and move the loop to the following character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By each character
, do you mean each space separated word
? If so, this function is being called for each space separated word
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have different ideas for the end solution, you want to pass in a space separated list of characters or words that translate to characters, I think the most flexible way would be to pass in a list of characters. So instead of this:
"args": {"text": "ctrl+c up enter"}
It would be:
"args": {"text": "\x03\x1b[A\x0d"}
I think we should start with this as it supports everything and then see if we need something better. In fact if we support my proposal an extension could provide the nicer interface if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see something like this being nice:
"args": {
"keys": [
"ctrl+c",
"up",
"enter"
]
}
But I think it should live in an extension first to see if people find it useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On implementation side, implementing this is easy:
"args": {"text": "\x03\x1b[A\x0d"}
For each char, termnalInstance.sendText(String.fromChar(char))
But will it be easy enough for end user to use?
Final decision is yours. Let me know what way should we go :)
BTW, How should we handle [A
if we go that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the delay, had too many notifications 😱
- Yes, I would also expect
\a
,\b
, etc. to work as specified in this file: https://github.com/xtermjs/xterm.js/blob/f47f095b8928a6e50ce80f87d7fd11e50cf9a190/src/common/data/EscapeSequences.ts#L25, not sure if they will without special casing - text should allow spaces, using
{ "text": "hello world" }
should send that, including the space - We probably need to use
\\x03
in the keybindings.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tyriar
I'm stuck on one last thing, that I need some help with,
If I use \\x03
for ctrl+c
, it works but then terminalInstance.sendText
ignores next single char.
That is, for args: {'text': '\\x03ls\n'}
, the output on terminal is bash: s: command not found
It works as expected with args: {'text': '\\x03 ls\n'}
For upArrow
key, if I use "args": {"text": "\\x03\\x1b[A\n"}
or "args": {"text": "\\x03 \\x1b[A\n"}
I'm getting bash: s: command not found
on terminal. (last executed command is ls.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
// Arrow keys | ||
if (text.toLowerCase() === 'down') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these key strings should be handled specially, what if the user wants to send the text "down"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remove all except up
?
@Tyriar This is because this code takes care of unicode chars and convert them to appropriate string. |
@njkevlani oh you mean it works with |
Currently, this implementation works with
|
FYI you can workaround the extra
|
@njkevlani thanks for the contribution, this should land in Monday's Insiders build. |
@njkevlani check out microsoft/vscode-docs@b532d2a for the documentation I added on this. |
Thanks @Tyriar for accepting the PR :) |
I am a little confused about usage of
Note the The above works but is not what I expected, I thought the below would work:
But this later form is what I have seen used consistently in my research. Is the working code how it must be done in vscode + powershell + W10(fast ring)? |
That won't work because you don't have a |
Also on Windows things could be different, you're sending the text directly to the shell, so the shell needs to support whatever you're sending. Refer to their documentation for that. |
Of course The documentation https://code.visualstudio.com/docs/editor/integrated-terminal#_send-text-from-a-keybinding just gives two citations to exterm info that would lead one to believe And since the vscode documentation gives this example:
which works as is for me (in powershell on W10) I am still at a loss to explain why |
The fact that it's powershell is the problem, you're sending sequences that bash expects to powershell and it doesn't know how to handle it. You would need to consult the powershell documentation on whether it's even possible to send a sequence to do this. |
Fixes #56024
We can set keybindings for sending custom key sequences to terminal. Sequence is sent to current active terminal. Terminal is not created if it does not exist.
Keybinding can be create as:
Some examples of
args
are:"args": {"text": "ctrl+c ls ctrl+j"}
"args": {"text": "ctrl+c python -m http.server \n"}
"args": {"text": "ctrl+c up enter"}
"args": {"text": "ctrl+c up \\x0a"}
"args": {"text": "ctrl+c up \\X0A"}
Currently supported sequence type:
ctrl
modifierenter
\n