mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Decided to get rid of that startup window...
git-svn-id: svn://blicky.net/ncdu/trunk@40 ce56bc8d-f834-0410-b703-f827bd498a76
This commit is contained in:
parent
02a94d79e8
commit
04b7032846
8 changed files with 13 additions and 234 deletions
|
|
@ -1,4 +1,5 @@
|
|||
svn - ?
|
||||
- Removed the startup window
|
||||
- Filenames ending with a tidle (~) will now also
|
||||
be hidden with the 'h'-key
|
||||
- Fixed buffer overflow when supplying a path longer
|
||||
|
|
|
|||
7
TODO
7
TODO
|
|
@ -1,13 +1,6 @@
|
|||
Small list of planned features/changes, suggestions are always welcome.
|
||||
|
||||
|
||||
- Improve configuration interface (settings.c)
|
||||
* All command line options should be accessible in the GUI
|
||||
* Tabs?
|
||||
* Still use the ncurses forms library, or implement our own?
|
||||
(hopefully less buggy and more control)
|
||||
- Or just remove the startup screen altogether?
|
||||
|
||||
- Add export/import feature for filelists
|
||||
* Also comparing two filelists
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ AC_PROG_RANLIB
|
|||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB(ncurses, initscr)
|
||||
AC_CHECK_LIB(form, new_form)
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([limits.h stdlib.h string.h sys/time.h unistd.h fnmatch.h ncurses.h form.h])
|
||||
AC_CHECK_HEADERS([limits.h stdlib.h string.h sys/time.h unistd.h fnmatch.h ncurses.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
|
|
|
|||
24
doc/ncdu.1
24
doc/ncdu.1
|
|
@ -1,11 +1,10 @@
|
|||
." Text automatically generated by txt2man
|
||||
.TH NCDU 1 "July 21, 2007" "ncdu-svn" "ncdu manual"
|
||||
.TH NCDU 1 "September 10, 2008" "ncdu-svn" "ncdu manual"
|
||||
.SH NAME
|
||||
\fBncdu \fP- NCurses Disk Usage
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.fam C
|
||||
\fBncdu\fP [\fB-hqvx\fP] [\fIdir\fP]
|
||||
\fBncdu\fP [\fB-hqvx\fP] [\fB--exclude PATTERN\fP] [\fB-X FILE\fP] \fIdir\fP
|
||||
.fam T
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
|
|
@ -13,10 +12,6 @@
|
|||
the well-known 'du', and provides a fast way to see what
|
||||
directories are using your disk space.
|
||||
.PP
|
||||
If \fIdir\fP is specified, \fBncdu\fP will automatically start
|
||||
calculating the disk size. Otherwise, you will be prompted
|
||||
with a small configuration window.
|
||||
.PP
|
||||
For a more detailed explanation of \fBncdu\fP, please check
|
||||
http://dev.yorhel.nl/ncdu/
|
||||
.SH OPTIONS
|
||||
|
|
@ -46,21 +41,6 @@ be added multiple times to add more patterns.
|
|||
Exclude files that match any pattern in FILE. Patterns
|
||||
should be seperated by a newline.
|
||||
.SH KEYS
|
||||
.SS SETTINGS WINDOW
|
||||
.TP
|
||||
.B
|
||||
up/down/tab
|
||||
Cycle through the form fields.
|
||||
.TP
|
||||
.B
|
||||
Enter
|
||||
Post form
|
||||
.SS CALCULATING WINDOW
|
||||
.TP
|
||||
.B
|
||||
q
|
||||
Quit
|
||||
.SS BROWSER
|
||||
.TP
|
||||
.B
|
||||
?
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
bin_PROGRAMS = ncdu
|
||||
|
||||
ncdu_SOURCES = browser.c calc.c main.c settings.c util.c exclude.c help.c delete.c
|
||||
ncdu_SOURCES = browser.c calc.c main.c util.c exclude.c help.c delete.c
|
||||
|
||||
noinst_HEADERS = ncdu.h
|
||||
|
|
|
|||
28
src/main.c
28
src/main.c
|
|
@ -70,7 +70,7 @@ void parseCli(int argc, char **argv) {
|
|||
case 'q': sdelay = 2000; break;
|
||||
case '?':
|
||||
case 'h':
|
||||
printf("ncdu [-hqvx] [--exclude PATTERN] [-X FILE] [dir]\n\n");
|
||||
printf("ncdu [-hqvx] [--exclude PATTERN] [-X FILE] directory\n\n");
|
||||
printf(" -h This help message\n");
|
||||
printf(" -q Quiet mode, refresh interval 2 seconds\n");
|
||||
printf(" -v Print version\n");
|
||||
|
|
@ -82,7 +82,7 @@ void parseCli(int argc, char **argv) {
|
|||
printf("ncdu %s\n", PACKAGE_VERSION);
|
||||
exit(0);
|
||||
default:
|
||||
printf("Unknown option: -%c\n", argv[i][j]);
|
||||
printf("Unknown option: -%c\nSee '%s -h' for more information.\n", argv[i][j], argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -92,15 +92,10 @@ void parseCli(int argc, char **argv) {
|
|||
sdir[0] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct dir *loadDir(char *path) {
|
||||
struct stat st;
|
||||
|
||||
if(stat(path, &st) < 0)
|
||||
return(showCalc(path));
|
||||
return(showCalc(path));
|
||||
if(!sdir[0]) {
|
||||
printf("Please specify a directory.\nSee '%s -h' for more information.\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -117,16 +112,9 @@ int main(int argc, char **argv) {
|
|||
keypad(stdscr, TRUE);
|
||||
ncresize();
|
||||
|
||||
if(!sdir[0] && settingsWin())
|
||||
goto mainend;
|
||||
if((dat = showCalc(sdir)) != NULL)
|
||||
showBrowser();
|
||||
|
||||
while((dat = loadDir(sdir)) == NULL)
|
||||
if(settingsWin())
|
||||
goto mainend;
|
||||
|
||||
showBrowser();
|
||||
|
||||
mainend:
|
||||
erase();
|
||||
refresh();
|
||||
endwin();
|
||||
|
|
|
|||
|
|
@ -157,8 +157,6 @@ extern void nccreate(int, int, char *);
|
|||
extern void ncprint(int, int, char *, ...);
|
||||
extern struct dir * freedir(struct dir *);
|
||||
extern char *getpath(struct dir *, char *);
|
||||
/* settings.c */
|
||||
extern int settingsWin(void);
|
||||
/* calc.c */
|
||||
extern struct dir *showCalc(char *);
|
||||
/* browser.c */
|
||||
|
|
|
|||
180
src/settings.c
180
src/settings.c
|
|
@ -1,180 +0,0 @@
|
|||
/* ncdu - NCurses Disk Usage
|
||||
|
||||
Copyright (c) 2007-2008 Yoran Heling
|
||||
|
||||
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"
|
||||
|
||||
|
||||
int settingsGet(void) {
|
||||
WINDOW *set;
|
||||
FORM *setf;
|
||||
FIELD *fields[11];
|
||||
int w, h, cx, cy, i, j, ch;
|
||||
int fw, fh, fy, fx, fnrow, fnbuf;
|
||||
char tmp[10], *buf = "", rst = 0;
|
||||
|
||||
if(!sdir[0])
|
||||
getcwd(sdir, PATH_MAX);
|
||||
|
||||
erase();
|
||||
refresh();
|
||||
/* h, w, y, x */
|
||||
fields[0] = new_field(1, 10, 0, 0, 0, 0);
|
||||
fields[1] = new_field(1, 43, 0, 11, 0, 0);
|
||||
fields[2] = new_field(1, 16, 1, 11, 0, 0);
|
||||
fields[3] = new_field(1, 1, 1, 27, 0, 0);
|
||||
fields[4] = new_field(1, 1, 1, 28, 0, 0);
|
||||
fields[5] = new_field(1, 6, 3, 11, 0, 0);
|
||||
fields[6] = new_field(1, 9, 3, 19, 0, 0);
|
||||
fields[7] = NULL;
|
||||
|
||||
/* Directory */
|
||||
field_opts_off(fields[0], O_ACTIVE);
|
||||
set_field_buffer(fields[0], 0, "Directory:");
|
||||
set_field_back(fields[1], A_UNDERLINE);
|
||||
field_opts_off(fields[1], O_STATIC);
|
||||
field_opts_off(fields[1], O_AUTOSKIP);
|
||||
set_max_field(fields[1], PATH_MAX);
|
||||
set_field_buffer(fields[1], 0, sdir);
|
||||
/* One filesystem */
|
||||
field_opts_off(fields[2], O_ACTIVE);
|
||||
set_field_buffer(fields[2], 0, "One filesystem [");
|
||||
field_opts_off(fields[3], O_AUTOSKIP);
|
||||
set_field_back(fields[3], A_UNDERLINE);
|
||||
set_field_buffer(fields[3], 0, sflags & SF_SMFS ? "X" : " ");
|
||||
field_opts_off(fields[4], O_ACTIVE);
|
||||
set_field_buffer(fields[4], 0, "]");
|
||||
/* buttons */
|
||||
set_field_buffer(fields[5], 0, "[OK]");
|
||||
set_field_buffer(fields[6], 0, "[CLOSE]");
|
||||
|
||||
setf = new_form(fields);
|
||||
h=8;w=60;
|
||||
|
||||
set = newwin(h, w, winrows/2 - h/2, wincols/2 - w/2);
|
||||
keypad(stdscr, TRUE);
|
||||
keypad(set, TRUE);
|
||||
box(set, 0, 0);
|
||||
curs_set(1);
|
||||
|
||||
set_form_win(setf, set);
|
||||
set_form_sub(setf, derwin(set, h-3, w-4, 2, 2));
|
||||
|
||||
wattron(set, A_BOLD);
|
||||
mvwaddstr(set, 0, 4, "Calculate disk space usage...");
|
||||
wattroff(set, A_BOLD);
|
||||
post_form(setf);
|
||||
refresh();
|
||||
wrefresh(set);
|
||||
|
||||
while((ch = wgetch(set))) {
|
||||
getyx(set, cy, cx);
|
||||
cy-=2; cx-=2;
|
||||
for(i=field_count(setf); --i>=0; ) {
|
||||
field_info(fields[i], &fh, &fw, &fy, &fx, &fnrow, &fnbuf);
|
||||
if(cy >= fy && cy < fy+fh && cx >= fx && cx < fx+fw) {
|
||||
buf = field_buffer(fields[i], 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch(ch) {
|
||||
case KEY_BACKSPACE:
|
||||
case 127: form_driver(setf, REQ_DEL_PREV); break;
|
||||
case KEY_LL:
|
||||
case KEY_END: form_driver(setf, REQ_END_LINE); break;
|
||||
case KEY_HOME: form_driver(setf, REQ_BEG_LINE); break;
|
||||
case KEY_LEFT: form_driver(setf, REQ_LEFT_CHAR); break;
|
||||
case KEY_RIGHT:
|
||||
if(i == 1) {
|
||||
for(j=strlen(buf);--j>i;)
|
||||
if(buf[j] != ' ')
|
||||
break;
|
||||
if(j < fw && cx > fx+j)
|
||||
break;
|
||||
}
|
||||
form_driver(setf, REQ_RIGHT_CHAR);
|
||||
break;
|
||||
case KEY_DC: form_driver(setf, REQ_DEL_CHAR); break;
|
||||
case KEY_DOWN: form_driver(setf, REQ_NEXT_FIELD); break;
|
||||
case KEY_UP: form_driver(setf, REQ_PREV_FIELD); break;
|
||||
case '\t': form_driver(setf, REQ_NEXT_FIELD); break;
|
||||
case KEY_RESIZE: rst = 1; goto setend; break;
|
||||
default:
|
||||
if(i == 6) {
|
||||
rst = 2;
|
||||
goto setend;
|
||||
}
|
||||
if(i == 5 || ch == '\n')
|
||||
goto setend;
|
||||
if(i == 3)
|
||||
set_field_buffer(fields[i], 0, buf[0] == ' ' ? "X" : " ");
|
||||
else if(!isprint(ch)) break;
|
||||
else if(i == 6) {
|
||||
if(!isdigit(ch)) strcpy(tmp, " 0");
|
||||
else if(buf[0] != ' ' || buf[1] == ' ' || buf[1] == '0') sprintf(tmp, " %c", ch);
|
||||
else sprintf(tmp, "%c%c", buf[1], ch);
|
||||
set_field_buffer(fields[i], 0, tmp);
|
||||
} else
|
||||
form_driver(setf, ch);
|
||||
break;
|
||||
}
|
||||
wrefresh(set);
|
||||
}
|
||||
setend:
|
||||
/* !!!WARNING!!! ugly hack !!!WARNING!!! */
|
||||
set_current_field(setf, fields[1]);
|
||||
form_driver(setf, REQ_END_LINE);
|
||||
for(i=0; i<40; i++)
|
||||
form_driver(setf, ' ');
|
||||
dynamic_field_info(fields[1], &fh, &fw, &fx);
|
||||
memcpy(sdir, field_buffer(fields[1], 0), fw);
|
||||
for(i=strlen(sdir); --i>=0;)
|
||||
if(sdir[i] != ' ' && (sdir[i] != '/' || i == 0)) {
|
||||
sdir[i+1] = 0;
|
||||
break;
|
||||
}
|
||||
/* EOW */
|
||||
sflags = sflags & SF_IGNS;
|
||||
buf = field_buffer(fields[3], 0);
|
||||
if(buf[0] != ' ') sflags |= SF_SMFS;
|
||||
|
||||
unpost_form(setf);
|
||||
for(i=7;--i>=0;)
|
||||
free_field(fields[i]);
|
||||
werase(set);
|
||||
delwin(set);
|
||||
erase();
|
||||
refresh();
|
||||
curs_set(0);
|
||||
return(rst);
|
||||
}
|
||||
|
||||
int settingsWin(void) {
|
||||
int r;
|
||||
while((r = settingsGet()) == 1) {
|
||||
ncresize();
|
||||
return(settingsWin());
|
||||
}
|
||||
return(r);
|
||||
}
|
||||
Loading…
Reference in a new issue