From 9a384a4fa5281268aeeb6cfd62812bdc89b7c191 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Wed, 22 Aug 2018 08:57:27 +0530 Subject: [PATCH 1/6] Added new command for sending custom sequence to terminal --- .../parts/terminal/common/terminalCommands.ts | 5 +- .../electron-browser/terminal.contribution.ts | 8 ++- .../electron-browser/terminalActions.ts | 62 ++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/parts/terminal/common/terminalCommands.ts b/src/vs/workbench/parts/terminal/common/terminalCommands.ts index 8d5345ed224be..89781821f8323 100644 --- a/src/vs/workbench/parts/terminal/common/terminalCommands.ts +++ b/src/vs/workbench/parts/terminal/common/terminalCommands.ts @@ -54,7 +54,8 @@ export const enum TERMINAL_COMMAND_ID { SELECT_TO_NEXT_COMMAND = 'workbench.action.terminal.selectToNextCommand', SELECT_TO_PREVIOUS_LINE = 'workbench.action.terminal.selectToPreviousLine', SELECT_TO_NEXT_LINE = 'workbench.action.terminal.selectToNextLine', - TOGGLE_ESCAPE_SEQUENCE_LOGGING = 'toggleEscapeSequenceLogging' + TOGGLE_ESCAPE_SEQUENCE_LOGGING = 'toggleEscapeSequenceLogging', + SEND_SEQUENCE = 'workbench.action.terminal.sendSequence' } @@ -79,4 +80,4 @@ function registerOpenTerminalAtIndexCommands(): void { } }); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts index 9ef058f299459..eaa6e1db6f8a4 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts @@ -17,7 +17,7 @@ import { getTerminalDefaultShellUnixLike, getTerminalDefaultShellWindows } from import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; -import { KillTerminalAction, ClearSelectionTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, CreateNewInActiveWorkspaceTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, RenameTerminalAction, SelectAllTerminalAction, FocusTerminalFindWidgetAction, HideTerminalFindWidgetAction, DeleteWordLeftTerminalAction, DeleteWordRightTerminalAction, QuickOpenActionTermContributor, QuickOpenTermAction, TERMINAL_PICKER_PREFIX, MoveToLineStartTerminalAction, MoveToLineEndTerminalAction, SplitTerminalAction, SplitInActiveWorkspaceTerminalAction, FocusPreviousPaneTerminalAction, FocusNextPaneTerminalAction, ResizePaneLeftTerminalAction, ResizePaneRightTerminalAction, ResizePaneUpTerminalAction, ResizePaneDownTerminalAction, ScrollToPreviousCommandAction, ScrollToNextCommandAction, SelectToPreviousCommandAction, SelectToNextCommandAction, SelectToPreviousLineAction, SelectToNextLineAction, ToggleEscapeSequenceLoggingAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions'; +import { KillTerminalAction, ClearSelectionTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, CreateNewInActiveWorkspaceTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, RenameTerminalAction, SelectAllTerminalAction, FocusTerminalFindWidgetAction, HideTerminalFindWidgetAction, DeleteWordLeftTerminalAction, DeleteWordRightTerminalAction, QuickOpenActionTermContributor, QuickOpenTermAction, TERMINAL_PICKER_PREFIX, MoveToLineStartTerminalAction, MoveToLineEndTerminalAction, SplitTerminalAction, SplitInActiveWorkspaceTerminalAction, FocusPreviousPaneTerminalAction, FocusNextPaneTerminalAction, ResizePaneLeftTerminalAction, ResizePaneRightTerminalAction, ResizePaneUpTerminalAction, ResizePaneDownTerminalAction, ScrollToPreviousCommandAction, ScrollToNextCommandAction, SelectToPreviousCommandAction, SelectToNextCommandAction, SelectToPreviousLineAction, SelectToNextLineAction, ToggleEscapeSequenceLoggingAction, SendSequenceTerminalCommand } from 'vs/workbench/parts/terminal/electron-browser/terminalActions'; import { Registry } from 'vs/platform/registry/common/platform'; import { ShowAllCommandsAction } from 'vs/workbench/parts/quickopen/browser/commandsHandler'; import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; @@ -534,6 +534,12 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToPrevious actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToNextLineAction, SelectToNextLineAction.ID, SelectToNextLineAction.LABEL), 'Terminal: Select To Next Line', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleEscapeSequenceLoggingAction, ToggleEscapeSequenceLoggingAction.ID, ToggleEscapeSequenceLoggingAction.LABEL), 'Terminal: Toggle Escape Sequence Logging', category); +const sendSequenceTerminalCommand = new SendSequenceTerminalCommand({ + id: SendSequenceTerminalCommand.ID, + precondition: null +}); +sendSequenceTerminalCommand.register(); + setupTerminalCommands(); setupTerminalMenu(); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index d1cafbd699d0c..2ff593a5fb359 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -20,13 +20,14 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IQuickInputService, IPickOptions, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput'; import { ActionBarContributor } from 'vs/workbench/browser/actions'; import { TerminalEntry } from 'vs/workbench/parts/terminal/browser/terminalQuickOpen'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { TERMINAL_COMMAND_ID } from 'vs/workbench/parts/terminal/common/terminalCommands'; +import { Command } from 'vs/editor/browser/editorExtensions'; export const TERMINAL_PICKER_PREFIX = 'term '; @@ -227,6 +228,65 @@ export class MoveToLineEndTerminalAction extends BaseSendTextTerminalAction { } } +export class SendSequenceTerminalCommand extends Command { + 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 { + const terminalInstance = accessor.get(ITerminalService).getActiveInstance(); + if (!terminalInstance) { + return; + } + const text = args.text.split(' '); + var terminalText; + for (let i = 0; i < text.length; i++) { + terminalText = ' ' + prepareTerminaText(text[i]); + terminalInstance.sendText(terminalText, false); + } + } +} + +function prepareTerminaText(text: string): string { + // Hexcodes and excape char + if (text.substring(0, 2).toLowerCase() === '\\x') { + // Valid hex with 2 digits + // var isOk = /^\\x[0-9a-f]{2}$/i.test(text); + if (/^\\x[0-9a-f]{2}$/i.test(text)) { + return String.fromCharCode(parseInt(text.substring(2), 16)); + } + } + + // ctrl modifier with single char + if (text.indexOf('+') >= 0) { + const text1 = text.split('+'); + if (text1[0].toLowerCase() === 'ctrl') { + if (text1[1].length === 1) { + return String.fromCharCode(text1[1].toUpperCase().charCodeAt(0) - 64); + } + } + } + // handle enter + if (text.toLowerCase() === 'enter') { + return '\n'; + } + + // Arrow keys + if (text.toLowerCase() === 'down') { + return String.fromCharCode(15); + } + if (text.toLowerCase() === 'up') { + return String.fromCharCode(16); + } + if (text.toLowerCase() === 'right') { + return String.fromCharCode(17); + } + if (text.toLowerCase() === 'left') { + return String.fromCharCode(18); + } + + return text; +} + export class CreateNewTerminalAction extends Action { public static readonly ID = TERMINAL_COMMAND_ID.NEW; From 6a6c809888859e57922460804b62ece0d0e1d993 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Wed, 22 Aug 2018 09:06:10 +0530 Subject: [PATCH 2/6] Added new command for sending custom sequence to terminal --- .../workbench/parts/terminal/electron-browser/terminalActions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index 2ff593a5fb359..c082b6838c680 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -250,7 +250,6 @@ function prepareTerminaText(text: string): string { // Hexcodes and excape char if (text.substring(0, 2).toLowerCase() === '\\x') { // Valid hex with 2 digits - // var isOk = /^\\x[0-9a-f]{2}$/i.test(text); if (/^\\x[0-9a-f]{2}$/i.test(text)) { return String.fromCharCode(parseInt(text.substring(2), 16)); } From a10e863cd1bb9b8012c85be7cf116bf773d068fe Mon Sep 17 00:00:00 2001 From: Nilesh Date: Fri, 24 Aug 2018 00:32:20 +0530 Subject: [PATCH 3/6] Fixed Typo --- .../parts/terminal/electron-browser/terminalActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index c082b6838c680..e3ec77b0699a2 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -240,13 +240,13 @@ export class SendSequenceTerminalCommand extends Command { const text = args.text.split(' '); var terminalText; for (let i = 0; i < text.length; i++) { - terminalText = ' ' + prepareTerminaText(text[i]); + terminalText = ' ' + prepareTerminalText(text[i]); terminalInstance.sendText(terminalText, false); } } } -function prepareTerminaText(text: string): string { +function prepareTerminalText(text: string): string { // Hexcodes and excape char if (text.substring(0, 2).toLowerCase() === '\\x') { // Valid hex with 2 digits From abde15619adef32a6b876de9f1ae9e81a5592ec1 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Fri, 24 Aug 2018 00:34:36 +0530 Subject: [PATCH 4/6] Changed Declearation --- .../parts/terminal/electron-browser/terminalActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index e3ec77b0699a2..c95e796cc9e10 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -238,7 +238,7 @@ export class SendSequenceTerminalCommand extends Command { return; } const text = args.text.split(' '); - var terminalText; + let terminalText; for (let i = 0; i < text.length; i++) { terminalText = ' ' + prepareTerminalText(text[i]); terminalInstance.sendText(terminalText, false); From ea66a9f44d8095e3cfcc8c800d5879152a630065 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Fri, 24 Aug 2018 00:51:19 +0530 Subject: [PATCH 5/6] Changed scop of function --- .../electron-browser/terminalActions.ts | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index c95e796cc9e10..fd43100011ebe 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -240,50 +240,50 @@ export class SendSequenceTerminalCommand extends Command { const text = args.text.split(' '); let terminalText; for (let i = 0; i < text.length; i++) { - terminalText = ' ' + prepareTerminalText(text[i]); + terminalText = ' ' + this.prepareTerminalText(text[i]); terminalInstance.sendText(terminalText, false); } } -} -function prepareTerminalText(text: string): string { - // Hexcodes and excape char - if (text.substring(0, 2).toLowerCase() === '\\x') { - // Valid hex with 2 digits - if (/^\\x[0-9a-f]{2}$/i.test(text)) { - return String.fromCharCode(parseInt(text.substring(2), 16)); + private prepareTerminalText(text: string): string { + // Hexcodes and excape char + if (text.substring(0, 2).toLowerCase() === '\\x') { + // Valid hex with 2 digits + if (/^\\x[0-9a-f]{2}$/i.test(text)) { + return String.fromCharCode(parseInt(text.substring(2), 16)); + } } - } - // ctrl modifier with single char - if (text.indexOf('+') >= 0) { - const text1 = text.split('+'); - if (text1[0].toLowerCase() === 'ctrl') { - if (text1[1].length === 1) { - return String.fromCharCode(text1[1].toUpperCase().charCodeAt(0) - 64); + // ctrl modifier with single char + if (text.indexOf('+') >= 0) { + const text1 = text.split('+'); + if (text1[0].toLowerCase() === 'ctrl') { + if (text1[1].length === 1) { + return String.fromCharCode(text1[1].toUpperCase().charCodeAt(0) - 64); + } } } - } - // handle enter - if (text.toLowerCase() === 'enter') { - return '\n'; - } + // handle enter + if (text.toLowerCase() === 'enter') { + return '\n'; + } - // Arrow keys - if (text.toLowerCase() === 'down') { - return String.fromCharCode(15); - } - if (text.toLowerCase() === 'up') { - return String.fromCharCode(16); - } - if (text.toLowerCase() === 'right') { - return String.fromCharCode(17); - } - if (text.toLowerCase() === 'left') { - return String.fromCharCode(18); - } + // Arrow keys + if (text.toLowerCase() === 'down') { + return String.fromCharCode(15); + } + if (text.toLowerCase() === 'up') { + return String.fromCharCode(16); + } + if (text.toLowerCase() === 'right') { + return String.fromCharCode(17); + } + if (text.toLowerCase() === 'left') { + return String.fromCharCode(18); + } - return text; + return text; + } } export class CreateNewTerminalAction extends Action { From 6c20496ced37ed551b4d673efdf3865540229b7b Mon Sep 17 00:00:00 2001 From: Nilesh Date: Tue, 4 Sep 2018 19:38:03 +0530 Subject: [PATCH 6/6] Limiting args.text to unicode chars --- .../electron-browser/terminalActions.ts | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index fd43100011ebe..8e1a6a12d7c2d 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -237,52 +237,7 @@ export class SendSequenceTerminalCommand extends Command { if (!terminalInstance) { return; } - const text = args.text.split(' '); - let terminalText; - for (let i = 0; i < text.length; i++) { - terminalText = ' ' + this.prepareTerminalText(text[i]); - terminalInstance.sendText(terminalText, false); - } - } - - private prepareTerminalText(text: string): string { - // Hexcodes and excape char - if (text.substring(0, 2).toLowerCase() === '\\x') { - // Valid hex with 2 digits - if (/^\\x[0-9a-f]{2}$/i.test(text)) { - return String.fromCharCode(parseInt(text.substring(2), 16)); - } - } - - // ctrl modifier with single char - if (text.indexOf('+') >= 0) { - const text1 = text.split('+'); - if (text1[0].toLowerCase() === 'ctrl') { - if (text1[1].length === 1) { - return String.fromCharCode(text1[1].toUpperCase().charCodeAt(0) - 64); - } - } - } - // handle enter - if (text.toLowerCase() === 'enter') { - return '\n'; - } - - // Arrow keys - if (text.toLowerCase() === 'down') { - return String.fromCharCode(15); - } - if (text.toLowerCase() === 'up') { - return String.fromCharCode(16); - } - if (text.toLowerCase() === 'right') { - return String.fromCharCode(17); - } - if (text.toLowerCase() === 'left') { - return String.fromCharCode(18); - } - - return text; + terminalInstance.sendText(args.text, false); } }