added color, made resizable, put text in subwindow
This commit is contained in:
parent
54139ec204
commit
c465e85d67
6 changed files with 67 additions and 26 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
cards
|
BIN
cards
BIN
cards
Binary file not shown.
BIN
obj/card.o
BIN
obj/card.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
|
@ -16,7 +16,7 @@ CARD* card_parse_csv(char *f, int *ct) {
|
|||
FILE *fp;
|
||||
char *l, *o, *r;
|
||||
const char *delims = " \0";
|
||||
CARD *ca;
|
||||
CARD *ca = NULL;
|
||||
|
||||
if ((fp = fopen(f, "r")) == NULL)
|
||||
die("failed to open file (null pointer)");
|
||||
|
|
87
src/main.c
87
src/main.c
|
@ -37,8 +37,8 @@ char *strdup_(char *s) {
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
CARD *cards;
|
||||
WINDOW *main_card;
|
||||
int cards_ct, cc = 0, cf = 0, term_y, term_x;
|
||||
WINDOW *main_card, *outer_text_card, *inner_text_container;
|
||||
int cards_ct, cc = 0, cf = 0, max_y, max_x;
|
||||
char k = '\0';
|
||||
|
||||
if (argc < 2)
|
||||
|
@ -50,15 +50,47 @@ int main(int argc, char **argv) {
|
|||
initscr();
|
||||
noecho();
|
||||
curs_set(0);
|
||||
getmaxyx(stdscr, term_y, term_x);
|
||||
main_card = newwin(term_y * .75,
|
||||
term_x * .75,
|
||||
(term_y * .5) - ((term_y * .75) * .5),
|
||||
(term_x * .5) - ((term_x * .75) * .5));
|
||||
refresh();
|
||||
if (!has_colors()) {
|
||||
endwin();
|
||||
die("terminal with color support required");
|
||||
}
|
||||
start_color();
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
init_pair(2, COLOR_BLACK, COLOR_WHITE);
|
||||
|
||||
// main loop
|
||||
do {
|
||||
// (re)init cards
|
||||
getmaxyx(stdscr, max_y, max_x);
|
||||
main_card = newwin(max_y * .75,
|
||||
max_x * .75,
|
||||
(max_y * .5) - ((max_y * .75) * .5),
|
||||
(max_x * .5) - ((max_x * .75) * .5));
|
||||
|
||||
getmaxyx(main_card, max_y, max_x);
|
||||
outer_text_card = derwin(main_card,
|
||||
max_y * .5,
|
||||
max_x * .9,
|
||||
(max_y * .5) - ((max_y * .5) * .5),
|
||||
(max_x * .5) - ((max_x * .9) * .5));
|
||||
|
||||
getmaxyx(outer_text_card, max_y, max_x);
|
||||
inner_text_container = derwin(outer_text_card,
|
||||
max_y - 2,
|
||||
max_x - 2,
|
||||
1,
|
||||
1);
|
||||
|
||||
// (re)draw cards
|
||||
clear();
|
||||
/* wattron(outer_text_card, A_BOLD); */
|
||||
wattron(inner_text_container, COLOR_PAIR(2));
|
||||
wattron(main_card, A_BOLD);
|
||||
box(outer_text_card, 0, 0);
|
||||
box(main_card, 0, 0);
|
||||
refresh();
|
||||
|
||||
// get user input
|
||||
switch (k) {
|
||||
case 'j':
|
||||
if (++cc > cards_ct - 1)
|
||||
|
@ -77,31 +109,38 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
break;
|
||||
case 'q':
|
||||
delwin(inner_text_container);
|
||||
delwin(outer_text_card);
|
||||
delwin(main_card);
|
||||
endwin();
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// clear old card
|
||||
wclear(main_card);
|
||||
wrefresh(main_card);
|
||||
|
||||
// draw box
|
||||
box(main_card, 0, 0);
|
||||
|
||||
// print title + text
|
||||
if (cf == 0) {
|
||||
// print
|
||||
if (cf == 0) { // obverse
|
||||
mvwprintw(main_card, 0, 10, " Card #%d/%d [front] \r", cc + 1, cards_ct);
|
||||
mvwprintw(main_card, (term_y * .75) * .5, (term_x * .75) * .5, "%s\r", cards[cc].obverse);
|
||||
} else {
|
||||
wprintw(inner_text_container, "%s\r", cards[cc].obverse);
|
||||
} else { // reverse
|
||||
mvwprintw(main_card, 0, 10, " Card #%d/%d [back] \r", cc + 1, cards_ct);
|
||||
mvwprintw(main_card, (term_y * .75) * .5, (term_x * .75) * .5, "%s\r", cards[cc].reverse);
|
||||
wprintw(inner_text_container, "%s\r", cards[cc].reverse);
|
||||
}
|
||||
wrefresh(main_card);
|
||||
} while ((k = getch()) != EOF);
|
||||
|
||||
/* for (size_t i = 0; i < cards_ct; i++) */
|
||||
/* printf("o: `%s`, r: `%s`\n", cards[i].obverse, cards[i].reverse); */
|
||||
/// colors
|
||||
wbkgd(outer_text_card, COLOR_PAIR(2));
|
||||
wbkgd(main_card, COLOR_PAIR(1));
|
||||
|
||||
// refresh
|
||||
touchwin(outer_text_card);
|
||||
wrefresh(inner_text_container);
|
||||
touchwin(main_card);
|
||||
wrefresh(outer_text_card);
|
||||
wrefresh(main_card);
|
||||
delwin(inner_text_container);
|
||||
delwin(outer_text_card);
|
||||
delwin(main_card);
|
||||
|
||||
} while ((k = getch()) != EOF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue