From 9dd8268d44d7c6041bb04c8e36ef6202afcd20ca Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 28 Oct 2017 18:55:45 +0100 Subject: [PATCH] Fixed prompt --- CliClient/app/app-gui.js | 1 + CliClient/app/app.js | 17 ++++++++++------- CliClient/app/base-command.js | 4 ---- CliClient/locales/en_GB.po | 24 ++++++++++++------------ CliClient/locales/fr_FR.po | 24 ++++++++++++------------ CliClient/locales/joplin.pot | 24 ++++++++++++------------ 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/CliClient/app/app-gui.js b/CliClient/app/app-gui.js index ebfddc578e..76371f7c4c 100644 --- a/CliClient/app/app-gui.js +++ b/CliClient/app/app-gui.js @@ -257,6 +257,7 @@ class AppGui { } addCommandToConsole(cmd) { + if (!cmd) return; this.stdout(chalk.cyan.bold('> ' + cmd)); } diff --git a/CliClient/app/app.js b/CliClient/app/app.js index 07c11a81f0..6e6ecc3362 100644 --- a/CliClient/app/app.js +++ b/CliClient/app/app.js @@ -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(); } }); diff --git a/CliClient/app/base-command.js b/CliClient/app/base-command.js index 3639f9c47c..c40c366dc6 100644 --- a/CliClient/app/base-command.js +++ b/CliClient/app/base-command.js @@ -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); } diff --git a/CliClient/locales/en_GB.po b/CliClient/locales/en_GB.po index a736fcce82..ce729b2a14 100644 --- a/CliClient/locales/en_GB.po +++ b/CliClient/locales/en_GB.po @@ -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 "" diff --git a/CliClient/locales/fr_FR.po b/CliClient/locales/fr_FR.po index e104a510b0..fdf7740552 100644 --- a/CliClient/locales/fr_FR.po +++ b/CliClient/locales/fr_FR.po @@ -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 "" diff --git a/CliClient/locales/joplin.pot b/CliClient/locales/joplin.pot index a736fcce82..ce729b2a14 100644 --- a/CliClient/locales/joplin.pot +++ b/CliClient/locales/joplin.pot @@ -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 ""