1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Fixed prompt

This commit is contained in:
Laurent Cozic 2017-10-28 18:55:45 +01:00
parent add1cb33bf
commit 9dd8268d44
6 changed files with 47 additions and 47 deletions

View File

@ -257,6 +257,7 @@ class AppGui {
}
addCommandToConsole(cmd) {
if (!cmd) return;
this.stdout(chalk.cyan.bold('> ' + cmd));
}

View File

@ -301,19 +301,22 @@ class Application {
});
cmd.setPrompt(async (message, options) => {
if (!options) options = {};
if (!options.type) options.type = 'boolean';
if (!options.booleanAnswerDefault) options.booleanAnswerDefault = 'y';
if (!options.answers) options.answers = options.booleanAnswerDefault === 'y' ? [_('Y'), _('n')] : [_('N'), _('y')];
if (options.type == 'boolean') {
message += ' (' + options.answers.join('/') + ')';
}
const answer = await this.gui().prompt('', message + ' ');
let answer = await this.gui().prompt('', message + ' ');
if (options.type === 'boolean') {
if (answer === null) return false;
let output = false;
if (answer === '' || answer.toLowerCase() == options.answers[0].toLowerCase()) {
output = true;
}
return options.booleanAnswerDefault === 'y' ? output : !output;
if (answer === null) return false; // Pressed ESCAPE
if (!answer) answer = options.answers[0];
let positiveIndex = options.booleanAnswerDefault == 'y' ? 0 : 1;
return answer.toLowerCase() === options.answers[positiveIndex].toLowerCase();
}
});

View File

@ -78,10 +78,6 @@ class BaseCommand {
async prompt(message, options = null) {
if (!this.prompt_) throw new Error('Prompt is undefined');
if (!options) options = {};
if (!options.type) options.type = 'boolean';
if (!options.booleanAnswerDefault) options.booleanAnswerDefault = 'y';
if (!options.answers) options.answers = options.booleanAnswerDefault === 'y' ? [_('Y'), _('n')] : [_('N'), _('y')];
return await this.prompt_(message, options);
}

View File

@ -99,6 +99,18 @@ msgstr ""
msgid "Exits the application."
msgstr ""
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
msgid "Cancelling background synchronisation... Please wait."
msgstr ""
@ -143,18 +155,6 @@ msgid ""
"source '%s'"
msgstr ""
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
#, javascript-format
msgid "Missing required argument: %s"
msgstr ""

View File

@ -110,6 +110,18 @@ msgstr "Affiche l'aide pour la commande donnée."
msgid "Exits the application."
msgstr "Quitter le logiciel."
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
#, fuzzy
msgid "Cancelling background synchronisation... Please wait."
msgstr "Annulation..."
@ -155,18 +167,6 @@ msgid ""
"source '%s'"
msgstr ""
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
#, javascript-format
msgid "Missing required argument: %s"
msgstr ""

View File

@ -99,6 +99,18 @@ msgstr ""
msgid "Exits the application."
msgstr ""
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
msgid "Cancelling background synchronisation... Please wait."
msgstr ""
@ -143,18 +155,6 @@ msgid ""
"source '%s'"
msgstr ""
msgid "Y"
msgstr ""
msgid "n"
msgstr ""
msgid "N"
msgstr ""
msgid "y"
msgstr ""
#, javascript-format
msgid "Missing required argument: %s"
msgstr ""