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 l = 0; // line number
27 int colors = 0; // amount of colors supported
28 int fade = 0; // disable color fading by default
29 int trans = -1; // enable transparency if term supports it
30 int max_lines = 0; // max lines per slide
31 int max_cols = 0; // max columns per line
32 int offset; // text offset
34 // header line 1 is displayed at the top
35 int bar_top = (deck->headers > 0) ? 1 : 0;
36 // header line 2 and 3 are displayed at the bottom
37 int bar_bottom = (deck->headers > 1) ? 1 : 0;
39 slide_t *slide = deck->slide;
43 // set max_lines if line count exceeded
44 max_lines = (slide->lines > max_lines) ? slide->lines : max_lines;
47 // set max_cols if length exceeded
48 max_cols = (line->length > max_cols) ? line->length : max_cols;
54 // replace stdin with current tty if markdown input was piped
55 freopen("/dev/tty", "rw", stdin);
60 if((max_cols > COLS) ||
61 (max_lines + bar_top + bar_bottom + 2 > LINES)) {
63 fprintf(stderr, "Error: Terminal size %ix%i to small. Need at least %ix%i.\n",
64 COLS, LINES, max_cols, max_lines + bar_top + bar_bottom + 2);
69 // replace stdin with current tty if markdown input was piped
70 freopen("/dev/tty", "rw", stdin);
75 // disable output of keyboard typing
78 // make getch() process one char at a time
85 if(has_colors() == TRUE) {
89 if(notrans) trans = 0; // 0 is black
93 init_pair(CP_WHITE, 255, trans);
94 init_pair(CP_BLUE, 123, trans);
95 init_pair(CP_RED, 213, trans);
96 init_pair(CP_YELLOW, 208, trans);
98 // enable color fading
103 init_pair(CP_WHITE, 7, trans);
104 init_pair(CP_BLUE, 4, trans);
105 init_pair(CP_RED, 1, trans);
106 init_pair(CP_YELLOW, 3, trans);
112 // set background color of main window
114 wbkgd(stdscr, COLOR_PAIR(CP_YELLOW));
119 offset = next_blank(line->text, 0) + 1;
120 // add text to header
122 0, (COLS - line->length + offset) / 2,
123 "%s", &line->text->text[offset]);
128 line = deck->header->next;
129 offset = next_blank(line->text, 0) + 1;
130 // add text to left footer
133 "%s", &line->text->text[offset]);
135 if(deck->headers > 2) {
136 line = deck->header->next->next;
137 offset = next_blank(line->text, 0) + 1;
138 // add text to right footer
140 LINES - 1, COLS - line->length + offset - 3,
141 "%s", &line->text->text[offset]);
145 // make header + fooder visible
149 WINDOW *content = newwin(LINES - bar_top - bar_bottom, COLS, 0 + bar_top, 0);
151 wbkgd(content, COLOR_PAIR(CP_WHITE));
163 add_line(content, l, (COLS - max_cols) / 2, line);
168 // make content visible
173 fade_in(content, trans, colors);
175 // wait for user input
178 // evaluate user input
181 // show previous slide
184 case 8: // BACKSPACE (ascii)
185 case 127: // BACKSPACE (xterm)
186 case 263: // BACKSPACE (getty)
206 // do not fade out on exit
214 fade_out(content, trans, colors);
222 void add_line(WINDOW *window, int y, int x, line_t *line) {
223 if(line->text->text) {
224 int offset = 0; // text offset
225 offset = next_nonblank(line->text, 0);
226 // print line to window
229 "%s", &line->text->text[offset]);
233 void fade_out(WINDOW *window, int trans, int colors) {
236 for(i = 22; i >= 0; i--) {
237 // darken color pairs
238 init_pair(CP_WHITE, white_ramp[i], trans);
239 init_pair(CP_BLUE, blue_ramp[i], trans);
240 init_pair(CP_RED, red_ramp[i], trans);
241 // refresh window with new color
243 // delay for our eyes to recognize the change
249 void fade_in(WINDOW *window, int trans, int colors) {
252 for(i = 0; i <= 23; i++) {
253 // lighten color pairs
254 init_pair(CP_WHITE, white_ramp[i], trans);
255 init_pair(CP_BLUE, blue_ramp[i], trans);
256 init_pair(CP_RED, red_ramp[i], trans);
257 // refresh window with new color
259 // delay for our eyes to recognize the change