mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 09:35:41 -05:00
Merge VS Code 1.31.1 (#4283)
This commit is contained in:
@@ -10,13 +10,13 @@ import { Event } from 'vs/base/common/event';
|
||||
|
||||
export class DialogChannel implements IServerChannel {
|
||||
|
||||
constructor(@IDialogService private dialogService: IDialogService) { }
|
||||
constructor(@IDialogService private readonly dialogService: IDialogService) { }
|
||||
|
||||
listen<T>(_, event: string): Event<T> {
|
||||
throw new Error(`Event not found: ${event}`);
|
||||
}
|
||||
|
||||
call(_, command: string, args?: any[]): Thenable<any> {
|
||||
call(_, command: string, args?: any[]): Promise<any> {
|
||||
switch (command) {
|
||||
case 'show': return this.dialogService.show(args![0], args![1], args![2]);
|
||||
case 'confirm': return this.dialogService.confirm(args![0]);
|
||||
@@ -31,11 +31,11 @@ export class DialogChannelClient implements IDialogService {
|
||||
|
||||
constructor(private channel: IChannel) { }
|
||||
|
||||
show(severity: Severity, message: string, options: string[]): Thenable<number> {
|
||||
show(severity: Severity, message: string, options: string[]): Promise<number> {
|
||||
return this.channel.call('show', [severity, message, options]);
|
||||
}
|
||||
|
||||
confirm(confirmation: IConfirmation): Thenable<IConfirmationResult> {
|
||||
confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
|
||||
return this.channel.call('confirm', [confirmation]);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user