Added 'r' key to refresh the current directory
git-svn-id: svn://blicky.net/ncdu/trunk@11 ce56bc8d-f834-0410-b703-f827bd498a76
Этот коммит содержится в:
родитель
ce6785124c
Коммит
362554d2ac
@ -283,7 +283,8 @@ struct dir * selected(void) {
|
||||
|
||||
void showBrowser(void) {
|
||||
int ch, change;
|
||||
struct dir *n;
|
||||
char tmp[PATH_MAX];
|
||||
struct dir *n, *t, *d;
|
||||
|
||||
bcur = dat->sub;
|
||||
bgraph = 1;
|
||||
@ -355,6 +356,54 @@ void showBrowser(void) {
|
||||
}
|
||||
break;
|
||||
|
||||
/* refresh */
|
||||
case 'r':
|
||||
if((n = showCalc(getpath(bcur, tmp))) != NULL) {
|
||||
/* free current items */
|
||||
t = bcur;
|
||||
bcur = bcur->parent;
|
||||
while(t->prev != NULL)
|
||||
t = t->prev;
|
||||
d = t;
|
||||
while(d != NULL) {
|
||||
t = d;
|
||||
d = t->next;
|
||||
freedir(t);
|
||||
}
|
||||
|
||||
/* update parent dir */
|
||||
bcur->sub = n->sub;
|
||||
bcur->files = n->files;
|
||||
bcur->dirs = n->dirs;
|
||||
bcur->size = n->size;
|
||||
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;
|
||||
t->files += bcur->files;
|
||||
t->dirs += bcur->dirs+1;
|
||||
}
|
||||
|
||||
/* add reference to parent dir */
|
||||
if(bcur->parent) {
|
||||
t = calloc(sizeof(struct dir), 1);
|
||||
t->name = malloc(3);
|
||||
t->flags |= FF_PAR;
|
||||
strcpy(t->name, "..");
|
||||
t->parent = bcur;
|
||||
t->next = bcur->sub;
|
||||
t->next->prev = t;
|
||||
bcur->sub = t;
|
||||
}
|
||||
|
||||
bcur = bcur->sub;
|
||||
free(n->name);
|
||||
free(n);
|
||||
}
|
||||
break;
|
||||
|
||||
/* and other stuff */
|
||||
case KEY_RESIZE:
|
||||
ncresize();
|
||||
|
16
src/calc.c
16
src/calc.c
@ -142,7 +142,7 @@ static void drawProgress(char *cdir) {
|
||||
prg = newwin(10, 60, winrows/2-3, wincols/2-30);
|
||||
box(prg, 0, 0);
|
||||
wattron(prg, A_BOLD);
|
||||
mvwaddstr(prg, 0, 4, "Calculating...");
|
||||
mvwaddstr(prg, 0, 4, dat == NULL ? "Calculating..." : "Recalculating...");
|
||||
wattroff(prg, A_BOLD);
|
||||
|
||||
mvwprintw(prg, 2, 2, "Total files: %-8d dirs: %-8d size: %s",
|
||||
@ -209,6 +209,8 @@ int updateProgress(char *path) {
|
||||
return(0);
|
||||
if(ch == KEY_RESIZE) {
|
||||
ncresize();
|
||||
if(dat != NULL)
|
||||
drawBrowser(0);
|
||||
drawProgress(path);
|
||||
}
|
||||
}
|
||||
@ -368,6 +370,7 @@ int calcDir(struct dir *dest, char *path) {
|
||||
struct dir *showCalc(char *path) {
|
||||
char tmp[PATH_MAX];
|
||||
struct stat fs;
|
||||
struct dir *t;
|
||||
|
||||
/* init/reset global vars */
|
||||
*lasterr = '\0';
|
||||
@ -378,12 +381,15 @@ struct dir *showCalc(char *path) {
|
||||
if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0) {
|
||||
do {
|
||||
ncresize();
|
||||
if(dat != NULL)
|
||||
drawBrowser(0);
|
||||
drawError(path);
|
||||
} while (getch() == KEY_RESIZE);
|
||||
return(NULL);
|
||||
}
|
||||
parent = calloc(sizeof(struct dir), 1);
|
||||
parent->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512;
|
||||
parent->flags |= FF_DIR;
|
||||
curdev = fs.st_dev;
|
||||
parent->name = malloc(strlen(tmp)+1);
|
||||
strcpy(parent->name, tmp);
|
||||
@ -393,6 +399,14 @@ struct dir *showCalc(char *path) {
|
||||
freedir(parent);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* remove reference to parent dir if we are in the parent dir */
|
||||
t = parent->sub;
|
||||
parent->sub = t->next;
|
||||
parent->sub->prev = NULL;
|
||||
free(t->name);
|
||||
free(t);
|
||||
|
||||
return(parent);
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ int main(int argc, char **argv) {
|
||||
if(gd && settingsWin())
|
||||
goto mainend;
|
||||
|
||||
dat = NULL;
|
||||
while((dat = showCalc(sdir)) == NULL)
|
||||
if(settingsWin())
|
||||
goto mainend;
|
||||
|
@ -90,6 +90,7 @@ void ncresize(void) {
|
||||
if(ch == 'i')
|
||||
sflags |= SF_IGNS;
|
||||
}
|
||||
erase();
|
||||
}
|
||||
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user