From: Hiral Patel Date: Sun, 1 Feb 2015 03:56:53 +0000 (-0500) Subject: Navigate to any slide number X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=e19dfe3efed8333bb4363491740239ad7cbe0483;p=smdp.git Navigate to any slide number --- diff --git a/include/viewer.h b/include/viewer.h index 263f703..d921247 100644 --- a/include/viewer.h +++ b/include/viewer.h @@ -50,6 +50,7 @@ #define CP_BLACK 5 // CP_WHITE with foreground and background swapped #define FADE_DELAY 15000 // micro seconds +#define GOTO_SLIDE_DELAY 5 // tenths of seconds int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload); void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors); @@ -57,5 +58,6 @@ void inline_display(WINDOW *window, const char *c, const int colors); void fade_out(WINDOW *window, int trans, int colors, int invert); void fade_in(WINDOW *window, int trans, int colors, int invert); int int_length (int val); +int get_slide_number(char init); #endif // !defined( VIEWER_H ) diff --git a/src/viewer.c b/src/viewer.c index 211557e..b540b1a 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -361,16 +361,17 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa break; // show slide n - case '9': i++; - case '8': i++; - case '7': i++; - case '6': i++; - case '5': i++; - case '4': i++; - case '3': i++; - case '2': i++; - case '1': i++; - if(i <= deck->slides) { + case '9': + case '8': + case '7': + case '6': + case '5': + case '4': + case '3': + case '2': + case '1': + i = get_slide_number(c); + if(i > 0 && i <= deck->slides) { while(sc != i) { // search forward if(sc < i) { @@ -839,3 +840,20 @@ int int_length (int val) { } return l; } + +int get_slide_number(char init) { + int retval = init - '0'; + char c; + // block for tenths of a second when using getch, ERR if no input + halfdelay(GOTO_SLIDE_DELAY); + while((c = getch()) != ERR) { + if (c < '0' || c > '9') { + retval = -1; + break; + } + retval = (retval * 10) + (c - '0'); + } + nocbreak(); // cancel half delay mode + cbreak(); // go back to cbreak + return retval; +}