mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
* Added error handling for the import feature
* Created own window-functions and removed ncurses window usage * Rewrote fullsize git-svn-id: svn://blicky.net/ncdu/trunk@27 ce56bc8d-f834-0410-b703-f827bd498a76
This commit is contained in:
parent
96d0ffffa2
commit
db920f8dab
8 changed files with 264 additions and 203 deletions
|
|
@ -29,31 +29,26 @@ struct dir *bcur;
|
||||||
|
|
||||||
|
|
||||||
void drawInfo(struct dir *dr) {
|
void drawInfo(struct dir *dr) {
|
||||||
WINDOW *nfo;
|
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
nfo = newwin(11, 60, winrows/2-5, wincols/2-30);
|
nccreate(11, 60, "Item info");
|
||||||
box(nfo, 0, 0);
|
|
||||||
wattron(nfo, A_BOLD);
|
|
||||||
mvwaddstr(nfo, 0, 4, "Item info");
|
|
||||||
|
|
||||||
mvwaddstr(nfo, 2, 3, "Name:");
|
attron(A_BOLD);
|
||||||
mvwaddstr(nfo, 3, 3, "Path:");
|
ncaddstr(2, 3, "Name:");
|
||||||
mvwaddstr(nfo, 4, 3, "Type:");
|
ncaddstr(3, 3, "Path:");
|
||||||
mvwaddstr(nfo, 6, 3, " Disk usage:");
|
ncaddstr(4, 3, "Type:");
|
||||||
mvwaddstr(nfo, 7, 3, "Apparent size:");
|
ncaddstr(6, 3, " Disk usage:");
|
||||||
wattroff(nfo, A_BOLD);
|
ncaddstr(7, 3, "Apparent size:");
|
||||||
|
attroff(A_BOLD);
|
||||||
|
|
||||||
mvwaddstr(nfo, 2, 9, cropdir(dr->name, 49));
|
ncaddstr(2, 9, cropdir(dr->name, 49));
|
||||||
mvwaddstr(nfo, 3, 9, cropdir(getpath(dr, path), 49));
|
ncaddstr(3, 9, cropdir(getpath(dr, path), 49));
|
||||||
mvwaddstr(nfo, 4, 9, dr->flags & FF_DIR ? "Directory"
|
ncaddstr(4, 9, dr->flags & FF_DIR ? "Directory"
|
||||||
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
|
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
|
||||||
mvwprintw(nfo, 6, 18, "%s (%s B)", cropsize(dr->size), fullsize(dr->size));
|
ncprint(6, 18, "%s (%s B)", cropsize(dr->size), fullsize(dr->size));
|
||||||
mvwprintw(nfo, 7, 18, "%s (%s B)", cropsize(dr->asize), fullsize(dr->asize));
|
ncprint(7, 18, "%s (%s B)", cropsize(dr->asize), fullsize(dr->asize));
|
||||||
|
|
||||||
mvwaddstr(nfo, 9, 32, "Press any key to continue");
|
ncaddstr(9, 32, "Press any key to continue");
|
||||||
wrefresh(nfo);
|
|
||||||
delwin(nfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
46
src/calc.c
46
src/calc.c
|
|
@ -135,28 +135,23 @@ char *rpath(const char *from, char *to) {
|
||||||
|
|
||||||
/* the progress window */
|
/* the progress window */
|
||||||
static void drawProgress(char *cdir) {
|
static void drawProgress(char *cdir) {
|
||||||
WINDOW *prg;
|
|
||||||
char ani[15];
|
char ani[15];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
prg = newwin(10, 60, winrows/2-3, wincols/2-30);
|
nccreate(10, 60, dat == NULL ? "Calculating..." : "Recalculating...");
|
||||||
box(prg, 0, 0);
|
|
||||||
wattron(prg, A_BOLD);
|
|
||||||
mvwaddstr(prg, 0, 4, dat == NULL ? "Calculating..." : "Recalculating...");
|
|
||||||
wattroff(prg, A_BOLD);
|
|
||||||
|
|
||||||
mvwprintw(prg, 2, 2, "Total items: %-8d size: %s",
|
ncprint(2, 2, "Total items: %-8d size: %s",
|
||||||
parent->items, cropsize(parent->size));
|
parent->items, cropsize(parent->size));
|
||||||
mvwprintw(prg, 3, 2, "Current dir: %s", cropdir(cdir, 43));
|
ncprint(3, 2, "Current dir: %s", cropdir(cdir, 43));
|
||||||
mvwaddstr(prg, 8, 43, "Press q to quit");
|
ncaddstr(8, 43, "Press q to quit");
|
||||||
|
|
||||||
/* show warning if we couldn't open a dir */
|
/* show warning if we couldn't open a dir */
|
||||||
if(lasterr[0] != '\0') {
|
if(lasterr[0] != '\0') {
|
||||||
wattron(prg, A_BOLD);
|
attron(A_BOLD);
|
||||||
mvwaddstr(prg, 5, 2, "Warning:");
|
ncaddstr(5, 2, "Warning:");
|
||||||
wattroff(prg, A_BOLD);
|
attroff(A_BOLD);
|
||||||
mvwprintw(prg, 5, 11, "could not open %-32s", cropdir(lasterr, 32));
|
ncprint(5, 11, "could not open %-32s", cropdir(lasterr, 32));
|
||||||
mvwaddstr(prg, 6, 3, "some directory sizes may not be correct");
|
ncaddstr(6, 3, "some directory sizes may not be correct");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* animation - but only if the screen refreshes more than or once every second */
|
/* animation - but only if the screen refreshes more than or once every second */
|
||||||
|
|
@ -171,30 +166,24 @@ static void drawProgress(char *cdir) {
|
||||||
ani[i] = antext[i];
|
ani[i] = antext[i];
|
||||||
} else
|
} else
|
||||||
strcpy(ani, antext);
|
strcpy(ani, antext);
|
||||||
mvwaddstr(prg, 8, 3, ani);
|
ncaddstr(8, 3, ani);
|
||||||
|
|
||||||
wrefresh(prg);
|
refresh();
|
||||||
delwin(prg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* show error if can't open parent dir */
|
/* show error if can't open parent dir */
|
||||||
static void drawError(char *dir) {
|
static void drawError(char *dir) {
|
||||||
WINDOW *err;
|
nccreate(10, 60, "Error!");
|
||||||
|
|
||||||
err = newwin(10, 60, winrows/2-3, wincols/2-30);
|
attron(A_BOLD);
|
||||||
box(err, 0, 0);
|
ncaddstr(5, 2, "Error:");
|
||||||
wattron(err, A_BOLD);
|
attroff(A_BOLD);
|
||||||
mvwaddstr(err, 0, 4, "Error!");
|
|
||||||
|
|
||||||
mvwaddstr(err, 5, 2, "Error:");
|
ncprint(5, 9, "could not open %s", cropdir(dir, 34));
|
||||||
wattroff(err, A_BOLD);
|
ncaddstr(6, 3, "press any key to continue...");
|
||||||
mvwprintw(err, 5, 9, "could not open %s", cropdir(dir, 34));
|
|
||||||
mvwaddstr(err, 6, 3, "press any key to continue...");
|
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
wrefresh(err);
|
|
||||||
delwin(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -380,7 +369,6 @@ struct dir *showCalc(char *path) {
|
||||||
if(dat != NULL)
|
if(dat != NULL)
|
||||||
drawBrowser(0);
|
drawBrowser(0);
|
||||||
drawError(path);
|
drawError(path);
|
||||||
refresh();
|
|
||||||
} while (getch() == KEY_RESIZE);
|
} while (getch() == KEY_RESIZE);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
84
src/delete.c
84
src/delete.c
|
|
@ -29,84 +29,62 @@ suseconds_t lastupdate;
|
||||||
|
|
||||||
|
|
||||||
void drawConfirm(struct dir *del, int sel) {
|
void drawConfirm(struct dir *del, int sel) {
|
||||||
WINDOW *cfm;
|
nccreate(6, 60, "Confirm delete");
|
||||||
|
|
||||||
cfm = newwin(6, 60, winrows/2-3, wincols/2-30);
|
ncprint(1, 2, "Are you sure you want to delete \"%s\"%c",
|
||||||
box(cfm, 0, 0);
|
|
||||||
wattron(cfm, A_BOLD);
|
|
||||||
mvwaddstr(cfm, 0, 4, "Confirm delete");
|
|
||||||
wattroff(cfm, A_BOLD);
|
|
||||||
|
|
||||||
mvwprintw(cfm, 1, 2, "Are you sure you want to delete \"%s\"%c",
|
|
||||||
cropdir(del->name, 21), del->flags & FF_DIR ? ' ' : '?');
|
cropdir(del->name, 21), del->flags & FF_DIR ? ' ' : '?');
|
||||||
if(del->flags & FF_DIR)
|
if(del->flags & FF_DIR)
|
||||||
mvwprintw(cfm, 2, 18, "and all of its contents?");
|
ncprint(2, 18, "and all of its contents?");
|
||||||
|
|
||||||
if(sel == 0)
|
if(sel == 0)
|
||||||
wattron(cfm, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(cfm, 4, 15, "yes");
|
ncaddstr(4, 15, "yes");
|
||||||
wattroff(cfm, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(sel == 1)
|
if(sel == 1)
|
||||||
wattron(cfm, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(cfm, 4, 24, "no");
|
ncaddstr(4, 24, "no");
|
||||||
wattroff(cfm, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(sel == 2)
|
if(sel == 2)
|
||||||
wattron(cfm, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(cfm, 4, 31, "don't ask me again");
|
ncaddstr(4, 31, "don't ask me again");
|
||||||
wattroff(cfm, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
|
|
||||||
wrefresh(cfm);
|
refresh();
|
||||||
delwin(cfm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* show progress */
|
/* show progress */
|
||||||
static void drawProgress(char *file) {
|
static void drawProgress(char *file) {
|
||||||
WINDOW *prg;
|
nccreate(6, 60, "Deleting...");
|
||||||
|
|
||||||
prg = newwin(6, 60, winrows/2-3, wincols/2-30);
|
ncaddstr(1, 2, cropdir(file, 47));
|
||||||
nodelay(prg, 1);
|
ncaddstr(4, 41, "Press q to abort");
|
||||||
box(prg, 0, 0);
|
|
||||||
wattron(prg, A_BOLD);
|
|
||||||
mvwaddstr(prg, 0, 4, "Deleting...");
|
|
||||||
wattroff(prg, A_BOLD);
|
|
||||||
|
|
||||||
mvwaddstr(prg, 1, 2, cropdir(file, 47));
|
refresh();
|
||||||
mvwaddstr(prg, 4, 41, "Press q to abort");
|
|
||||||
|
|
||||||
wrefresh(prg);
|
|
||||||
delwin(prg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* show error dialog */
|
/* show error dialog */
|
||||||
static void drawError(int sel, char *file) {
|
static void drawError(int sel, char *file) {
|
||||||
WINDOW *err;
|
nccreate(6, 60, "Error!");
|
||||||
|
|
||||||
err = newwin(6, 60, winrows/2-3, wincols/2-30);
|
ncprint(1, 2, "Can't delete %s:", cropdir(file, 42));
|
||||||
box(err, 0, 0);
|
ncaddstr(2, 4, strerror(errno));
|
||||||
wattron(err, A_BOLD);
|
|
||||||
mvwaddstr(err, 0, 4, "Error!");
|
|
||||||
wattroff(err, A_BOLD);
|
|
||||||
|
|
||||||
mvwprintw(err, 1, 2, "Can't delete %s:", cropdir(file, 42));
|
|
||||||
mvwaddstr(err, 2, 4, strerror(errno));
|
|
||||||
|
|
||||||
if(sel == 0)
|
if(sel == 0)
|
||||||
wattron(err, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(err, 4, 14, "abort");
|
ncaddstr(4, 14, "abort");
|
||||||
wattroff(err, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(sel == 1)
|
if(sel == 1)
|
||||||
wattron(err, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(err, 4, 23, "ignore");
|
ncaddstr(4, 23, "ignore");
|
||||||
wattroff(err, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(sel == 2)
|
if(sel == 2)
|
||||||
wattron(err, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(err, 4, 33, "ignore all");
|
ncaddstr(4, 33, "ignore all");
|
||||||
wattroff(err, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
|
|
||||||
wrefresh(err);
|
refresh();
|
||||||
delwin(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
58
src/export.c
58
src/export.c
|
|
@ -39,7 +39,7 @@ unsigned int ilevel;
|
||||||
|
|
||||||
#define writeInt(hl, word, bytes) _writeInt(hl, (unsigned char *) &word, bytes, sizeof(word))
|
#define writeInt(hl, word, bytes) _writeInt(hl, (unsigned char *) &word, bytes, sizeof(word))
|
||||||
|
|
||||||
/* Write any integer in network byte order.
|
/* Write any unsigned integer in network byte order.
|
||||||
* This function always writes the number of bytes specified by storage to the
|
* This function always writes the number of bytes specified by storage to the
|
||||||
* file, disregarding the actual size of word. If the actual size is smaller
|
* file, disregarding the actual size of word. If the actual size is smaller
|
||||||
* than the storage, the number will be preceded by null-bytes. If the actual
|
* than the storage, the number will be preceded by null-bytes. If the actual
|
||||||
|
|
@ -116,6 +116,7 @@ void exportFile(char *dest, struct dir *src) {
|
||||||
/* header */
|
/* header */
|
||||||
fprintf(wr, "ncdu%c%s%c", 1, PACKAGE_STRING, 0);
|
fprintf(wr, "ncdu%c%s%c", 1, PACKAGE_STRING, 0);
|
||||||
|
|
||||||
|
/* we assume timestamp > 0 */
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
writeInt(wr, tv.tv_sec, 8);
|
writeInt(wr, tv.tv_sec, 8);
|
||||||
|
|
||||||
|
|
@ -137,10 +138,10 @@ void exportFile(char *dest, struct dir *src) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define readInt(hl, word, bytes) _readInt(hl, (unsigned char *) &word, bytes, sizeof(word))
|
#define readInt(hl, word, bytes) if(!_readInt(hl, (unsigned char *) &word, bytes, sizeof(word))) return(NULL)
|
||||||
|
|
||||||
/* reverse of writeInt */
|
/* reverse of writeInt */
|
||||||
void _readInt(FILE *rd, unsigned char *word, int storage, int size) {
|
int _readInt(FILE *rd, unsigned char *word, int storage, int size) {
|
||||||
unsigned char buf[8];
|
unsigned char buf[8];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
@ -148,7 +149,8 @@ void _readInt(FILE *rd, unsigned char *word, int storage, int size) {
|
||||||
memset(buf, 0, 8);
|
memset(buf, 0, 8);
|
||||||
|
|
||||||
/* read integer to the end of the buffer */
|
/* read integer to the end of the buffer */
|
||||||
fread(buf+(8-storage), 1, storage, rd);
|
if(fread(buf+(8-storage), 1, storage, rd) != storage)
|
||||||
|
return(0);
|
||||||
|
|
||||||
/* copy buf to word, in host byte order */
|
/* copy buf to word, in host byte order */
|
||||||
if(IS_BIG_ENDIAN)
|
if(IS_BIG_ENDIAN)
|
||||||
|
|
@ -156,6 +158,7 @@ void _readInt(FILE *rd, unsigned char *word, int storage, int size) {
|
||||||
else
|
else
|
||||||
for(i=0; i<size; i++)
|
for(i=0; i<size; i++)
|
||||||
word[i] = buf[7-i];
|
word[i] = buf[7-i];
|
||||||
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -167,17 +170,21 @@ struct dir *importFile(char *filename) {
|
||||||
unsigned int level;
|
unsigned int level;
|
||||||
struct dir *prev, *cur, *tmp, *parent;
|
struct dir *prev, *cur, *tmp, *parent;
|
||||||
|
|
||||||
rd = fopen(filename, "r");
|
if(!(rd = fopen(filename, "r")))
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
/* check filetype */
|
/* check filetype */
|
||||||
fread(buf, 1, 5, rd);
|
if(fread(buf, 1, 5, rd) != 5)
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
if(buf[0] != 'n' || buf[1] != 'c' || buf[2] != 'd'
|
if(buf[0] != 'n' || buf[1] != 'c' || buf[2] != 'd'
|
||||||
|| buf[3] != 'u' || buf[4] != (char) 1)
|
|| buf[3] != 'u' || buf[4] != (char) 1)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
/* package name, version and timestamp are ignored for now */
|
/* package name, version and timestamp are ignored for now */
|
||||||
for(i=0; i<=64 && fgetc(rd) != 0; i++) ;
|
for(i=0; i<=64 && fgetc(rd) != 0; i++) ;
|
||||||
fread(buf, 1, 8, rd);
|
if(fread(buf, 1, 8, rd) != 8)
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
/* number of items is not ignored */
|
/* number of items is not ignored */
|
||||||
readInt(rd, items, 4);
|
readInt(rd, items, 4);
|
||||||
|
|
@ -187,21 +194,21 @@ struct dir *importFile(char *filename) {
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
for(item=0; item<items; item++) {
|
for(item=0; item<items; item++) {
|
||||||
unsigned int curlev;
|
unsigned int curlev;
|
||||||
unsigned char flags, name[8192];
|
unsigned char name[8192];
|
||||||
int ch;
|
int ch, flags;
|
||||||
|
|
||||||
readInt(rd, curlev, 2);
|
readInt(rd, curlev, 2);
|
||||||
flags = fgetc(rd);
|
flags = fgetc(rd);
|
||||||
|
|
||||||
|
if(flags == EOF || (prev && curlev == 0) || (!prev && curlev != 0) || curlev > level+1)
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
cur = calloc(sizeof(struct dir), 1);
|
cur = calloc(sizeof(struct dir), 1);
|
||||||
if(!prev)
|
if(!prev)
|
||||||
parent = cur;
|
parent = cur;
|
||||||
else if(curlev > level) {
|
else if(curlev > level) {
|
||||||
prev->sub = cur;
|
prev->sub = cur;
|
||||||
cur->parent = prev;
|
cur->parent = prev;
|
||||||
} else if(curlev == level) {
|
|
||||||
prev->next = cur;
|
|
||||||
cur->parent = prev->parent;
|
|
||||||
} else {
|
} else {
|
||||||
for(i=level; i>curlev; i--)
|
for(i=level; i>curlev; i--)
|
||||||
prev = prev->parent;
|
prev = prev->parent;
|
||||||
|
|
@ -227,6 +234,8 @@ struct dir *importFile(char *filename) {
|
||||||
/* name */
|
/* name */
|
||||||
for(i=0; i<8192; i++) {
|
for(i=0; i<8192; i++) {
|
||||||
ch = fgetc(rd);
|
ch = fgetc(rd);
|
||||||
|
if(ch == EOF)
|
||||||
|
return(NULL);
|
||||||
name[i] = (unsigned char) ch;
|
name[i] = (unsigned char) ch;
|
||||||
if(ch == 0)
|
if(ch == 0)
|
||||||
break;
|
break;
|
||||||
|
|
@ -247,4 +256,29 @@ struct dir *importFile(char *filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct dir *showImport(char *path) {
|
||||||
|
struct dir *ret;
|
||||||
|
|
||||||
|
nccreate(3, 60, "Importing...");
|
||||||
|
ncprint(1, 2, "Importing '%s'...", cropdir(path, 43));
|
||||||
|
refresh();
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
ret = importFile(path);
|
||||||
|
if(ret)
|
||||||
|
return(ret);
|
||||||
|
|
||||||
|
if(s_export) {
|
||||||
|
printf("Error importing '%s'\n", path);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* show an error message */
|
||||||
|
nccreate(5, 60, "Error...");
|
||||||
|
ncprint(1, 2, "Can't import '%s'", cropdir(path, 43));
|
||||||
|
ncprint(3, 3, "press any key to continue...");
|
||||||
|
getch();
|
||||||
|
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
150
src/help.c
150
src/help.c
|
|
@ -48,110 +48,104 @@ char *keys[KEYS*2] = {
|
||||||
|
|
||||||
|
|
||||||
void drawHelp(int page, int start) {
|
void drawHelp(int page, int start) {
|
||||||
WINDOW *hlp;
|
|
||||||
int i, line;
|
int i, line;
|
||||||
|
|
||||||
hlp = newwin(15, 60, winrows/2-7, wincols/2-30);
|
nccreate(15, 60, "ncdu help");
|
||||||
box(hlp, 0, 0);
|
ncaddstr(13, 38, "Press q to continue");
|
||||||
wattron(hlp, A_BOLD);
|
|
||||||
mvwaddstr(hlp, 0, 4, "ncdu help");
|
|
||||||
wattroff(hlp, A_BOLD);
|
|
||||||
mvwaddstr(hlp, 13, 38, "Press q to continue");
|
|
||||||
|
|
||||||
if(page == 1)
|
if(page == 1)
|
||||||
wattron(hlp, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(hlp, 0, 30, "1:Keys");
|
ncaddstr(0, 30, "1:Keys");
|
||||||
wattroff(hlp, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(page == 2)
|
if(page == 2)
|
||||||
wattron(hlp, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(hlp, 0, 39, "2:Format");
|
ncaddstr(0, 39, "2:Format");
|
||||||
wattroff(hlp, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
if(page == 3)
|
if(page == 3)
|
||||||
wattron(hlp, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvwaddstr(hlp, 0, 50, "3:About");
|
ncaddstr(0, 50, "3:About");
|
||||||
wattroff(hlp, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
|
|
||||||
switch(page) {
|
switch(page) {
|
||||||
case 1:
|
case 1:
|
||||||
line = 1;
|
line = 1;
|
||||||
for(i=start*2; i<start*2+20; i+=2) {
|
for(i=start*2; i<start*2+20; i+=2) {
|
||||||
wattron(hlp, A_BOLD);
|
attron(A_BOLD);
|
||||||
mvwaddstr(hlp, ++line, 13-strlen(keys[i]), keys[i]);
|
ncaddstr(++line, 13-strlen(keys[i]), keys[i]);
|
||||||
wattroff(hlp, A_BOLD);
|
attroff(A_BOLD);
|
||||||
mvwaddstr(hlp, line, 15, keys[i+1]);
|
ncaddstr(line, 15, keys[i+1]);
|
||||||
}
|
}
|
||||||
if(start != KEYS-10)
|
if(start != KEYS-10)
|
||||||
mvwaddstr(hlp, 12, 25, "-- more --");
|
ncaddstr(12, 25, "-- more --");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
wattron(hlp, A_BOLD);
|
attron(A_BOLD);
|
||||||
mvwaddstr(hlp, 2, 3, "X [size] [graph] [file or directory]");
|
ncaddstr(2, 3, "X [size] [graph] [file or directory]");
|
||||||
wattroff(hlp, A_BOLD);
|
attroff(A_BOLD);
|
||||||
mvwaddstr(hlp, 3, 4, "The X is only present in the following cases:");
|
ncaddstr(3, 4, "The X is only present in the following cases:");
|
||||||
wattron(hlp, A_BOLD);
|
attron(A_BOLD);
|
||||||
mvwaddch(hlp, 5, 4, '!');
|
ncaddch( 5, 4, '!');
|
||||||
mvwaddch(hlp, 6, 4, '.');
|
ncaddch( 6, 4, '.');
|
||||||
mvwaddch(hlp, 7, 4, '<');
|
ncaddch( 7, 4, '<');
|
||||||
mvwaddch(hlp, 8, 4, '>');
|
ncaddch( 8, 4, '>');
|
||||||
mvwaddch(hlp, 9, 4, '@');
|
ncaddch( 9, 4, '@');
|
||||||
mvwaddch(hlp,10, 4, 'e');
|
ncaddch(10, 4, 'e');
|
||||||
wattroff(hlp, A_BOLD);
|
attroff(A_BOLD);
|
||||||
mvwaddstr(hlp, 5, 7, "An error occured while reading this directory");
|
ncaddstr( 5, 7, "An error occured while reading this directory");
|
||||||
mvwaddstr(hlp, 6, 7, "An error occured while reading a subdirectory");
|
ncaddstr( 6, 7, "An error occured while reading a subdirectory");
|
||||||
mvwaddstr(hlp, 7, 7, "File or directory is excluded from the statistics");
|
ncaddstr( 7, 7, "File or directory is excluded from the statistics");
|
||||||
mvwaddstr(hlp, 8, 7, "Directory was on an other filesystem");
|
ncaddstr( 8, 7, "Directory was on an other filesystem");
|
||||||
mvwaddstr(hlp, 9, 7, "This is not a file nor a dir (symlink, socket, ...)");
|
ncaddstr( 9, 7, "This is not a file nor a dir (symlink, socket, ...)");
|
||||||
mvwaddstr(hlp,10, 7, "Empty directory");
|
ncaddstr(10, 7, "Empty directory");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
/* Indeed, too much spare time */
|
/* Indeed, too much spare time */
|
||||||
wattron(hlp, A_REVERSE);
|
attron(A_REVERSE);
|
||||||
#define x 12
|
#define x 12
|
||||||
#define y 3
|
#define y 3
|
||||||
/* N */
|
/* N */
|
||||||
mvwaddstr(hlp, y+0, x+0, " ");
|
ncaddstr(y+0, x+0, " ");
|
||||||
mvwaddstr(hlp, y+1, x+0, " ");
|
ncaddstr(y+1, x+0, " ");
|
||||||
mvwaddstr(hlp, y+2, x+0, " ");
|
ncaddstr(y+2, x+0, " ");
|
||||||
mvwaddstr(hlp, y+3, x+0, " ");
|
ncaddstr(y+3, x+0, " ");
|
||||||
mvwaddstr(hlp, y+4, x+0, " ");
|
ncaddstr(y+4, x+0, " ");
|
||||||
mvwaddstr(hlp, y+1, x+4, " ");
|
ncaddstr(y+1, x+4, " ");
|
||||||
mvwaddstr(hlp, y+2, x+4, " ");
|
ncaddstr(y+2, x+4, " ");
|
||||||
mvwaddstr(hlp, y+3, x+4, " ");
|
ncaddstr(y+3, x+4, " ");
|
||||||
mvwaddstr(hlp, y+4, x+4, " ");
|
ncaddstr(y+4, x+4, " ");
|
||||||
/* C */
|
/* C */
|
||||||
mvwaddstr(hlp, y+0, x+8, " ");
|
ncaddstr(y+0, x+8, " ");
|
||||||
mvwaddstr(hlp, y+1, x+8, " ");
|
ncaddstr(y+1, x+8, " ");
|
||||||
mvwaddstr(hlp, y+2, x+8, " ");
|
ncaddstr(y+2, x+8, " ");
|
||||||
mvwaddstr(hlp, y+3, x+8, " ");
|
ncaddstr(y+3, x+8, " ");
|
||||||
mvwaddstr(hlp, y+4, x+8, " ");
|
ncaddstr(y+4, x+8, " ");
|
||||||
/* D */
|
/* D */
|
||||||
mvwaddstr(hlp, y+0, x+19, " ");
|
ncaddstr(y+0, x+19, " ");
|
||||||
mvwaddstr(hlp, y+1, x+19, " ");
|
ncaddstr(y+1, x+19, " ");
|
||||||
mvwaddstr(hlp, y+2, x+15, " ");
|
ncaddstr(y+2, x+15, " ");
|
||||||
mvwaddstr(hlp, y+3, x+15, " ");
|
ncaddstr(y+3, x+15, " ");
|
||||||
mvwaddstr(hlp, y+3, x+19, " ");
|
ncaddstr(y+3, x+19, " ");
|
||||||
mvwaddstr(hlp, y+4, x+15, " ");
|
ncaddstr(y+4, x+15, " ");
|
||||||
/* U */
|
/* U */
|
||||||
mvwaddstr(hlp, y+0, x+23, " ");
|
ncaddstr(y+0, x+23, " ");
|
||||||
mvwaddstr(hlp, y+1, x+23, " ");
|
ncaddstr(y+1, x+23, " ");
|
||||||
mvwaddstr(hlp, y+2, x+23, " ");
|
ncaddstr(y+2, x+23, " ");
|
||||||
mvwaddstr(hlp, y+3, x+23, " ");
|
ncaddstr(y+3, x+23, " ");
|
||||||
mvwaddstr(hlp, y+0, x+27, " ");
|
ncaddstr(y+0, x+27, " ");
|
||||||
mvwaddstr(hlp, y+1, x+27, " ");
|
ncaddstr(y+1, x+27, " ");
|
||||||
mvwaddstr(hlp, y+2, x+27, " ");
|
ncaddstr(y+2, x+27, " ");
|
||||||
mvwaddstr(hlp, y+3, x+27, " ");
|
ncaddstr(y+3, x+27, " ");
|
||||||
mvwaddstr(hlp, y+4, x+23, " ");
|
ncaddstr(y+4, x+23, " ");
|
||||||
wattroff(hlp, A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
mvwaddstr(hlp, y+0, x+30, "NCurses");
|
ncaddstr(y+0, x+30, "NCurses");
|
||||||
mvwaddstr(hlp, y+1, x+30, "Disk");
|
ncaddstr(y+1, x+30, "Disk");
|
||||||
mvwaddstr(hlp, y+2, x+30, "Usage");
|
ncaddstr(y+2, x+30, "Usage");
|
||||||
mvwprintw(hlp, y+4, x+30, "%s", PACKAGE_VERSION);
|
ncprint( y+4, x+30, "%s", PACKAGE_VERSION);
|
||||||
mvwaddstr(hlp, 9, 7, "Written by Yoran Heling <projects@yorhel.nl>");
|
ncaddstr( 9, 7, "Written by Yoran Heling <projects@yorhel.nl>");
|
||||||
mvwaddstr(hlp,10, 16, "http://dev.yorhel.nl/ncdu/");
|
ncaddstr(10, 16, "http://dev.yorhel.nl/ncdu/");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wrefresh(hlp);
|
refresh();
|
||||||
delwin(hlp); /* no need to use it anymore - free it */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ struct dir *dat;
|
||||||
int winrows, wincols;
|
int winrows, wincols;
|
||||||
char sdir[PATH_MAX], *s_export;
|
char sdir[PATH_MAX], *s_export;
|
||||||
int sflags, bflags, sdelay, bgraph;
|
int sflags, bflags, sdelay, bgraph;
|
||||||
|
int subwinc, subwinr;
|
||||||
|
|
||||||
|
|
||||||
/* parse command line */
|
/* parse command line */
|
||||||
|
|
@ -110,7 +111,7 @@ struct dir *loadDir(char *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(S_ISREG(st.st_mode))
|
if(S_ISREG(st.st_mode))
|
||||||
return(importFile(path));
|
return(showImport(path));
|
||||||
else
|
else
|
||||||
return(showCalc(path));
|
return(showCalc(path));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/ncdu.h
10
src/ncdu.h
|
|
@ -29,6 +29,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
@ -81,6 +82,9 @@
|
||||||
static unsigned int endian_test = 1;
|
static unsigned int endian_test = 1;
|
||||||
#define IS_BIG_ENDIAN (!(*(char *) &endian_test))
|
#define IS_BIG_ENDIAN (!(*(char *) &endian_test))
|
||||||
|
|
||||||
|
/* check nccreate in util.c for more info on these defines */
|
||||||
|
#define ncaddstr(r, c, s) mvaddstr(subwinr+(r), subwinc+(c), s)
|
||||||
|
#define ncaddch(r, c, s) mvaddch(subwinr+(r), subwinc+(c), s)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -145,6 +149,8 @@ extern int winrows, wincols;
|
||||||
/* global settings */
|
/* global settings */
|
||||||
extern char sdir[PATH_MAX], *s_export;
|
extern char sdir[PATH_MAX], *s_export;
|
||||||
extern int sflags, bflags, sdelay, bgraph;
|
extern int sflags, bflags, sdelay, bgraph;
|
||||||
|
/* used for creating windows */
|
||||||
|
extern int subwinr, subwinc;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -155,6 +161,8 @@ extern char *cropdir(const char *, int);
|
||||||
extern char *cropsize(const off_t);
|
extern char *cropsize(const off_t);
|
||||||
extern char *fullsize(const off_t);
|
extern char *fullsize(const off_t);
|
||||||
extern void ncresize(void);
|
extern void ncresize(void);
|
||||||
|
extern void nccreate(int, int, char *);
|
||||||
|
extern void ncprint(int, int, char *, ...);
|
||||||
extern struct dir * freedir(struct dir *);
|
extern struct dir * freedir(struct dir *);
|
||||||
extern char *getpath(struct dir *, char *);
|
extern char *getpath(struct dir *, char *);
|
||||||
/* settings.c */
|
/* settings.c */
|
||||||
|
|
@ -174,4 +182,4 @@ extern int addExcludeFile(char *);
|
||||||
extern int matchExclude(char *);
|
extern int matchExclude(char *);
|
||||||
/* export.c */
|
/* export.c */
|
||||||
extern void exportFile(char *, struct dir *);
|
extern void exportFile(char *, struct dir *);
|
||||||
extern struct dir *importFile(char *);
|
extern struct dir *showImport(char *);
|
||||||
|
|
|
||||||
83
src/util.c
83
src/util.c
|
|
@ -73,18 +73,26 @@ char *cropsize(const off_t from) {
|
||||||
BUG: Uses a dot as seperator, ignores current locale */
|
BUG: Uses a dot as seperator, ignores current locale */
|
||||||
char *fullsize(const off_t from) {
|
char *fullsize(const off_t from) {
|
||||||
char tmp[20];
|
char tmp[20];
|
||||||
int i, j, len;
|
off_t n = from;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
sprintf(tmp, "%lld", from);
|
/* the K&R method - more portable than sprintf with %lld */
|
||||||
|
i = 0;
|
||||||
fullsizedat[19] = '\0';
|
do {
|
||||||
len = strlen(tmp);
|
tmp[i++] = n % 10 + '0';
|
||||||
for(i=len, j=18; i >= 0; i--) {
|
} while((n /= 10) > 0);
|
||||||
if(len-i != 1 && (len-i-1) % 3 == 0)
|
tmp[i] = '\0';
|
||||||
fullsizedat[j--] = '.';
|
|
||||||
fullsizedat[j--] = tmp[i];
|
/* reverse and add thousand seperators */
|
||||||
|
j = 0;
|
||||||
|
while(i--) {
|
||||||
|
fullsizedat[j++] = tmp[i];
|
||||||
|
if(i != 0 && i%3 == 0)
|
||||||
|
fullsizedat[j++] = '.';
|
||||||
}
|
}
|
||||||
return fullsizedat+j+1;
|
fullsizedat[j] = '\0';
|
||||||
|
|
||||||
|
return(fullsizedat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,6 +122,61 @@ void ncresize(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Instead of using several ncurses windows, we only draw to stdscr.
|
||||||
|
* the functions nccreate, ncprint and the macros ncaddstr and ncaddch
|
||||||
|
* mimic the behaviour of ncurses windows.
|
||||||
|
* This works better than using ncurses windows when all windows are
|
||||||
|
* created in the correct order: it paints directly on stdscr, so
|
||||||
|
* wrefresh, wnoutrefresh and other window-specific functions are not
|
||||||
|
* necessary.
|
||||||
|
* Also, this method doesn't require any window objects, as you can
|
||||||
|
* only create one window at a time.
|
||||||
|
*
|
||||||
|
* This function creates a new window in the center of the screen
|
||||||
|
* with a border and a title.
|
||||||
|
*/
|
||||||
|
void nccreate(int height, int width, char *title) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
subwinr = winrows/2-height/2;
|
||||||
|
subwinc = wincols/2-width/2;
|
||||||
|
|
||||||
|
/* clear window */
|
||||||
|
for(i=0; i<height; i++)
|
||||||
|
mvhline(subwinr+i, subwinc, ' ', width);
|
||||||
|
|
||||||
|
/* box() only works around curses windows, so create our own */
|
||||||
|
move(subwinr, subwinc);
|
||||||
|
addch(ACS_ULCORNER);
|
||||||
|
for(i=0; i<width-2; i++)
|
||||||
|
addch(ACS_HLINE);
|
||||||
|
addch(ACS_URCORNER);
|
||||||
|
|
||||||
|
move(subwinr+height-1, subwinc);
|
||||||
|
addch(ACS_LLCORNER);
|
||||||
|
for(i=0; i<width-2; i++)
|
||||||
|
addch(ACS_HLINE);
|
||||||
|
addch(ACS_LRCORNER);
|
||||||
|
|
||||||
|
mvvline(subwinr+1, subwinc, ACS_VLINE, height-2);
|
||||||
|
mvvline(subwinr+1, subwinc+width-1, ACS_VLINE, height-2);
|
||||||
|
|
||||||
|
/* title */
|
||||||
|
attron(A_BOLD);
|
||||||
|
mvaddstr(subwinr, subwinc+4, title);
|
||||||
|
attroff(A_BOLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ncprint(int r, int c, char *fmt, ...) {
|
||||||
|
va_list arg;
|
||||||
|
va_start(arg, fmt);
|
||||||
|
move(subwinr+r, subwinc+c);
|
||||||
|
vw_printw(stdscr, fmt, arg);
|
||||||
|
va_end(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void freedir_rec(struct dir *dr) {
|
void freedir_rec(struct dir *dr) {
|
||||||
struct dir *tmp, *tmp2;
|
struct dir *tmp, *tmp2;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue