diff --git a/src/helpers.h b/src/helpers.h index 97c9ffef..8765c110 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -884,6 +884,10 @@ extern time_t curdir_mtime; #define FILE_SIZE(s) (conf.apparent_size == 1 ? (s).st_size \ : (s).st_blocks * S_BLKSIZE) +/* Do we have the sort method S in light mode? */ +#define ST_IN_LIGHT_MODE(s) ((s) == SNAME || (s) == SVER || (s) == SINO \ + || (s) == SEXT || (s) == SNONE) + #define UNUSED(x) (void)(x) /* Just silence the compiler's warning */ #define TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? ((c) - 'a' + 'A') : (c)) #define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c)) diff --git a/src/keybinds.c b/src/keybinds.c index 96153ac3..8b6928e7 100644 --- a/src/keybinds.c +++ b/src/keybinds.c @@ -1191,6 +1191,10 @@ rl_sort_next(int count, int key) conf.sort++; #endif /* !ST_BTIME */ + if (conf.light_mode == 1) + while (!ST_IN_LIGHT_MODE(conf.sort + 1) && conf.sort + 1 <= SORT_TYPES) + conf.sort++; + conf.sort++; if (conf.sort > SORT_TYPES) conf.sort = 0; @@ -1224,9 +1228,13 @@ rl_sort_previous(int count, int key) conf.sort--; #endif /* !ST_BTIME */ + if (conf.light_mode == 1) + while (!ST_IN_LIGHT_MODE(conf.sort - 1) && conf.sort - 1 >= 0) + conf.sort--; + conf.sort--; if (conf.sort < 0) - conf.sort = SORT_TYPES; + conf.sort = conf.light_mode == 1 ? SINO : SORT_TYPES; if (conf.autols == 1) { sort_switch = 1; diff --git a/src/readline.c b/src/readline.c index 951c3b8b..bd9208d6 100644 --- a/src/readline.c +++ b/src/readline.c @@ -2061,7 +2061,8 @@ sort_num_generator(const char *text, int state) i = 0; int num_text = atoi(text); - if (num_text == INT_MIN) + if (num_text == INT_MIN + || (conf.light_mode == 1 && !ST_IN_LIGHT_MODE(num_text))) return (char *)NULL; static char *const sorts[] = { @@ -2172,6 +2173,9 @@ sort_name_generator(const char *text, int state) } while ((name = sort_methods[i++].name) != NULL) { + if (conf.light_mode == 1 && i > 0 + && !ST_IN_LIGHT_MODE(sort_methods[i - 1].num)) + continue; if (strncmp(name, text, len) == 0) return strdup(name); } @@ -4269,8 +4273,10 @@ my_rl_completion(const char *text, const int start, const int end) /* Sort number */ if (*lb == 's' && (strncmp(lb, "st ", 3) == 0 || strncmp(lb, "sort ", 5) == 0) - && is_number(text) && n >= 0 && n <= SORT_TYPES) + && is_number(text) && n >= 0 && n <= SORT_TYPES) { + rl_attempted_completion_over = 1; return complete_sort_num(text, words_n); + } } /* ### DESELECT COMPLETION ### */ diff --git a/src/sort.c b/src/sort.c index b6388801..1b8c7ac0 100644 --- a/src/sort.c +++ b/src/sort.c @@ -34,10 +34,6 @@ #include "listing.h" #include "messages.h" /* SORT_USAGE */ -/* Do we have the sort method S in light mode? */ -#define ST_IN_LIGHT_MODE(s) ((s) == SNAME || (s) == SVER || (s) == SINO \ - || (s) == SEXT || (s) == SNONE) - int skip_nonexec(const struct dirent *ent) { @@ -355,26 +351,30 @@ alphasort_insensitive(const struct dirent **a, const struct dirent **b) // return (ret - (ret * 2)); } +static char * +num_to_sort_name(const int n) +{ + switch (n) { + case SNONE: return "none"; + case SNAME: return "name"; + case STSIZE: return "size"; + case SATIME: return "atime"; + case SBTIME: return "btime"; + case SCTIME: return "ctime"; + case SMTIME: return "mtime"; + case SVER: return "version"; + case SEXT: return "extension"; + case SINO: return "inode"; + case SOWN: return "owner"; + case SGRP: return "group"; + default: return "unknown"; + } +} + void print_sort_method(void) { - char *name = (char *)NULL; - - switch (conf.sort) { - case SNONE: name = "none"; break; - case SNAME: name = "name"; break; - case STSIZE: name = "size"; break; - case SATIME: name = "atime"; break; - case SBTIME: name = "btime"; break; - case SCTIME: name = "ctime"; break; - case SMTIME: name = "mtime"; break; - case SVER: name = "version"; break; - case SEXT: name = "extension"; break; - case SINO: name = "inode"; break; - case SOWN: name = "owner"; break; - case SGRP: name = "group"; break; - default: name = "unknown"; break; - } + char *name = num_to_sort_name(conf.sort); printf("%s%s%s%s", BOLD, name, NC, (conf.sort_reverse == 1) ? " [rev]" : ""); @@ -420,6 +420,13 @@ set_sort_by_name(char **arg) for (i = 0; i <= SORT_TYPES; i++) { if (*(*arg) == *sort_methods[i].name && strcmp(*arg, sort_methods[i].name) == 0) { + if (conf.light_mode == 1 + && !ST_IN_LIGHT_MODE(sort_methods[i].num)) { + fprintf(stderr, _("st: '%s': Not available in light mode\n"), + sort_methods[i].name); + return FUNC_FAILURE; + } + *arg = xnrealloc(*arg, 32, sizeof(char)); snprintf(*arg, 32, "%d", sort_methods[i].num); return FUNC_SUCCESS; @@ -454,9 +461,15 @@ sort_function(char **arg) /* Argument is a number */ const int n = atoi(arg[1]); + if (conf.light_mode == 1 && !ST_IN_LIGHT_MODE(n)) { + fprintf(stderr, _("st: %d (%s): Not available in light mode\n"), + n, num_to_sort_name(n)); + return FUNC_FAILURE; + } + #ifndef ST_BTIME if (n == SBTIME) { - puts(_("st: Birth time is not available on this platform")); + fputs(_("st: Birth time is not available on this platform"), stderr); return FUNC_FAILURE; } #endif /* !ST_BTIME */ diff --git a/src/suggestions.c b/src/suggestions.c index 0e7fe905..a4cc77a2 100644 --- a/src/suggestions.c +++ b/src/suggestions.c @@ -1635,7 +1635,8 @@ check_sort_methods(const char *str, const size_t len) } int a = atoi(str); - if (a < 0 || a > SORT_TYPES) { + if (a < 0 || a > SORT_TYPES + || (conf.light_mode == 1 && !ST_IN_LIGHT_MODE(a))) { if (suggestion.printed) clear_suggestion(CS_FREEBUF); return NO_MATCH;