Skip to content

Commit

Permalink
Merge pull request #161779 from microsoft/tyriar/161758
Browse files Browse the repository at this point in the history
Enforce all properties on output matchers
  • Loading branch information
Tyriar committed Sep 26, 2022
2 parents 3d17ff3 + 38939c5 commit e7cfaa6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,27 @@ export interface ICommandAction extends IAction {
addNewLine?: boolean;
}

/**
* A matcher that runs on a sub-section of a terminal command's output
*/
export interface ITerminalOutputMatcher {
/**
* A string or regex to match against the unwrapped line.
*/
lineMatcher: string | RegExp;
anchor?: 'top' | 'bottom';
offset?: number;
length?: number;
/**
* Which side of the output to anchor the {@link offset} and {@link length} against.
*/
anchor: 'top' | 'bottom';
/**
* How far from either the top or the bottom of the butter to start matching against.
*/
offset: number;
/**
* The number of rows to match against, this should be as small as possible for performance
* reasons.
*/
length: number;
}

export interface IXtermTerminal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const GitCreatePrOutputRegex = /Create a pull request for \'([^\s]+)\' on
export function gitSimilarCommand(): ITerminalContextualActionOptions {
return {
commandLineMatcher: GitCommandLineRegex,
outputMatcher: { lineMatcher: GitSimilarOutputRegex, anchor: 'bottom' },
outputMatcher: {
lineMatcher: GitSimilarOutputRegex,
anchor: 'bottom',
offset: 0,
length: 3
},
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Run git ${matchResult.outputMatch[1]}` : ``,
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
Expand All @@ -45,7 +50,14 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: AnyCommandLineRegex,
outputMatcher: !isWindows ? { lineMatcher: FreePortOutputRegex, anchor: 'bottom' } : undefined,
// TODO: Support free port on Windows https://github.com/microsoft/vscode/issues/161775
outputMatcher: isWindows ? undefined : {
lineMatcher: FreePortOutputRegex,
anchor: 'bottom',
offset: 0,
length: 20
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
const port = matchResult?.outputMatch?.[1];
if (!port) {
Expand All @@ -69,7 +81,12 @@ export function gitPushSetUpstream(): ITerminalContextualActionOptions {
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Git push ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: { lineMatcher: GitPushOutputRegex, anchor: 'bottom' },
outputMatcher: {
lineMatcher: GitPushOutputRegex,
anchor: 'bottom',
offset: 0,
length: 5
},
exitStatus: false,
getActions: (matchResult: ContextualMatchResult, command: ITerminalCommand) => {
const branch = matchResult?.outputMatch?.[1];
Expand All @@ -94,7 +111,12 @@ export function gitCreatePr(openerService: IOpenerService): ITerminalContextualA
return {
actionName: (matchResult: ContextualMatchResult) => matchResult.outputMatch ? `Create PR for ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: GitPushCommandLineRegex,
outputMatcher: { lineMatcher: GitCreatePrOutputRegex, anchor: 'bottom' },
outputMatcher: {
lineMatcher: GitCreatePrOutputRegex,
anchor: 'bottom',
offset: 0,
length: 5
},
exitStatus: true,
getActions: (matchResult: ContextualMatchResult, command?: ITerminalCommand) => {
if (!command) {
Expand Down

0 comments on commit e7cfaa6

Please sign in to comment.