5 #include "include/parser.h"
6 #include "include/viewer.h"
8 static short white_ramp[24] = { 16, 232, 233, 234, 235, 236,
9 237, 238, 239, 240, 241, 242,
10 244, 245, 246, 247, 248, 249,
11 250, 251, 252, 253, 254, 255 };
13 static short blue_ramp[24] = { 16, 17, 17, 18, 18, 19,
14 19, 20, 20, 21, 27, 32,
15 33, 38, 39, 44, 45, 45,
16 81, 81, 51, 51, 123, 123 };
18 static short red_ramp[24] = { 16, 52, 52, 53, 53, 89,
19 89, 90, 90, 126, 127, 127,
20 163, 163, 164, 164, 200, 200,
21 201, 201, 207, 207, 213, 213 };
23 int ncurses_display(deck_t *deck, int notrans, int nofade) {
26 int colors = 0; // amount of colors supported
27 int fade = 0; // disable color fading by default
28 int trans = -1; // enable transparency if term supports it
29 int max_lines = 0; // max lines per slide
30 int max_cols = 0; // max columns per line
32 // header line 1 is displayed at the top
33 int bar_top = (deck->headers > 0) ? 1 : 0;
34 // header line 2 and 3 are displayed at the bottom
35 int bar_bottom = (deck->headers > 1) ? 1 : 0;
37 slide_t *slide = deck->slide;
41 // set max_lines if line count exceeded
42 max_lines = (slide->lines > max_lines) ? slide->lines : max_lines;
45 // set max_cols if length exceeded
46 max_cols = (line->length > max_cols) ? line->length : max_cols;
52 // replace stdin with current tty if markdown input was piped
53 freopen("/dev/tty", "rw", stdin);
58 if((max_cols > COLS) ||
59 (max_lines + bar_top + bar_bottom + 2 > LINES)) {
61 fprintf(stderr, "Error: Terminal size %ix%i to small. Need at least %ix%i.\n",
62 COLS, LINES, max_cols, max_lines + bar_top + bar_bottom + 2);
67 // replace stdin with current tty if markdown input was piped
68 freopen("/dev/tty", "rw", stdin);
73 // disable output of keyboard typing
76 // make getch() process one char at a time
83 if(has_colors() == TRUE) {
87 if(notrans) trans = 0; // 0 is black
91 init_pair(CP_WHITE, 255, trans);
92 init_pair(CP_BLUE, 123, trans);
93 init_pair(CP_RED, 213, trans);
94 init_pair(CP_YELLOW, 208, trans);
96 // enable color fading
101 init_pair(CP_WHITE, 7, trans);
102 init_pair(CP_BLUE, 4, trans);
103 init_pair(CP_RED, 1, trans);
104 init_pair(CP_YELLOW, 3, trans);
110 // set background color of main window
112 wbkgd(stdscr, COLOR_PAIR(CP_YELLOW));
116 //TODO move cursor to calculated indentation
118 //TODO add text to header
119 wprintw(stdscr, "header");
124 //TODO move cursor to calculated indentation
125 wmove(stdscr, LINES - 1, 1);
126 //TODO add text to footer
127 wprintw(stdscr, "footer");
130 // make header + fooder visible
134 WINDOW *content = newwin(LINES - bar_top - bar_bottom, COLS, 0 + bar_top, 0);
136 wbkgd(content, COLOR_PAIR(CP_WHITE));
144 wprintw(content, "content");
146 // make content visible
151 fade_in(content, trans, colors);
153 // wait for user input
156 // evaluate user input
159 // show previous slide
181 // do not fade out on exit
189 fade_out(content, trans, colors);
197 void fade_out(WINDOW *window, int trans, int colors) {
200 for(i = 22; i >= 0; i--) {
201 // darken color pairs
202 init_pair(CP_WHITE, white_ramp[i], trans);
203 init_pair(CP_BLUE, blue_ramp[i], trans);
204 init_pair(CP_RED, red_ramp[i], trans);
205 // refresh window with new color
207 // delay for our eyes to recognize the change
213 void fade_in(WINDOW *window, int trans, int colors) {
216 for(i = 0; i <= 23; i++) {
217 // lighten color pairs
218 init_pair(CP_WHITE, white_ramp[i], trans);
219 init_pair(CP_BLUE, blue_ramp[i], trans);
220 init_pair(CP_RED, red_ramp[i], trans);
221 // refresh window with new color
223 // delay for our eyes to recognize the change