2007-07-20 15:15:46 +04:00
|
|
|
/* ncdu - NCurses Disk Usage
|
|
|
|
|
2008-08-02 17:59:58 +04:00
|
|
|
Copyright (c) 2007-2008 Yoran Heling
|
2007-07-20 15:15:46 +04:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ncdu.h"
|
|
|
|
|
|
|
|
struct dir *bcur;
|
|
|
|
|
|
|
|
|
2007-08-01 19:01:42 +04:00
|
|
|
void drawInfo(struct dir *dr) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
nccreate(11, 60, "Item info");
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
attron(A_BOLD);
|
|
|
|
ncaddstr(2, 3, "Name:");
|
|
|
|
ncaddstr(3, 3, "Path:");
|
|
|
|
ncaddstr(4, 3, "Type:");
|
|
|
|
ncaddstr(6, 3, " Disk usage:");
|
|
|
|
ncaddstr(7, 3, "Apparent size:");
|
|
|
|
attroff(A_BOLD);
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2007-08-16 12:36:58 +04:00
|
|
|
ncaddstr(2, 9, cropdir(dr->name, 49));
|
|
|
|
ncaddstr(3, 9, cropdir(getpath(dr, path), 49));
|
|
|
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory"
|
2007-08-01 19:01:42 +04:00
|
|
|
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
|
2007-08-16 12:36:58 +04:00
|
|
|
ncprint(6, 18, "%s (%s B)", cropsize(dr->size), fullsize(dr->size));
|
|
|
|
ncprint(7, 18, "%s (%s B)", cropsize(dr->asize), fullsize(dr->asize));
|
2007-08-01 19:01:42 +04:00
|
|
|
|
2008-09-20 13:35:21 +04:00
|
|
|
ncaddstr(9, 32, "Press i to hide this window");
|
2007-08-01 19:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
int cmp(struct dir *x, struct dir *y) {
|
|
|
|
struct dir *a, *b;
|
|
|
|
int r = 0;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
if(bflags & BF_DESC) {
|
|
|
|
a = y; b = x;
|
|
|
|
} else {
|
|
|
|
b = y; a = x;
|
|
|
|
}
|
|
|
|
if(!(bflags & BF_NDIRF) && y->flags & FF_DIR && !(x->flags & FF_DIR))
|
2007-07-24 12:53:55 +04:00
|
|
|
return(1);
|
|
|
|
if(!(bflags & BF_NDIRF) && !(y->flags & FF_DIR) && x->flags & FF_DIR)
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
if(bflags & BF_NAME)
|
2007-07-20 15:15:46 +04:00
|
|
|
r = strcmp(a->name, b->name);
|
|
|
|
if(r == 0)
|
|
|
|
r = a->size > b->size ? 1 : (a->size == b->size ? 0 : -1);
|
2007-08-01 19:01:42 +04:00
|
|
|
if(r == 0)
|
|
|
|
r = a->asize > b->asize ? 1 : (a->asize == b->asize ? 0 : -1);
|
2007-07-24 12:53:55 +04:00
|
|
|
if(r == 0)
|
2007-07-26 20:37:33 +04:00
|
|
|
r = strcmp(x->name, y->name);
|
2007-07-20 15:15:46 +04:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mergesort algorithm, many thanks to
|
|
|
|
http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
|
|
|
*/
|
|
|
|
struct dir *sortFiles(struct dir *list) {
|
|
|
|
struct dir *p, *q, *e, *tail;
|
|
|
|
int insize, nmerges, psize, qsize, i;
|
|
|
|
|
|
|
|
insize = 1;
|
|
|
|
while(1) {
|
|
|
|
p = list;
|
|
|
|
list = NULL;
|
|
|
|
tail = NULL;
|
|
|
|
nmerges = 0;
|
|
|
|
while(p) {
|
|
|
|
nmerges++;
|
|
|
|
q = p;
|
|
|
|
psize = 0;
|
|
|
|
for(i=0; i<insize; i++) {
|
|
|
|
psize++;
|
|
|
|
q = q->next;
|
|
|
|
if(!q) break;
|
|
|
|
}
|
|
|
|
qsize = insize;
|
|
|
|
while(psize > 0 || (qsize > 0 && q)) {
|
|
|
|
if(psize == 0) {
|
|
|
|
e = q; q = q->next; qsize--;
|
|
|
|
} else if(qsize == 0 || !q) {
|
|
|
|
e = p; p = p->next; psize--;
|
|
|
|
} else if(cmp(p,q) <= 0) {
|
|
|
|
e = p; p = p->next; psize--;
|
|
|
|
} else {
|
|
|
|
e = q; q = q->next; qsize--;
|
|
|
|
}
|
|
|
|
if(tail) tail->next = e;
|
|
|
|
else list = e;
|
|
|
|
tail = e;
|
|
|
|
}
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
tail->next = NULL;
|
|
|
|
if(nmerges <= 1)
|
|
|
|
return list;
|
|
|
|
insize *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char graphdat[11];
|
|
|
|
char *graph(off_t max, off_t size) {
|
|
|
|
int i, c = (int) (((float) size / (float) max) * 10.0f);
|
|
|
|
for(i=0; i<10; i++)
|
|
|
|
graphdat[i] = i < c ? '#' : ' ';
|
|
|
|
graphdat[10] = '\0';
|
|
|
|
return graphdat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-24 14:52:13 +04:00
|
|
|
#define exlhid(x) if(bflags & BF_HIDE && (\
|
2008-08-02 17:43:39 +04:00
|
|
|
(x != &ref && (x->name[0] == '.' || x->name[strlen(x->name)-1] == '~'))\
|
2007-07-24 14:52:13 +04:00
|
|
|
|| x->flags & FF_EXL)\
|
|
|
|
) { i--; continue; }
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
void drawBrowser(int change) {
|
2008-09-20 13:35:21 +04:00
|
|
|
struct dir *n, ref, *sel;
|
2007-08-01 19:01:42 +04:00
|
|
|
char tmp[PATH_MAX], ct, dt, *size;
|
2007-07-24 11:58:22 +04:00
|
|
|
int selected, i, o;
|
2007-07-29 14:50:48 +04:00
|
|
|
off_t max = 1;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
erase();
|
|
|
|
|
|
|
|
/* exit if there are no items to display */
|
2007-07-26 20:37:33 +04:00
|
|
|
if(bcur == NULL || bcur->parent == NULL) {
|
|
|
|
if(bcur == NULL || bcur->sub == NULL) {
|
2007-07-20 15:15:46 +04:00
|
|
|
erase();
|
|
|
|
refresh();
|
|
|
|
endwin();
|
|
|
|
printf("No items to display...\n");
|
|
|
|
exit(0);
|
|
|
|
} else
|
|
|
|
bcur = bcur->sub;
|
|
|
|
}
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
/* create header and status bar */
|
2007-07-20 15:15:46 +04:00
|
|
|
attron(A_REVERSE);
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(0, 0, ' ', wincols);
|
|
|
|
mvhline(winrows-1, 0, ' ', wincols);
|
2007-07-20 15:15:46 +04:00
|
|
|
mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ? for help", PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
|
2007-11-02 22:22:20 +03:00
|
|
|
strcpy(tmp, cropsize(bcur->parent->size));
|
2007-08-01 17:17:26 +04:00
|
|
|
mvprintw(winrows-1, 0, " Total disk usage: %s Apparent size: %s Items: %d",
|
2007-11-02 22:22:20 +03:00
|
|
|
tmp, cropsize(bcur->parent->asize), bcur->parent->items);
|
2007-08-01 17:17:26 +04:00
|
|
|
attroff(A_REVERSE);
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(1, 0, '-', wincols);
|
2008-08-02 22:29:35 +04:00
|
|
|
mvaddch(1, 3, ' ');
|
|
|
|
getpath(bcur, tmp);
|
|
|
|
mvaddstr(1, 4, cropdir(tmp, wincols-8));
|
|
|
|
mvaddch(1, 4+(strlen(tmp) > wincols-8 ? wincols-8 : strlen(tmp)), ' ');
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2007-07-27 11:52:50 +04:00
|
|
|
/* make sure the items are in correct order */
|
|
|
|
if(!(bflags & BF_SORT)) {
|
|
|
|
bcur = sortFiles(bcur);
|
|
|
|
bcur->parent->sub = bcur;
|
|
|
|
bflags |= BF_SORT;
|
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2007-08-12 13:52:24 +04:00
|
|
|
/* add reference to parent dir */
|
|
|
|
memset(&ref, 0, sizeof(struct dir));
|
|
|
|
if(bcur->parent->parent) {
|
|
|
|
ref.name = "..";
|
|
|
|
ref.next = bcur;
|
|
|
|
ref.parent = bcur->parent;
|
|
|
|
bcur = &ref;
|
|
|
|
}
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
/* get maximum size and selected item */
|
|
|
|
for(n = bcur, selected = i = 0; n != NULL; n = n->next, i++) {
|
|
|
|
exlhid(n)
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
selected = i;
|
2008-12-11 20:07:55 +03:00
|
|
|
if((bflags & BF_AS ? n->asize : n->size) > max)
|
|
|
|
max = bflags & BF_AS ? n->asize : n->size;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
if(selected+change < 0)
|
|
|
|
change -= selected+change;
|
|
|
|
if(selected+change > --i)
|
|
|
|
change -= (selected+change)-i;
|
|
|
|
for(n = bcur, i = 0; n != NULL; n = n->next, i++) {
|
|
|
|
exlhid(n)
|
|
|
|
if(i == selected && n->flags & FF_BSEL)
|
|
|
|
n->flags -= FF_BSEL;
|
|
|
|
if(i == selected+change)
|
|
|
|
n->flags |= FF_BSEL;
|
|
|
|
}
|
|
|
|
selected += change;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
/* determine the listing format */
|
2007-07-20 15:15:46 +04:00
|
|
|
switch(bgraph) {
|
|
|
|
case 0:
|
|
|
|
sprintf(tmp, "%%c %%7s %%c%%-%ds", wincols-12);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%10s] %%c%%-%ds", wincols-24);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%4.1f%%%%] %%c%%-%ds", wincols-19);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sprintf(tmp, "%%c %%7s [%%4.1f%%%% %%10s] %%c%%-%ds", wincols-30);
|
|
|
|
}
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
/* determine start position */
|
|
|
|
for(n = bcur, i = 0; n != NULL; n = n->next, i++) {
|
|
|
|
exlhid(n)
|
|
|
|
if(i == (selected / (winrows-3)) * (winrows-3))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
selected -= i;
|
|
|
|
|
|
|
|
/* print the list to the screen */
|
|
|
|
for(i=0; n != NULL && i < winrows-3; n = n->next, i++) {
|
|
|
|
exlhid(n)
|
2008-09-20 13:35:21 +04:00
|
|
|
if(i == selected) {
|
2007-07-24 11:58:22 +04:00
|
|
|
attron(A_REVERSE);
|
2008-09-20 13:35:21 +04:00
|
|
|
sel = n;
|
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
/* reference to parent dir has a different format */
|
2008-08-02 17:43:39 +04:00
|
|
|
if(n == &ref) {
|
2007-07-24 11:58:22 +04:00
|
|
|
mvhline(i+2, 0, ' ', wincols);
|
|
|
|
o = bgraph == 0 ? 11 :
|
|
|
|
bgraph == 1 ? 23 :
|
|
|
|
bgraph == 2 ? 18 :
|
|
|
|
29 ;
|
|
|
|
mvaddstr(i+2, o, "/..");
|
|
|
|
if(i == selected)
|
|
|
|
attroff(A_REVERSE);
|
2007-07-20 15:15:46 +04:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
/* determine indication character */
|
|
|
|
ct = n->flags & FF_EXL ? '<' :
|
|
|
|
n->flags & FF_ERR ? '!' :
|
|
|
|
n->flags & FF_SERR ? '.' :
|
|
|
|
n->flags & FF_OTHFS ? '>' :
|
2007-07-29 18:06:05 +04:00
|
|
|
!(n->flags & FF_FILE
|
|
|
|
|| n->flags & FF_DIR) ? '@' :
|
2007-07-24 11:58:22 +04:00
|
|
|
n->flags & FF_DIR
|
|
|
|
&& n->sub == NULL ? 'e' :
|
2007-07-21 17:55:51 +04:00
|
|
|
' ' ;
|
2007-07-24 11:58:22 +04:00
|
|
|
dt = n->flags & FF_DIR ? '/' : ' ';
|
2007-08-01 19:01:42 +04:00
|
|
|
size = cropsize(bflags & BF_AS ? n->asize : n->size);
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
/* format and add item to the list */
|
2007-07-20 15:15:46 +04:00
|
|
|
switch(bgraph) {
|
|
|
|
case 0:
|
2007-08-01 19:01:42 +04:00
|
|
|
mvprintw(i+2, 0, tmp, ct, size,
|
2007-07-24 11:58:22 +04:00
|
|
|
dt, cropdir(n->name, wincols-12)
|
|
|
|
);
|
2007-07-20 15:15:46 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2007-08-01 19:01:42 +04:00
|
|
|
mvprintw(i+2, 0, tmp, ct, size,
|
2008-12-11 20:07:55 +03:00
|
|
|
graph(max, bflags & BF_AS ? n->asize : n->size),
|
2007-07-24 11:58:22 +04:00
|
|
|
dt, cropdir(n->name, wincols-24)
|
|
|
|
);
|
2007-07-20 15:15:46 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2007-08-01 19:01:42 +04:00
|
|
|
mvprintw(i+2, 0, tmp, ct, size,
|
2007-07-24 11:58:22 +04:00
|
|
|
((float) n->size / (float) n->parent->size) * 100.0f,
|
|
|
|
dt, cropdir(n->name, wincols-19)
|
|
|
|
);
|
2007-07-20 15:15:46 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2007-08-01 19:01:42 +04:00
|
|
|
mvprintw(i+2, 0, tmp, ct, size,
|
2008-12-11 20:07:55 +03:00
|
|
|
((float) n->size / (float) n->parent->size) * 100.0f, graph(max, bflags & BF_AS ? n->asize : n->size),
|
2007-07-24 11:58:22 +04:00
|
|
|
dt, cropdir(n->name, wincols-30)
|
|
|
|
);
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
if(i == selected)
|
|
|
|
attroff(A_REVERSE);
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2007-08-12 13:52:24 +04:00
|
|
|
|
2008-08-02 17:31:21 +04:00
|
|
|
/* move cursor to selected row for accessibility */
|
|
|
|
move(selected+2, 0);
|
|
|
|
|
2008-09-20 13:35:21 +04:00
|
|
|
/* show file information window */
|
|
|
|
if(bflags & BF_INFO) {
|
|
|
|
if(sel == bcur && bcur == &ref)
|
|
|
|
bflags -= BF_INFO;
|
|
|
|
else
|
|
|
|
drawInfo(sel);
|
|
|
|
}
|
|
|
|
|
2007-08-12 13:52:24 +04:00
|
|
|
/* remove reference to parent dir */
|
|
|
|
if(bcur == &ref)
|
|
|
|
bcur = ref.next;
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dir * selected(void) {
|
|
|
|
struct dir *n = bcur;
|
|
|
|
do {
|
|
|
|
if(n->flags & FF_BSEL)
|
|
|
|
return n;
|
|
|
|
} while((n = n->next) != NULL);
|
2007-08-12 13:52:24 +04:00
|
|
|
if(bcur->parent->parent)
|
|
|
|
return(bcur->parent);
|
2007-07-29 14:50:48 +04:00
|
|
|
return NULL;
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define toggle(x,y) if(x & y) x -=y; else x |= y
|
2008-09-20 13:35:21 +04:00
|
|
|
#define hideinfo if(bflags & BF_INFO) bflags -= BF_INFO
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
void showBrowser(void) {
|
2007-07-27 11:52:50 +04:00
|
|
|
int ch, change, oldflags;
|
2007-07-26 16:56:24 +04:00
|
|
|
char tmp[PATH_MAX];
|
2007-07-27 11:52:50 +04:00
|
|
|
struct dir *n, *t, *d, *last;
|
2007-07-20 15:15:46 +04:00
|
|
|
|
2007-07-25 22:38:49 +04:00
|
|
|
bcur = dat->sub;
|
2007-07-24 11:58:22 +04:00
|
|
|
bgraph = 1;
|
|
|
|
nodelay(stdscr, 0);
|
2007-07-24 12:25:44 +04:00
|
|
|
bflags = BF_SIZE | BF_DESC | BF_NDIRF;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
drawBrowser(0);
|
2007-07-20 15:15:46 +04:00
|
|
|
refresh();
|
2007-07-24 11:58:22 +04:00
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
while((ch = getch())) {
|
2007-07-24 11:58:22 +04:00
|
|
|
change = 0;
|
2007-07-27 11:52:50 +04:00
|
|
|
last = bcur;
|
|
|
|
oldflags = bflags;
|
|
|
|
|
2007-07-20 15:15:46 +04:00
|
|
|
switch(ch) {
|
2007-07-24 11:58:22 +04:00
|
|
|
/* selecting items */
|
|
|
|
case KEY_UP:
|
|
|
|
change = -1;
|
2007-07-20 15:15:46 +04:00
|
|
|
break;
|
2007-07-24 11:58:22 +04:00
|
|
|
case KEY_DOWN:
|
|
|
|
change = 1;
|
2007-07-20 15:15:46 +04:00
|
|
|
break;
|
2007-07-24 11:58:22 +04:00
|
|
|
case KEY_HOME:
|
|
|
|
change = -16777216;
|
|
|
|
break;
|
|
|
|
case KEY_LL:
|
|
|
|
case KEY_END:
|
|
|
|
change = 16777216;
|
|
|
|
break;
|
|
|
|
case KEY_PPAGE:
|
|
|
|
change = -1*(winrows-3);
|
|
|
|
break;
|
|
|
|
case KEY_NPAGE:
|
|
|
|
change = winrows-3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* sorting items */
|
2007-07-20 15:15:46 +04:00
|
|
|
case 'n':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
if(bflags & BF_NAME)
|
|
|
|
toggle(bflags, BF_DESC);
|
|
|
|
else
|
|
|
|
bflags = (bflags & BF_HIDE) + (bflags & BF_NDIRF) + BF_NAME;
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 's':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
if(bflags & BF_SIZE)
|
|
|
|
toggle(bflags, BF_DESC);
|
|
|
|
else
|
2007-07-24 12:25:44 +04:00
|
|
|
bflags = (bflags & BF_HIDE) + (bflags & BF_NDIRF) + BF_SIZE + BF_DESC;
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 'p':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
toggle(sflags, SF_SI);
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 'h':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
toggle(bflags, BF_HIDE);
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 't':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
toggle(bflags, BF_NDIRF);
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
2007-08-01 19:01:42 +04:00
|
|
|
case 'a':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-08-01 19:01:42 +04:00
|
|
|
toggle(bflags, BF_AS);
|
|
|
|
break;
|
2007-07-24 11:58:22 +04:00
|
|
|
|
|
|
|
/* browsing */
|
|
|
|
case 10:
|
|
|
|
case KEY_RIGHT:
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-24 11:58:22 +04:00
|
|
|
n = selected();
|
2007-08-12 13:52:24 +04:00
|
|
|
if(n == bcur->parent)
|
2007-07-26 20:37:33 +04:00
|
|
|
bcur = bcur->parent->parent->sub;
|
2007-07-24 11:58:22 +04:00
|
|
|
else if(n->sub != NULL)
|
|
|
|
bcur = n->sub;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-24 11:58:22 +04:00
|
|
|
if(bcur->parent->parent != NULL) {
|
2007-07-26 20:37:33 +04:00
|
|
|
bcur = bcur->parent->parent->sub;
|
2007-07-24 11:58:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-26 16:56:24 +04:00
|
|
|
/* refresh */
|
|
|
|
case 'r':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
|
|
|
drawBrowser(0);
|
2007-07-26 16:56:24 +04:00
|
|
|
if((n = showCalc(getpath(bcur, tmp))) != NULL) {
|
|
|
|
/* free current items */
|
2007-07-26 20:37:33 +04:00
|
|
|
d = bcur;
|
2007-07-26 16:56:24 +04:00
|
|
|
bcur = bcur->parent;
|
|
|
|
while(d != NULL) {
|
|
|
|
t = d;
|
|
|
|
d = t->next;
|
|
|
|
freedir(t);
|
|
|
|
}
|
2007-07-26 20:37:33 +04:00
|
|
|
|
2007-07-26 16:56:24 +04:00
|
|
|
/* update parent dir */
|
|
|
|
bcur->sub = n->sub;
|
2007-08-01 17:17:26 +04:00
|
|
|
bcur->items = n->items;
|
2007-07-26 16:56:24 +04:00
|
|
|
bcur->size = n->size;
|
2008-09-17 20:40:39 +04:00
|
|
|
bcur->asize = n->asize;
|
2007-07-26 16:56:24 +04:00
|
|
|
for(t = bcur->sub; t != NULL; t = t->next)
|
|
|
|
t->parent = bcur;
|
|
|
|
|
|
|
|
/* update sizes of parent dirs */
|
|
|
|
for(t = bcur; (t = t->parent) != NULL; ) {
|
|
|
|
t->size += bcur->size;
|
2008-09-17 20:40:39 +04:00
|
|
|
t->asize += bcur->asize;
|
2007-08-01 17:17:26 +04:00
|
|
|
t->items += bcur->items;
|
2007-07-26 16:56:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bcur = bcur->sub;
|
|
|
|
free(n->name);
|
|
|
|
free(n);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
/* and other stuff */
|
|
|
|
case KEY_RESIZE:
|
|
|
|
ncresize();
|
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 'g':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-20 15:15:46 +04:00
|
|
|
if(++bgraph > 3) bgraph = 0;
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
|
|
|
case '?':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
2007-07-24 11:58:22 +04:00
|
|
|
showHelp();
|
|
|
|
break;
|
2007-08-01 19:01:42 +04:00
|
|
|
case 'i':
|
2008-09-20 13:35:21 +04:00
|
|
|
toggle(bflags, BF_INFO);
|
2007-08-01 19:01:42 +04:00
|
|
|
break;
|
2007-07-20 15:15:46 +04:00
|
|
|
case 'd':
|
2008-09-20 13:35:21 +04:00
|
|
|
hideinfo;
|
|
|
|
drawBrowser(0);
|
2007-07-24 11:58:22 +04:00
|
|
|
n = selected();
|
2007-08-12 13:52:24 +04:00
|
|
|
if(n != bcur->parent)
|
2007-07-24 11:58:22 +04:00
|
|
|
bcur = showDelete(n);
|
2007-07-26 20:37:33 +04:00
|
|
|
if(bcur && bcur->parent)
|
|
|
|
bcur = bcur->parent->sub;
|
2007-07-24 11:58:22 +04:00
|
|
|
break;
|
|
|
|
case 'q':
|
2008-10-19 12:02:02 +04:00
|
|
|
if(bflags & BF_INFO)
|
|
|
|
bflags -= BF_INFO;
|
|
|
|
else
|
|
|
|
goto endloop;
|
2007-07-20 15:15:46 +04:00
|
|
|
}
|
2008-09-20 13:35:21 +04:00
|
|
|
if((last != bcur || (oldflags | BF_HIDE | BF_AS | BF_INFO) != (bflags | BF_HIDE | BF_AS | BF_INFO)) && bflags & BF_SORT)
|
2007-07-27 11:52:50 +04:00
|
|
|
bflags -= BF_SORT;
|
|
|
|
|
2007-07-24 11:58:22 +04:00
|
|
|
drawBrowser(change);
|
2007-07-20 15:15:46 +04:00
|
|
|
refresh();
|
|
|
|
}
|
2007-07-24 11:58:22 +04:00
|
|
|
endloop:
|
2007-07-20 15:15:46 +04:00
|
|
|
erase();
|
|
|
|
}
|
|
|
|
|
|
|
|
|