Skip to content

Commit

Permalink
Allow explicitly unsetting ('u') a default prompt answer
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Dec 23, 2024
1 parent 8f46073 commit d404fea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions misc/clifmrc
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,14 @@
# 'D': All confirmation prompts (including the above ones, no matter their value)
#
# The right value holds the default answer for the corresponding prompt:
# 'y' or 'n'.
# 'y', 'n', or 'u' (unset - the value of 'd' is ignored for this prompt).
#
# If a value, left or right, is unset (or set to any other value), no default
# answer will be used ('y' or 'n' will be explicitly required, unless 'd' or 'D'
# are set to any valid value).
# are set to any valid value, in which case this value is used instead).
#
# For example, to set 'n' as the default answer for the 'r' command and
# 'y' for everything else: "r:n,d:y".
# For example, to set 'n' as the default answer for the 'r' command, unset for
# trash, and 'y' for everything else: "r:n,t:u,d:y".
;DefaultAnswer="o:n,r:n,t:y,R:n,d:y"

# How should the 'l' command create symbolic links. Possible values:
Expand Down
24 changes: 12 additions & 12 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3044,11 +3044,22 @@ set_term_cmd(char *cmd)
free(buf);
}

static void
set_default_answers_to_default(void)
{
conf.default_answer.remove = DEF_ANSWER_REMOVE;
conf.default_answer.trash = DEF_ANSWER_TRASH;
conf.default_answer.bulk_rename = DEF_ANSWER_BULK_RENAME;
conf.default_answer.overwrite = DEF_ANSWER_OVERWRITE;
conf.default_answer.default_ = DEF_ANSWER_DEFAULT;
conf.default_answer.default_all = DEF_ANSWER_DEFAULT_ALL;
}

static void
set_default_answer(const char *str)
{
if (!str || !*str || str[1] != ':'
|| (str[2] != 'y' && str[2] != 'n'))
|| (str[2] != 'y' && str[2] != 'n' && str[2] != 'u'))
return;

switch (*str) {
Expand Down Expand Up @@ -3092,17 +3103,6 @@ set_rl_edit_mode(const char *val)
rl_emacs_editing_mode(1, 0);
}

static void
set_default_answers_to_default(void)
{
conf.default_answer.remove = DEF_ANSWER_REMOVE;
conf.default_answer.trash = DEF_ANSWER_TRASH;
conf.default_answer.bulk_rename = DEF_ANSWER_BULK_RENAME;
conf.default_answer.overwrite = DEF_ANSWER_OVERWRITE;
conf.default_answer.default_ = DEF_ANSWER_DEFAULT;
conf.default_answer.default_all = DEF_ANSWER_DEFAULT_ALL;
}

/* Read the main configuration file and set options accordingly */
static void
read_config(void)
Expand Down
2 changes: 1 addition & 1 deletion src/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ static const char *
gen_y_n_str(const char def_answer)
{
switch (def_answer) {
case '0': return "[y/n]";
case 'y': return "[Y/n]";
case 'n': return "[y/N]";
case 'u': /* fallthrough */
default: return "[y/n]";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ ws2=31:ws3=38;5;228:ws4=32:ws5=36:ws6=38;5;214:ws7=35:ws8=2;37:xf=1;31:xs=32:"
#define MNT_UDISKS2 1

/* Default options */
/* Default answers for confirmation prompts: 0 (none), 'y', or 'n' */
/* Default answers for confirmation prompts: 0 or 'u' (unset), 'y', or 'n' */
#define DEF_ANSWER_BULK_RENAME 'n' /* 'br' command */
#define DEF_ANSWER_OVERWRITE 'n' /* 'c' and 'm' commands mostly */
#define DEF_ANSWER_REMOVE 'n' /* 'r' command */
Expand Down

0 comments on commit d404fea

Please sign in to comment.