Centralized screen update delay into input_handle()
Этот коммит содержится в:
родитель
8ddec92724
Коммит
ba243df042
@ -222,7 +222,7 @@ void browse_draw_item(struct dir *n, int row, off_t max, int ispar) {
|
||||
}
|
||||
|
||||
|
||||
int browse_draw() {
|
||||
void browse_draw() {
|
||||
struct dir *n, ref, *cur, *sel = NULL;
|
||||
char tmp[PATH_MAX], *tmp2;
|
||||
int selected, i;
|
||||
@ -254,7 +254,7 @@ int browse_draw() {
|
||||
}
|
||||
|
||||
if(!cur)
|
||||
return 0;
|
||||
return;
|
||||
|
||||
/* add reference to parent dir */
|
||||
memset(&ref, 0, sizeof(struct dir));
|
||||
@ -302,7 +302,6 @@ int browse_draw() {
|
||||
|
||||
/* move cursor to selected row for accessibility */
|
||||
move(selected+2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "ncdu.h"
|
||||
|
||||
int browse_key(int);
|
||||
int browse_draw(void);
|
||||
void browse_draw(void);
|
||||
void browse_init(struct dir *);
|
||||
|
||||
|
||||
|
27
src/calc.c
27
src/calc.c
@ -37,7 +37,6 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
@ -48,7 +47,6 @@
|
||||
|
||||
|
||||
/* external vars */
|
||||
int calc_delay = 100;
|
||||
char calc_smfs = 0;
|
||||
|
||||
/* global vars for internal use */
|
||||
@ -59,7 +57,6 @@ char errmsg[128]; /* error message, when failed=1 */
|
||||
struct dir *root; /* root directory struct we're calculating */
|
||||
struct dir *orig; /* original directory, when recalculating */
|
||||
dev_t curdev; /* current device we're calculating on */
|
||||
long lastupdate; /* time of the last screen update */
|
||||
int anpos; /* position of the animation string */
|
||||
int curpathl = 0, lasterrl = 0;
|
||||
|
||||
@ -246,7 +243,7 @@ void calc_draw_progress() {
|
||||
}
|
||||
|
||||
/* animation - but only if the screen refreshes more than or once every second */
|
||||
if(calc_delay <= 1000) {
|
||||
if(update_delay <= 1000) {
|
||||
if(++anpos == 28)
|
||||
anpos = 0;
|
||||
strcpy(ani, " ");
|
||||
@ -275,25 +272,12 @@ void calc_draw_error(char *cur, char *msg) {
|
||||
}
|
||||
|
||||
|
||||
int calc_draw() {
|
||||
struct timeval tv;
|
||||
|
||||
if(failed) {
|
||||
browse_draw();
|
||||
void calc_draw() {
|
||||
browse_draw();
|
||||
if(failed)
|
||||
calc_draw_error(curpath, errmsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* should we really draw the screen again? */
|
||||
gettimeofday(&tv, (void *)NULL);
|
||||
tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / calc_delay;
|
||||
if(lastupdate != tv.tv_usec) {
|
||||
browse_draw();
|
||||
else
|
||||
calc_draw_progress();
|
||||
lastupdate = tv.tv_usec;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -408,7 +392,6 @@ calc_fail:
|
||||
|
||||
void calc_init(char *dir, struct dir *org) {
|
||||
failed = anpos = 0;
|
||||
lastupdate = 999;
|
||||
orig = org;
|
||||
if(curpathl == 0) {
|
||||
curpathl = strlen(dir);
|
||||
|
@ -28,12 +28,11 @@
|
||||
|
||||
#include "ncdu.h"
|
||||
|
||||
extern int calc_delay; /* minimum screen update interval when calculating, in ms */
|
||||
extern char calc_smfs; /* stay on the same filesystem */
|
||||
|
||||
void calc_process(void);
|
||||
int calc_key(int);
|
||||
int calc_draw(void);
|
||||
void calc_draw(void);
|
||||
void calc_init(char *, struct dir *);
|
||||
|
||||
|
||||
|
32
src/delete.c
32
src/delete.c
@ -32,7 +32,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
#define DS_CONFIRM 0
|
||||
@ -40,9 +39,6 @@
|
||||
#define DS_FAILED 2
|
||||
|
||||
|
||||
int delete_delay = 100;
|
||||
|
||||
long lastupdate;
|
||||
struct dir *root, *nextsel, *curdir;
|
||||
char noconfirm = 0,
|
||||
ignoreerr = 0,
|
||||
@ -104,30 +100,13 @@ void delete_draw_error() {
|
||||
}
|
||||
|
||||
|
||||
int delete_draw() {
|
||||
struct timeval tv;
|
||||
|
||||
void delete_draw() {
|
||||
browse_draw();
|
||||
switch(state) {
|
||||
case DS_CONFIRM:
|
||||
browse_draw();
|
||||
delete_draw_confirm();
|
||||
return 0;
|
||||
case DS_PROGRESS:
|
||||
gettimeofday(&tv, (void *)NULL);
|
||||
tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / delete_delay;
|
||||
if(lastupdate != tv.tv_usec) {
|
||||
browse_draw();
|
||||
delete_draw_progress();
|
||||
lastupdate = tv.tv_usec;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
case DS_FAILED:
|
||||
browse_draw();
|
||||
delete_draw_error();
|
||||
return 0;
|
||||
case DS_CONFIRM: delete_draw_confirm(); break;
|
||||
case DS_PROGRESS: delete_draw_progress(); break;
|
||||
case DS_FAILED: delete_draw_error(); break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -239,7 +218,6 @@ void delete_process() {
|
||||
return browse_init(root);
|
||||
|
||||
/* delete */
|
||||
lastupdate = 999;
|
||||
seloption = 0;
|
||||
if(delete_dir(root))
|
||||
browse_init(root);
|
||||
|
@ -28,11 +28,9 @@
|
||||
|
||||
#include "ncdu.h"
|
||||
|
||||
extern int delete_delay;
|
||||
|
||||
void delete_process(void);
|
||||
int delete_key(int);
|
||||
int delete_draw(void);
|
||||
void delete_draw(void);
|
||||
void delete_init(struct dir *, struct dir *);
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ char *keys[KEYS*2] = {
|
||||
};
|
||||
|
||||
|
||||
int help_draw() {
|
||||
void help_draw() {
|
||||
int i, line;
|
||||
|
||||
browse_draw();
|
||||
@ -155,7 +155,6 @@ int help_draw() {
|
||||
ncaddstr(10, 16, "http://dev.yorhel.nl/ncdu/");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "ncdu.h"
|
||||
|
||||
int help_key(int);
|
||||
int help_draw(void);
|
||||
void help_draw(void);
|
||||
void help_init();
|
||||
|
||||
|
||||
|
36
src/main.c
36
src/main.c
@ -37,30 +37,46 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int pstate;
|
||||
|
||||
int min_rows = 17,
|
||||
min_cols = 60;
|
||||
long update_delay = 100,
|
||||
lastupdate = 999;
|
||||
|
||||
|
||||
void screen_draw() {
|
||||
int n = 1;
|
||||
switch(pstate) {
|
||||
case ST_CALC: n = calc_draw(); break;
|
||||
case ST_BROWSE: n = browse_draw(); break;
|
||||
case ST_HELP: n = help_draw(); break;
|
||||
case ST_DEL: n = delete_draw(); break;
|
||||
case ST_CALC: calc_draw(); break;
|
||||
case ST_BROWSE: browse_draw(); break;
|
||||
case ST_HELP: help_draw(); break;
|
||||
case ST_DEL: delete_draw(); break;
|
||||
}
|
||||
if(!n)
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
/* wait:
|
||||
* -1: non-blocking, always draw screen
|
||||
* 0: blocking wait for input and always draw screen
|
||||
* 1: non-blocking, draw screen only if a configured delay has passed or after keypress
|
||||
*/
|
||||
int input_handle(int wait) {
|
||||
int ch;
|
||||
struct timeval tv;
|
||||
|
||||
nodelay(stdscr, wait);
|
||||
screen_draw();
|
||||
nodelay(stdscr, wait?1:0);
|
||||
if(wait != 1)
|
||||
screen_draw();
|
||||
else {
|
||||
gettimeofday(&tv, (void *)NULL);
|
||||
tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay;
|
||||
if(lastupdate != tv.tv_usec) {
|
||||
screen_draw();
|
||||
lastupdate = tv.tv_usec;
|
||||
}
|
||||
}
|
||||
while((ch = getch()) != ERR) {
|
||||
if(ch == KEY_RESIZE) {
|
||||
if(ncresize(min_rows, min_cols))
|
||||
@ -108,7 +124,7 @@ char *argv_parse(int argc, char **argv) {
|
||||
for(j=1; j<len; j++)
|
||||
switch(argv[i][j]) {
|
||||
case 'x': calc_smfs = 1; break;
|
||||
case 'q': calc_delay = delete_delay = 2000; break;
|
||||
case 'q': update_delay = 2000; break;
|
||||
case '?':
|
||||
case 'h':
|
||||
printf("ncdu [-hqvx] [--exclude PATTERN] [-X FILE] directory\n\n");
|
||||
|
@ -77,6 +77,8 @@ struct dir {
|
||||
|
||||
/* program state */
|
||||
extern int pstate;
|
||||
/* minimum screen update interval when calculating, in ms */
|
||||
extern long update_delay;
|
||||
|
||||
/* handle input from keyboard and update display */
|
||||
int input_handle(int);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user