* faded in 256 color mode.
* Copyright (C) 2014 Michael Goehler
*
- * This file is part of mpd.
+ * This file is part of mdp.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if((max_cols > COLS) ||
(max_lines + bar_top + bar_bottom + 2 > LINES)) {
- fprintf(stderr, "Error: Terminal size %ix%i to small. Need at least %ix%i.\n",
+ fprintf(stderr, "Error: Terminal size %ix%i too small. Need at least %ix%i.\n",
COLS, LINES, max_cols, max_lines + bar_top + bar_bottom + 2);
endwin();
return(1);
start_color();
use_default_colors();
- if(notrans) trans = 0; // 0 is black
+ if(notrans) trans = 0; // black in 8 color mode
if(COLORS == 256) {
+ if(notrans) trans = 16; // black in 256 color mode
+
// 256 color mode
init_pair(CP_WHITE, 255, trans);
init_pair(CP_BLUE, 123, trans);
werase(content);
werase(stdscr);
+ // always resize window in case terminal geometry has changed
+ wresize(content, LINES - bar_top - bar_bottom, COLS);
+
// setup header
if(bar_top) {
line = deck->header;
}
// setup 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 > 1) {
+ 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]);
+ }
// add slide number to right footer
mvwprintw(stdscr,
LINES - 1, COLS - int_length(deck->slides) - int_length(sc) - 6,
// print lines
while(line) {
- add_line(content, l, (COLS - max_cols) / 2, line, max_cols);
+ add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors);
line = line->next;
l++;
}
return(0);
}
-void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) {
+void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {
int i = 0; // increment
char *c; // char pointer for iteration
char *special = "\\*_"; // list of interpreted chars
if(line->text->text) {
int offset = 0; // text offset
- offset = next_nonblank(line->text, 0);
// IS_CODE
if(CHECK_BIT(line->bits, IS_CODE)) {
if(CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) {
// set headline color
- wattron(window, COLOR_PAIR(CP_BLUE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_BLUE));
// enable underline for H1
if(CHECK_BIT(line->bits, IS_H1))
break;
// disable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
case '_':
switch(*c) {
// enable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_RED));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_RED));
break;
// enable underline
case '_':
// pop stack until empty to prevent formated trailing spaces
while(!(stack->empty)(stack)) {
switch((stack->pop)(stack)) {
- case '\\':
- wprintw(window, "%c", '\\');
- break;
// disable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
case '_':
wattroff(window, A_UNDERLINE);
break;
+ // do nothing for backslashes
}
}
}
wprintw(window, "%s", " ");
// reset to default color
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
wattroff(window, A_UNDERLINE);
wattroff(window, A_REVERSE);
}