update: better way to handle yes no prompt

This commit is contained in:
ngn 2024-05-02 00:50:53 +03:00
parent 013ecfb3e7
commit 0d00678c30
6 changed files with 63 additions and 46 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-01 23:04+0300\n" "POT-Creation-Date: 2024-05-02 00:49+0300\n"
"PO-Revision-Date: 2024-05-01 13:34+0300\n" "PO-Revision-Date: 2024-05-01 13:34+0300\n"
"Last-Translator: <ngn@ngn.tf>\n" "Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n" "Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -56,67 +56,72 @@ msgstr ""
msgid "Failed to parse configuration file" msgid "Failed to parse configuration file"
msgstr "" msgstr ""
#: src/log.c:150 #: src/log.c:145
msgid "y" msgid "y"
msgstr "" msgstr ""
#: src/log.c:150 #: src/log.c:145
msgid "Y" msgid "Y"
msgstr "" msgstr ""
#: src/log.c:152 #: src/log.c:146
msgid "n" msgid "n"
msgstr "" msgstr ""
#: src/log.c:152 #: src/log.c:146
msgid "N" msgid "N"
msgstr "" msgstr ""
#: src/log.c:155 #: src/log.c:149
#, c-format
msgid "%s [y/N] "
msgstr ""
#: src/log.c:169
msgid "Please answer with y/n" msgid "Please answer with y/n"
msgstr "" msgstr ""
#: src/main.c:74 #: src/main.c:72
#, c-format #, c-format
msgid "Failed to access paths (%s)" msgid "Failed to access paths (%s)"
msgstr "" msgstr ""
#: src/main.c:82 #: src/main.c:80
msgid "Failed to lock, mc is already running" msgid "Failed to lock, mc is already running"
msgstr "" msgstr ""
#: src/main.c:85 #: src/main.c:83
msgid "Failed to lock, did you mess up your directory permissions?" msgid "Failed to lock, did you mess up your directory permissions?"
msgstr "" msgstr ""
#: src/main.c:94 #: src/main.c:92
#, c-format #, c-format
msgid "%s: command failed" msgid "%s: command failed"
msgstr "" msgstr ""
#: src/main.c:98 #: src/main.c:96
#, c-format #, c-format
msgid "%s: command successful" msgid "%s: command successful"
msgstr "" msgstr ""
#: src/main.c:102 #: src/main.c:100
#, c-format #, c-format
msgid "MatterLinux Configuration Manager (%s)" msgid "MatterLinux Configuration Manager (%s)"
msgstr "" msgstr ""
#: src/main.c:103 #: src/main.c:101
msgid "Different operations are done using different commands\n" msgid "Different operations are done using different commands\n"
msgstr "" msgstr ""
#: src/main.c:106 #: src/main.c:104
msgid "pull down a configuration" msgid "pull down a configuration"
msgstr "" msgstr ""
#: src/main.c:109 #: src/main.c:107
msgid "build the configuration in the current directory" msgid "build the configuration in the current directory"
msgstr "" msgstr ""
#: src/main.c:111 #: src/main.c:109
msgid "" msgid ""
"Licensed under GPLv3, see <https://www.gnu.org/licenses/> for more " "Licensed under GPLv3, see <https://www.gnu.org/licenses/> for more "
"information" "information"

View File

@ -139,18 +139,32 @@ void input(const char *msg, ...) {
} }
bool yesno(const char *msg){ bool yesno(const char *msg){
char question[strlen(msg)+12], inp[2] = {'n','\0'}, c; if(env_mc_yes())
sprintf(question, "%s [y/n]? ", msg); return true;
char *yes[] = {_("y"), _("Y")};
char *no[] = {_("n"), _("N")};
char question[strlen(msg)+12], c;
sprintf(question, _("%s [y/N] "), msg);
while(true){ while(true){
input(question); input(question);
scanf("%c", &c);
inp[0] = c;
if(eq(inp, _("y")) || eq(inp, _("Y"))) int c = getchar();
return true; if(c == '\n')
else if(eq(inp, _("n")) || eq(inp, _("N")))
return false; return false;
getchar();
for(int i = 0; i < sizeof(yes)/sizeof(char*); i++){
if(yes[i][0] == c)
return true;
}
for(int i = 0; i < sizeof(no)/sizeof(char*); i++){
if(no[i][0] == c)
return false;
}
error(_("Please answer with y/n")); error(_("Please answer with y/n"));
} }

View File

@ -22,7 +22,6 @@
// clang-format on // clang-format on
#include <libintl.h>
#include <locale.h> #include <locale.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
@ -32,14 +31,13 @@
#include "args.h" #include "args.h"
#include "gen.h" #include "gen.h"
#include "intl.h"
#include "lock.h" #include "lock.h"
#include "log.h" #include "log.h"
#include "paths.h" #include "paths.h"
#include "pull.h" #include "pull.h"
#include "util.h" #include "util.h"
#define _(x) gettext(x)
typedef bool (*cmd)(); typedef bool (*cmd)();
struct CmdMap { struct CmdMap {
char *name; char *name;