1
1

* Added 'a'-key to toggle between showing apparent size and disk usage

* Added 'i'-key to show a small window containing info on the selected item
* Cleaned up file flags and browse flags


git-svn-id: svn://blicky.net/ncdu/trunk@19 ce56bc8d-f834-0410-b703-f827bd498a76
Этот коммит содержится в:
yorhel 2007-08-01 15:01:42 +00:00
родитель fa0aa6b53b
Коммит 2a9b34ce2d
3 изменённых файлов: 84 добавлений и 17 удалений

Просмотреть файл

@ -28,6 +28,35 @@
struct dir *bcur;
void drawInfo(struct dir *dr) {
WINDOW *nfo;
char path[PATH_MAX];
nfo = newwin(11, 60, winrows/2-5, wincols/2-30);
box(nfo, 0, 0);
wattron(nfo, A_BOLD);
mvwaddstr(nfo, 0, 4, "Item info");
mvwaddstr(nfo, 2, 3, "Name:");
mvwaddstr(nfo, 3, 3, "Path:");
mvwaddstr(nfo, 4, 3, "Type:");
mvwaddstr(nfo, 6, 3, " Disk usage:");
mvwaddstr(nfo, 7, 3, "Apparent size:");
wattroff(nfo, A_BOLD);
mvwaddstr(nfo, 2, 9, cropdir(dr->name, 49));
mvwaddstr(nfo, 3, 9, cropdir(getpath(dr, path), 49));
mvwaddstr(nfo, 4, 9, dr->flags & FF_DIR ? "Directory"
: dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
mvwprintw(nfo, 6, 18, "%s (%s B)", cropsize(dr->size), fullsize(dr->size));
mvwprintw(nfo, 7, 18, "%s (%s B)", cropsize(dr->asize), fullsize(dr->asize));
mvwaddstr(nfo, 9, 32, "Press any key to continue");
wrefresh(nfo);
delwin(nfo);
}
int cmp(struct dir *x, struct dir *y) {
struct dir *a, *b;
int r = 0;
@ -51,6 +80,8 @@ int cmp(struct dir *x, struct dir *y) {
r = strcmp(a->name, b->name);
if(r == 0)
r = a->size > b->size ? 1 : (a->size == b->size ? 0 : -1);
if(r == 0)
r = a->asize > b->asize ? 1 : (a->asize == b->asize ? 0 : -1);
if(r == 0)
r = strcmp(x->name, y->name);
return(r);
@ -120,7 +151,7 @@ char *graph(off_t max, off_t size) {
void drawBrowser(int change) {
struct dir *n;
char tmp[PATH_MAX], ct, dt;
char tmp[PATH_MAX], ct, dt, *size;
int selected, i, o;
off_t max = 1;
@ -233,28 +264,29 @@ void drawBrowser(int change) {
&& n->sub == NULL ? 'e' :
' ' ;
dt = n->flags & FF_DIR ? '/' : ' ';
size = cropsize(bflags & BF_AS ? n->asize : n->size);
/* format and add item to the list */
switch(bgraph) {
case 0:
mvprintw(i+2, 0, tmp, ct, cropsize(n->size),
mvprintw(i+2, 0, tmp, ct, size,
dt, cropdir(n->name, wincols-12)
);
break;
case 1:
mvprintw(i+2, 0, tmp, ct, cropsize(n->size),
mvprintw(i+2, 0, tmp, ct, size,
graph(max, n->size),
dt, cropdir(n->name, wincols-24)
);
break;
case 2:
mvprintw(i+2, 0, tmp, ct, cropsize(n->size),
mvprintw(i+2, 0, tmp, ct, size,
((float) n->size / (float) n->parent->size) * 100.0f,
dt, cropdir(n->name, wincols-19)
);
break;
case 3:
mvprintw(i+2, 0, tmp, ct, cropsize(n->size),
mvprintw(i+2, 0, tmp, ct, size,
((float) n->size / (float) n->parent->size) * 100.0f, graph(max, n->size),
dt, cropdir(n->name, wincols-30)
);
@ -340,6 +372,9 @@ void showBrowser(void) {
case 't':
toggle(bflags, BF_NDIRF);
break;
case 'a':
toggle(bflags, BF_AS);
break;
/* browsing */
case 10:
@ -408,6 +443,16 @@ void showBrowser(void) {
case '?':
showHelp();
break;
case 'i':
n = selected();
if(!(n->flags & FF_PAR)) {
drawInfo(n);
while(getch() == KEY_RESIZE) {
drawBrowser(0);
drawInfo(n);
}
}
break;
case 'd':
n = selected();
if(!(n->flags & FF_PAR))
@ -418,7 +463,7 @@ void showBrowser(void) {
case 'q':
goto endloop;
}
if((last != bcur || (oldflags | BF_HIDE) != (bflags | BF_HIDE)) && bflags & BF_SORT)
if((last != bcur || (oldflags | BF_HIDE | BF_AS) != (bflags | BF_HIDE | BF_AS)) && bflags & BF_SORT)
bflags -= BF_SORT;
drawBrowser(change);

Просмотреть файл

@ -90,19 +90,20 @@
#define FF_PAR 0x80 /* reference to parent directory (hack) */
/* Settings Flags (int sflags) */
#define SF_SMFS 1 /* same filesystem */
#define SF_SI 4 /* use powers of 1000 instead of 1024 */
#define SF_IGNS 8 /* ignore too small terminal sizes */
#define SF_NOCFM 16 /* don't confirm file deletion */
#define SF_IGNE 32 /* ignore errors when deleting */
#define SF_SMFS 0x01 /* same filesystem */
#define SF_SI 0x02 /* use powers of 1000 instead of 1024 */
#define SF_IGNS 0x04 /* ignore too small terminal sizes */
#define SF_NOCFM 0x08 /* don't confirm file deletion */
#define SF_IGNE 0x10 /* ignore errors when deleting */
/* Browse Flags (int bflags) */
#define BF_NAME 1
#define BF_SIZE 2
#define BF_NDIRF 32 /* Normally, dirs before files, setting this disables it */
#define BF_DESC 64
#define BF_HIDE 128 /* don't show hidden files... */
#define BF_SORT 256 /* no need to resort, list is already in correct order */
#define BF_NAME 0x01
#define BF_SIZE 0x02
#define BF_NDIRF 0x04 /* Normally, dirs before files, setting this disables it */
#define BF_DESC 0x08
#define BF_HIDE 0x10 /* don't show hidden files... */
#define BF_SORT 0x20 /* no need to resort, list is already in correct order */
#define BF_AS 0x40 /* show apparent sizes instead of disk usage */
/*
@ -137,6 +138,7 @@ extern int sflags, bflags, sdelay, bgraph;
/* util.c */
extern char *cropdir(const char *, int);
extern char *cropsize(const off_t);
extern char *fullsize(const off_t);
extern void ncresize(void);
extern struct dir * freedir(struct dir *);
extern char *getpath(struct dir *, char *);

Просмотреть файл

@ -26,6 +26,7 @@
#include "ncdu.h"
char cropsizedat[8];
char fullsizedat[20]; /* max: 999.999.999.999.999 */
char cropdirdat[4096];
char *cropdir(const char *from, int s) {
@ -68,6 +69,25 @@ char *cropsize(const off_t from) {
return(cropsizedat);
}
/* returns integer as a string with thousand seperators
BUG: Uses a dot as seperator, ignores current locale */
char *fullsize(const off_t from) {
char tmp[20];
int i, j, len;
sprintf(tmp, "%lld", from);
fullsizedat[19] = '\0';
len = strlen(tmp);
for(i=len, j=18; i >= 0; i--) {
if(len-i != 1 && (len-i-1) % 3 == 0)
fullsizedat[j--] = '.';
fullsizedat[j--] = tmp[i];
}
return fullsizedat+j+1;
}
void ncresize(void) {
int ch;
getmaxyx(stdscr, winrows, wincols);