***Controls:***
-- h, j, k, l, Cursor keys,
+- h, j, k, l, Arrow keys,
Space, Enter, Backspace,
Page Up, Page Down - next/previous slide
- Home - go to first slide
- End - go to last slide
- 1-9 - go to slide n
+- r - reload input file
- q - exit
#define FADE_DELAY 15000 // micro seconds
-int ncurses_display(deck_t *deck, int notrans, int nofade, int invert);
+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);
void inline_display(WINDOW *window, const char *c, const int colors);
void fade_out(WINDOW *window, int trans, int colors, int invert);
-> A command-line based markdown presentation tool. <-
+_Basic controls:_
+
+next slide *Enter*, *Space*, *Page Down*, *j*, *l*,
+ *Down Arrow*, *Right Arrow*
+
+previous slide *Backspace*, *Page Up*, *h*, *k*,
+ *Up Arrow*, *Left Arrow*
+
+quit *q*
+reload *r*
+slide N *1..9*
+first slide *Home*
+last slide *End*
+
-------------------------------------------------
-> # Supported markdown formatting's <-
}
int main(int argc, char *argv[]) {
- int notrans = 0;
- int nofade = 0;
- int invert = 0;
+ int notrans = 0; // disable transparency
+ int nofade = 0; // disable fading
+ int invert = 0; // invert color (black on white)
+ int reload = 0; // reload page N (0 means no reload)
+ int noreload = 1; // reload disabled until we know input is a file
// define command-line options
struct option longopts[] = {
}
// open file or set input to STDIN
- char *file;
+ char *file = NULL;
FILE *input;
if (optind < argc) {
do {
fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
exit(EXIT_FAILURE);
}
+ // enable reload because input is a file
+ noreload = 0;
}
} else {
input = stdin;
}
- // load deck object from input
- deck_t *deck;
- deck = markdown_load(input);
+ // reload loop
+ do {
+
+ // reopen input file on reload
+ if(noreload == 0 && reload > 0) {
+ if(file) {
+ input = fopen(file,"r");
+ if(!input) {
+ fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ fprintf(stderr, "%s: %s\n", argv[0], "no input file");
+ exit(EXIT_FAILURE);
+ }
+ }
- // close file
- fclose(input);
+ // load deck object from input
+ deck_t *deck;
+ deck = markdown_load(input);
- // replace stdin with current tty if input was a pipe
- if(input == stdin) {
- input = freopen("/dev/tty", "rw", stdin);
- if(!input) {
- fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno));
- exit(EXIT_FAILURE);
+ // close file
+ fclose(input);
+
+ // replace stdin with current tty if input was a pipe
+ // if input was a pipe reload is disabled, so we simply check that
+ if(noreload == 1) {
+ input = freopen("/dev/tty", "rw", stdin);
+ if(!input) {
+ fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
}
- }
- if(debug > 0) {
- markdown_debug(deck, debug);
- }
+ if(debug > 0) {
+ markdown_debug(deck, debug);
+ }
+
+ reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload);
- ncurses_display(deck, notrans, nofade, invert);
+ free_deck(deck);
- free_deck(deck);
+ // reload if supported and requested
+ } while(noreload == 0 && reload > 0);
return EXIT_SUCCESS;
}
206, 207, 201, 200, 199, 199,
198, 198, 197, 197, 196, 196};
-int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) {
+int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload) {
int c = 0; // char
int i = 0; // iterate
fprintf(stderr, "Error: Terminal width (%i columns) too small. Need at least %i columns.\n", COLS, i);
fprintf(stderr, "You may need to shorten some lines by inserting line breaks.\n");
- return 1;
+ // no reload
+ return 0;
}
// set max_cols
fprintf(stderr, "Error: Terminal height (%i lines) too small. Need at least %i lines.\n", LINES, max_lines + bar_top + bar_bottom);
fprintf(stderr, "You may need to add additional horizontal rules ('***') to split your file in shorter slides.\n");
- return 1;
+ // no reload
+ return 0;
}
// disable cursor
wbkgd(content, COLOR_PAIR(CP_WHITE));
slide = deck->slide;
+
+ // find slide to reload
+ while(reload > 1 && reload <= deck->slides) {
+ slide = slide->next;
+ sc++;
+ reload--;
+ }
+
+ // reset reload indicator
+ reload = 0;
+
while(slide) {
url_init();
}
break;
+ // reload
+ case 'r':
+ if(noreload == 0) {
+ // reload slide N
+ reload = sc;
+ slide = NULL;
+ } else {
+ // disable fading if reload is not possible
+ fade = false;
+ }
+ break;
+
// quit
case 'q':
// do not fade out on exit
fade = false;
+ // do not reload
+ reload = 0;
slide = NULL;
break;
// free ncurses memory
delwin(content);
- delwin(stdscr);
+ if(reload == 0)
+ delwin(stdscr);
- return 0;
+ // return reload indicator (0 means no reload)
+ return reload;
}
void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {