X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=viewer.c;h=a6cf53c7209d6c5f9f04c1502124aeacbf576079;hb=66f6ce722f0d763efbf66ca6f8a958bc75ab854e;hp=d6b5c8539bbb80ff4b6fbf641d69a57d22dea743;hpb=70ce4d7eba90b5da6f9187eb217794db6f153888;p=smdp.git diff --git a/viewer.c b/viewer.c index d6b5c85..a6cf53c 100644 --- a/viewer.c +++ b/viewer.c @@ -23,11 +23,13 @@ static short red_ramp[24] = { 16, 52, 52, 53, 53, 89, int ncurses_display(deck_t *deck, int notrans, int nofade) { int c = 0; // char + int l = 0; // line number int colors = 0; // amount of colors supported int fade = 0; // disable color fading by default int trans = -1; // enable transparency if term supports it int max_lines = 0; // max lines per slide int max_cols = 0; // max columns per line + int offset; // text offset // header line 1 is displayed at the top int bar_top = (deck->headers > 0) ? 1 : 0; @@ -113,18 +115,31 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // setup header if(bar_top) { - //TODO move cursor to calculated indentation - wmove(stdscr, 0, 1); - //TODO add text to header - wprintw(stdscr, "header"); + line = deck->header; + offset = next_blank(line->text, 0) + 1; + // add text to header + mvwprintw(stdscr, + 0, (COLS - line->length + offset) / 2, + "%s", &line->text->text[offset]); } // setup footer if(bar_bottom) { - //TODO move cursor to calculated indentation - wmove(stdscr, LINES - 1, 1); - //TODO add text to footer - wprintw(stdscr, "footer"); + line = deck->header->next; + offset = next_blank(line->text, 0) + 1; + // add text to left footer + mvwprintw(stdscr, + LINES - 1, 3, + "%s", &line->text->text[offset]); + + if(deck->headers > 2) { + line = deck->header->next->next; + offset = next_blank(line->text, 0) + 1; + // add text to right footer + mvwprintw(stdscr, + LINES - 1, COLS - line->length + offset - 3, + "%s", &line->text->text[offset]); + } } // make header + fooder visible @@ -140,8 +155,15 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // clear main window werase(content); - //TODO print lines - wprintw(content, "content"); + line = slide->line; + l = 0; + + // print lines + while(line) { + add_line(content, l, (COLS - max_cols) / 2, line); + line = line->next; + l++; + } // make content visible wrefresh(content); @@ -150,6 +172,9 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { if(fade) fade_in(content, trans, colors); + // re-enable fading after any undefined key press + if(COLORS == 256 && !nofade) fade = 1; + // wait for user input c = getch(); @@ -159,7 +184,9 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // show previous slide case KEY_UP: case KEY_LEFT: - case KEY_BACKSPACE: + case 8: // BACKSPACE (ascii) + case 127: // BACKSPACE (xterm) + case 263: // BACKSPACE (getty) case 'h': case 'k': if(slide->prev) @@ -169,7 +196,8 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // show next slide case KEY_DOWN: case KEY_RIGHT: - case KEY_ENTER: + case '\n': // ENTER + case ' ': // SPACE case 'j': case 'l': if(slide->next) @@ -182,6 +210,11 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { fade = 0; slide = (void*)0; break; + + default: + // disable fading on undefined key press + fade = 0; + break; } // fade out @@ -194,6 +227,17 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { return(0); } +void add_line(WINDOW *window, int y, int x, line_t *line) { + if(line->text->text) { + int offset = 0; // text offset + offset = next_nonblank(line->text, 0); + // print line to window + mvwprintw(window, + y, x, + "%s", &line->text->text[offset]); + } +} + void fade_out(WINDOW *window, int trans, int colors) { int i; // increment if(colors) {