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

Merged
merged 7 commits into from Sep 8, 2018

Conversation

Projects
None yet
3 participants
@njkevlani
Contributor

njkevlani commented Aug 22, 2018

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:

"key": "ctrl+shift+alt+p",
"command": "workbench.action.terminal.sendSequence",
"args": {"text": TEXT}

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:

  1. Hexcode
  2. Key strokes with ctrl modifier
  3. enter
  4. Arrow keys
  5. Escape chars like \n
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 {

This comment has been minimized.

@Tyriar

Tyriar Aug 23, 2018

Member

Can we type args?

@Tyriar

Tyriar Aug 23, 2018

Member

Can we type args?

This comment has been minimized.

@njkevlani

njkevlani Aug 23, 2018

Contributor

string?

@njkevlani

njkevlani Aug 23, 2018

Contributor

string?

Show outdated Hide outdated src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show outdated Hide outdated src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show outdated Hide outdated src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show resolved Hide resolved src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show resolved Hide resolved src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show outdated Hide outdated src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
Show outdated Hide outdated src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts
@njkevlani

This comment has been minimized.

Show comment
Hide comment
@njkevlani

njkevlani Sep 1, 2018

Contributor

@Tyriar
One thing that I noticed is that, if we pass "args": {"text": "\u0003\u001b[A\n"}, it works without any preprocessing. That is in this case we can directly call terminalInstance.sendText(args.text, false)

This is because this code takes care of unicode chars and convert them to appropriate string.
If we add same type of rules for hex chars, we can make code much cleaner :)

Contributor

njkevlani commented Sep 1, 2018

@Tyriar
One thing that I noticed is that, if we pass "args": {"text": "\u0003\u001b[A\n"}, it works without any preprocessing. That is in this case we can directly call terminalInstance.sendText(args.text, false)

This is because this code takes care of unicode chars and convert them to appropriate string.
If we add same type of rules for hex chars, we can make code much cleaner :)

@Tyriar

This comment has been minimized.

Show comment
Hide comment
@Tyriar

Tyriar Sep 4, 2018

Member

@njkevlani oh you mean it works with \u formatting currently? That should be good enough.

Member

Tyriar commented Sep 4, 2018

@njkevlani oh you mean it works with \u formatting currently? That should be good enough.

@njkevlani

This comment has been minimized.

Show comment
Hide comment
@njkevlani

njkevlani Sep 4, 2018

Contributor

Currently, this implementation works with args similar to following examples.

"args": {"text": "\u0003\r\u001b[A\n"}
"args": {"text": "\u0003\rpython -m http.server\n"}

Contributor

njkevlani commented Sep 4, 2018

Currently, this implementation works with args similar to following examples.

"args": {"text": "\u0003\r\u001b[A\n"}
"args": {"text": "\u0003\rpython -m http.server\n"}

@Tyriar

This comment has been minimized.

Show comment
Hide comment
@Tyriar

Tyriar Sep 8, 2018

Member

FYI you can workaround the extra \r if you use mac with the new platform-specific keybindings:

[
	{
		"key": "ctrl+q",
		"command": "workbench.action.terminal.sendSequence",
		"args": { "text": "\u0003\u001b[A\n" },
		"when": "isMac"
	},
	{
		"key": "ctrl+q",
		"command": "workbench.action.terminal.sendSequence",
		"args": { "text": "\u0003\r\u001b[A\n" },
		"when": "isLinux"
	}
]
Member

Tyriar commented Sep 8, 2018

FYI you can workaround the extra \r if you use mac with the new platform-specific keybindings:

[
	{
		"key": "ctrl+q",
		"command": "workbench.action.terminal.sendSequence",
		"args": { "text": "\u0003\u001b[A\n" },
		"when": "isMac"
	},
	{
		"key": "ctrl+q",
		"command": "workbench.action.terminal.sendSequence",
		"args": { "text": "\u0003\r\u001b[A\n" },
		"when": "isLinux"
	}
]

@Tyriar Tyriar added this to the September 2018 milestone Sep 8, 2018

@Tyriar

This comment has been minimized.

Show comment
Hide comment
@Tyriar

Tyriar Sep 8, 2018

Member

@njkevlani thanks for the contribution, this should land in Monday's Insiders build.

Member

Tyriar commented Sep 8, 2018

@njkevlani thanks for the contribution, this should land in Monday's Insiders build.

@Tyriar

Tyriar approved these changes Sep 8, 2018

@Tyriar Tyriar merged commit 4bfc0a6 into Microsoft:master Sep 8, 2018

1 of 2 checks passed

VS Code in progress
Details
license/cla All CLA requirements met.
Details
@Tyriar

This comment has been minimized.

Show comment
Hide comment
@Tyriar

Tyriar Sep 8, 2018

Member

@njkevlani check out Microsoft/vscode-docs@b532d2a for the documentation I added on this.

Member

Tyriar commented Sep 8, 2018

@njkevlani check out Microsoft/vscode-docs@b532d2a for the documentation I added on this.

@njkevlani

This comment has been minimized.

Show comment
Hide comment
@njkevlani

njkevlani Sep 9, 2018

Contributor

Thanks @Tyriar for accepting the PR :)

Contributor

njkevlani commented Sep 9, 2018

Thanks @Tyriar for accepting the PR :)

@njkevlani njkevlani deleted the njkevlani:feature-56024 branch Sep 9, 2018

@mikelward

This comment has been minimized.

Show comment
Hide comment
@mikelward

mikelward Oct 10, 2018

Looks like this fixes #31262. Thanks!

mikelward commented on 9a384a4 Oct 10, 2018

Looks like this fixes #31262. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment