提交 41a34975 编写于 作者: A Alex Dima

Revert "debt - remove unused node dialog service"

This reverts commit c9efee46.
上级 6b8c9461
......@@ -400,6 +400,7 @@
"./vs/platform/diagnostics/electron-main/diagnosticsService.ts",
"./vs/platform/dialogs/common/dialogs.ts",
"./vs/platform/dialogs/node/dialogIpc.ts",
"./vs/platform/dialogs/node/dialogService.ts",
"./vs/platform/download/common/download.ts",
"./vs/platform/download/node/downloadIpc.ts",
"./vs/platform/download/node/downloadService.ts",
......
......@@ -36,6 +36,8 @@ import { IDiagnosticsService, DiagnosticsService } from 'vs/platform/diagnostics
import { BufferLogService } from 'vs/platform/log/common/bufferLog';
import { uploadLogs } from 'vs/code/electron-main/logUploader';
import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { CommandLineDialogService } from 'vs/platform/dialogs/node/dialogService';
import { createWaitMarkerFile } from 'vs/code/node/wait';
class ExpectedError extends Error {
......@@ -308,6 +310,7 @@ function createServices(args: ParsedArgs, bufferLogService: BufferLogService): I
services.set(IStateService, new SyncDescriptor(StateService));
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService));
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IDialogService, new SyncDescriptor(CommandLineDialogService));
services.set(IDiagnosticsService, new SyncDescriptor(DiagnosticsService));
return new InstantiationService(services, true);
......
/*---------------------------------------------------------------------------------------------
* 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 { IDialogService, IConfirmation, IConfirmationResult } from 'vs/platform/dialogs/common/dialogs';
import Severity from 'vs/base/common/severity';
import { localize } from 'vs/nls';
import { canceled } from 'vs/base/common/errors';
export class CommandLineDialogService implements IDialogService {
_serviceBrand: any;
show(severity: Severity, message: string, options: string[]): Promise<number> {
const promise = new Promise<number>((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();
e(canceled());
});
});
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;
}
confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
return this.show(Severity.Info, confirmation.message, [confirmation.primaryButton || localize('ok', "Ok"), confirmation.secondaryButton || localize('cancel', "Cancel")]).then(index => {
return {
confirmed: index === 0
} as IConfirmationResult;
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册