提交 862e7920 编写于 作者: S Sandeep Somavarapu

fix #13299

上级 c038219f
......@@ -31,6 +31,8 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
import { mkdirp } from 'vs/base/node/pfs';
import { IChoiceService } from 'vs/platform/message/common/message';
import { ChoiceCliService } from 'vs/platform/message/common/messageCli';
const notFound = id => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = id => localize('notInstalled', "Extension '{0}' is not installed.", id);
......@@ -167,6 +169,7 @@ export function main(argv: ParsedArgs): TPromise<void> {
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
services.set(IChoiceService, new SyncDescriptor(ChoiceCliService));
if (isBuilt && !extensionDevelopmentPath && product.enableTelemetry) {
const appenders: AppInsightsAppender[] = [];
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as readline from 'readline';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
export class ChoiceCliService implements IChoiceService {
_serviceBrand: any;
choose(severity: Severity, message: string, options: string[]): TPromise<number> {
const promise = new TPromise((c, e) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});
rl.prompt();
rl.write(this.toQuestion(message, options));
rl.prompt();
rl.once('line', (answer) => {
rl.close();
c(this.toOption(answer, options));
});
rl.once('SIGINT', () => {
rl.close();
promise.cancel();
});
});
return promise;
}
private toQuestion(message: string, options: string[]): string {
return options.reduce((previousValue: string, currentValue: string, currentIndex: number) => {
return previousValue + currentValue + '(' + currentIndex + ')' + (currentIndex < options.length - 1 ? ' | ' : '\n');
}, message + ' ');
}
private toOption(answer: string, options: string[]): number {
const value = parseInt(answer);
if (!isNaN(value)) {
return value;
}
answer = answer.toLocaleLowerCase();
for (let i = 0; i < options.length; i++) {
if (options[i].toLocaleLowerCase() === answer) {
return i;
}
}
return -1;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册