mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
'C' sorts by items
This commit is contained in:
parent
cfcac262d1
commit
fdd86924e5
4 changed files with 22 additions and 7 deletions
|
|
@ -341,6 +341,10 @@ int browse_key(int ch) {
|
||||||
dirlist_set_sort(i, dirlist_sort_col == i ? !dirlist_sort_desc : 1, DL_NOCHANGE);
|
dirlist_set_sort(i, dirlist_sort_col == i ? !dirlist_sort_desc : 1, DL_NOCHANGE);
|
||||||
info_show = 0;
|
info_show = 0;
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
dirlist_set_sort(DL_COL_ITEMS, dirlist_sort_col == DL_COL_ITEMS ? !dirlist_sort_desc : 1, DL_NOCHANGE);
|
||||||
|
info_show = 0;
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
dirlist_set_hidden(!dirlist_hidden);
|
dirlist_set_hidden(!dirlist_hidden);
|
||||||
info_show = 0;
|
info_show = 0;
|
||||||
|
|
|
||||||
|
|
@ -62,25 +62,34 @@ static int dirlist_cmp(struct dir *x, struct dir *y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sort columns:
|
/* sort columns:
|
||||||
* 1 -> 2 -> 3
|
* 1 -> 2 -> 3 -> 4
|
||||||
* NAME: name -> size -> asize
|
* NAME: name -> size -> asize -> items
|
||||||
* SIZE: size -> asize -> name
|
* SIZE: size -> asize -> name -> items
|
||||||
* ASIZE: asize -> size -> name
|
* ASIZE: asize -> size -> name -> items
|
||||||
|
* ITEMS: items -> size -> asize -> name
|
||||||
*
|
*
|
||||||
* Note that the method used below is supposed to be fast, not readable :-)
|
* Note that the method used below is supposed to be fast, not readable :-)
|
||||||
*/
|
*/
|
||||||
#define CMP_NAME strcmp(x->name, y->name)
|
#define CMP_NAME strcmp(x->name, y->name)
|
||||||
#define CMP_SIZE (x->size > y->size ? 1 : (x->size == y->size ? 0 : -1))
|
#define CMP_SIZE (x->size > y->size ? 1 : (x->size == y->size ? 0 : -1))
|
||||||
#define CMP_ASIZE (x->asize > y->asize ? 1 : (x->asize == y->asize ? 0 : -1))
|
#define CMP_ASIZE (x->asize > y->asize ? 1 : (x->asize == y->asize ? 0 : -1))
|
||||||
|
#define CMP_ITEMS (x->items > y->items ? 1 : (x->items == y->items ? 0 : -1))
|
||||||
|
|
||||||
/* try 1 */
|
/* try 1 */
|
||||||
r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME : dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE : CMP_ASIZE;
|
r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME :
|
||||||
|
dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE :
|
||||||
|
dirlist_sort_col == DL_COL_ASIZE ? CMP_ASIZE :
|
||||||
|
CMP_ITEMS;
|
||||||
/* try 2 */
|
/* try 2 */
|
||||||
if(!r)
|
if(!r)
|
||||||
r = dirlist_sort_col == DL_COL_SIZE ? CMP_ASIZE : CMP_SIZE;
|
r = dirlist_sort_col == DL_COL_SIZE ? CMP_ASIZE : CMP_SIZE;
|
||||||
/* try 3 */
|
/* try 3 */
|
||||||
if(!r)
|
if(!r)
|
||||||
r = dirlist_sort_col == DL_COL_NAME ? CMP_ASIZE : CMP_NAME;
|
r = (dirlist_sort_col == DL_COL_NAME || dirlist_sort_col == DL_COL_ITEMS) ?
|
||||||
|
CMP_ASIZE : CMP_NAME;
|
||||||
|
/* try 4 */
|
||||||
|
if(!r)
|
||||||
|
r = dirlist_sort_col == DL_COL_ITEMS ? CMP_NAME : CMP_ITEMS;
|
||||||
|
|
||||||
/* reverse when sorting in descending order */
|
/* reverse when sorting in descending order */
|
||||||
if(dirlist_sort_desc && r != 0)
|
if(dirlist_sort_desc && r != 0)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
#define DL_COL_NAME 0
|
#define DL_COL_NAME 0
|
||||||
#define DL_COL_SIZE 1
|
#define DL_COL_SIZE 1
|
||||||
#define DL_COL_ASIZE 2
|
#define DL_COL_ASIZE 2
|
||||||
|
#define DL_COL_ITEMS 3
|
||||||
|
|
||||||
|
|
||||||
void dirlist_open(struct dir *);
|
void dirlist_open(struct dir *);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
int page, start;
|
int page, start;
|
||||||
|
|
||||||
|
|
||||||
#define KEYS 15
|
#define KEYS 16
|
||||||
char *keys[KEYS*2] = {
|
char *keys[KEYS*2] = {
|
||||||
/*|----key----| |----------------description----------------|*/
|
/*|----key----| |----------------description----------------|*/
|
||||||
"up, k", "Move cursor up",
|
"up, k", "Move cursor up",
|
||||||
|
|
@ -41,6 +41,7 @@ char *keys[KEYS*2] = {
|
||||||
"left, <, h", "Open parent directory",
|
"left, <, h", "Open parent directory",
|
||||||
"n", "Sort by name (ascending/descending)",
|
"n", "Sort by name (ascending/descending)",
|
||||||
"s", "Sort by size (ascending/descending)",
|
"s", "Sort by size (ascending/descending)",
|
||||||
|
"C", "Sort by items (ascending/descending)",
|
||||||
"d", "Delete selected file or directory",
|
"d", "Delete selected file or directory",
|
||||||
"t", "Toggle dirs before files when sorting",
|
"t", "Toggle dirs before files when sorting",
|
||||||
"g", "Show percentage and/or graph",
|
"g", "Show percentage and/or graph",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue