mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-17 11:08:41 -09:00
Added 'r' key to refresh the current directory
git-svn-id: svn://blicky.net/ncdu/trunk@11 ce56bc8d-f834-0410-b703-f827bd498a76
This commit is contained in:
parent
ce6785124c
commit
362554d2ac
4 changed files with 67 additions and 2 deletions
|
|
@ -283,7 +283,8 @@ struct dir * selected(void) {
|
||||||
|
|
||||||
void showBrowser(void) {
|
void showBrowser(void) {
|
||||||
int ch, change;
|
int ch, change;
|
||||||
struct dir *n;
|
char tmp[PATH_MAX];
|
||||||
|
struct dir *n, *t, *d;
|
||||||
|
|
||||||
bcur = dat->sub;
|
bcur = dat->sub;
|
||||||
bgraph = 1;
|
bgraph = 1;
|
||||||
|
|
@ -355,6 +356,54 @@ void showBrowser(void) {
|
||||||
}
|
}
|
||||||
break;
|
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 */
|
/* and other stuff */
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
ncresize();
|
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);
|
prg = newwin(10, 60, winrows/2-3, wincols/2-30);
|
||||||
box(prg, 0, 0);
|
box(prg, 0, 0);
|
||||||
wattron(prg, A_BOLD);
|
wattron(prg, A_BOLD);
|
||||||
mvwaddstr(prg, 0, 4, "Calculating...");
|
mvwaddstr(prg, 0, 4, dat == NULL ? "Calculating..." : "Recalculating...");
|
||||||
wattroff(prg, A_BOLD);
|
wattroff(prg, A_BOLD);
|
||||||
|
|
||||||
mvwprintw(prg, 2, 2, "Total files: %-8d dirs: %-8d size: %s",
|
mvwprintw(prg, 2, 2, "Total files: %-8d dirs: %-8d size: %s",
|
||||||
|
|
@ -209,6 +209,8 @@ int updateProgress(char *path) {
|
||||||
return(0);
|
return(0);
|
||||||
if(ch == KEY_RESIZE) {
|
if(ch == KEY_RESIZE) {
|
||||||
ncresize();
|
ncresize();
|
||||||
|
if(dat != NULL)
|
||||||
|
drawBrowser(0);
|
||||||
drawProgress(path);
|
drawProgress(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -368,6 +370,7 @@ int calcDir(struct dir *dest, char *path) {
|
||||||
struct dir *showCalc(char *path) {
|
struct dir *showCalc(char *path) {
|
||||||
char tmp[PATH_MAX];
|
char tmp[PATH_MAX];
|
||||||
struct stat fs;
|
struct stat fs;
|
||||||
|
struct dir *t;
|
||||||
|
|
||||||
/* init/reset global vars */
|
/* init/reset global vars */
|
||||||
*lasterr = '\0';
|
*lasterr = '\0';
|
||||||
|
|
@ -378,12 +381,15 @@ struct dir *showCalc(char *path) {
|
||||||
if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0) {
|
if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0) {
|
||||||
do {
|
do {
|
||||||
ncresize();
|
ncresize();
|
||||||
|
if(dat != NULL)
|
||||||
|
drawBrowser(0);
|
||||||
drawError(path);
|
drawError(path);
|
||||||
} while (getch() == KEY_RESIZE);
|
} while (getch() == KEY_RESIZE);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
parent = calloc(sizeof(struct dir), 1);
|
parent = calloc(sizeof(struct dir), 1);
|
||||||
parent->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512;
|
parent->size = sflags & SF_AS ? fs.st_size : fs.st_blocks * 512;
|
||||||
|
parent->flags |= FF_DIR;
|
||||||
curdev = fs.st_dev;
|
curdev = fs.st_dev;
|
||||||
parent->name = malloc(strlen(tmp)+1);
|
parent->name = malloc(strlen(tmp)+1);
|
||||||
strcpy(parent->name, tmp);
|
strcpy(parent->name, tmp);
|
||||||
|
|
@ -393,6 +399,14 @@ struct dir *showCalc(char *path) {
|
||||||
freedir(parent);
|
freedir(parent);
|
||||||
return(NULL);
|
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);
|
return(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ int main(int argc, char **argv) {
|
||||||
if(gd && settingsWin())
|
if(gd && settingsWin())
|
||||||
goto mainend;
|
goto mainend;
|
||||||
|
|
||||||
|
dat = NULL;
|
||||||
while((dat = showCalc(sdir)) == NULL)
|
while((dat = showCalc(sdir)) == NULL)
|
||||||
if(settingsWin())
|
if(settingsWin())
|
||||||
goto mainend;
|
goto mainend;
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ void ncresize(void) {
|
||||||
if(ch == 'i')
|
if(ch == 'i')
|
||||||
sflags |= SF_IGNS;
|
sflags |= SF_IGNS;
|
||||||
}
|
}
|
||||||
|
erase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue