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 ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -56,67 +56,72 @@ msgstr ""
msgid "Failed to parse configuration file"
msgstr ""
#: src/log.c:150
#: src/log.c:145
msgid "y"
msgstr ""
#: src/log.c:150
#: src/log.c:145
msgid "Y"
msgstr ""
#: src/log.c:152
#: src/log.c:146
msgid "n"
msgstr ""
#: src/log.c:152
#: src/log.c:146
msgid "N"
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"
msgstr ""
#: src/main.c:74
#: src/main.c:72
#, c-format
msgid "Failed to access paths (%s)"
msgstr ""
#: src/main.c:82
#: src/main.c:80
msgid "Failed to lock, mc is already running"
msgstr ""
#: src/main.c:85
#: src/main.c:83
msgid "Failed to lock, did you mess up your directory permissions?"
msgstr ""
#: src/main.c:94
#: src/main.c:92
#, c-format
msgid "%s: command failed"
msgstr ""
#: src/main.c:98
#: src/main.c:96
#, c-format
msgid "%s: command successful"
msgstr ""
#: src/main.c:102
#: src/main.c:100
#, c-format
msgid "MatterLinux Configuration Manager (%s)"
msgstr ""
#: src/main.c:103
#: src/main.c:101
msgid "Different operations are done using different commands\n"
msgstr ""
#: src/main.c:106
#: src/main.c:104
msgid "pull down a configuration"
msgstr ""
#: src/main.c:109
#: src/main.c:107
msgid "build the configuration in the current directory"
msgstr ""
#: src/main.c:111
#: src/main.c:109
msgid ""
"Licensed under GPLv3, see <https://www.gnu.org/licenses/> for more "
"information"

View File

@ -44,8 +44,8 @@ bool config_is_valid(config_t *config) {
}
target_t *cur = config->t_first;
while(cur){
if(!target_is_valid(cur))
while (cur) {
if (!target_is_valid(cur))
return false;
cur = cur->next;
}
@ -92,12 +92,12 @@ int config_handler(void *data, const char *section, const char *key, const char
} else if (MATCH("details", "keywords")) {
clist_from_str(&config->keywords, (char *)value);
return 1;
}else if(eq((char*)section, "details")) {
} else if (eq((char *)section, "details")) {
goto UNKNOWN;
return 1;
}
if(NULL == config->t_last || (NULL != config->t_last->name && !eq(config->t_last->name, (char*)section))){
if (NULL == config->t_last || (NULL != config->t_last->name && !eq(config->t_last->name, (char *)section))) {
debug("adding new target => %s", section);
config_add_target(config, strdup(section));
}

View File

@ -95,7 +95,7 @@ void details(const char *msg, ...) {
va_list args;
va_start(args, msg);
printf(" "COLOR_RESET);
printf(" " COLOR_RESET);
vprintf(msg, args);
printf(COLOR_RESET "\n");
@ -139,18 +139,32 @@ void input(const char *msg, ...) {
}
bool yesno(const char *msg){
char question[strlen(msg)+12], inp[2] = {'n','\0'}, c;
sprintf(question, "%s [y/n]? ", msg);
if(env_mc_yes())
return true;
char *yes[] = {_("y"), _("Y")};
char *no[] = {_("n"), _("N")};
char question[strlen(msg)+12], c;
sprintf(question, _("%s [y/N] "), msg);
while(true){
input(question);
scanf("%c", &c);
inp[0] = c;
if(eq(inp, _("y")) || eq(inp, _("Y")))
return true;
else if(eq(inp, _("n")) || eq(inp, _("N")))
int c = getchar();
if(c == '\n')
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"));
}

View File

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

View File

@ -17,7 +17,7 @@
#define _(x) gettext(x)
int pull_progress(const git_indexer_progress *stats, void *data){
int pull_progress(const git_indexer_progress *stats, void *data) {
bar(stats->indexed_objects, stats->total_objects);
return 0;
}
@ -89,13 +89,13 @@ COPY:
printf("%s ", repo_cfg.keywords.c[i]);
printf("\n\n");
if(!yesno(_("Do you want to continue?")))
if (!yesno(_("Do you want to continue?")))
goto END;
info(_("Checking all the targets"));
target_t *cur = repo_cfg.t_first;
while(NULL != cur){
if(!exists(cur->src)){
while (NULL != cur) {
if (!exists(cur->src)) {
error(_("Failed to access the source for the target \"%s\""), cur->name);
goto END;
}
@ -105,7 +105,7 @@ COPY:
success(_("All the targets are OK"));
END:
if(repo_cfg.name != NULL)
if (repo_cfg.name != NULL)
config_free(&repo_cfg);
free(repo_url);
return ret;