2 * "THE BEER-WARE LICENSE" (Revision 42):
3 * <tobias.rehbein@web.de> wrote this file. As long as you retain this notice
4 * you can do whatever you want with this stuff. If we meet some day, and you
5 * think this stuff is worth it, you can buy me a beer in return.
21 #define RESETGUI() do { \
27 static void print_oggfile(struct oggfile
*oggfile
);
28 static void print_header(char const *step
, struct ui_model
*model
);
30 /* Global variables */
39 if ((tty
= open("/dev/tty", O_RDONLY
)) == -1)
40 err(1, "could not open /dev/tty");
41 if ((ftty
= fopen("/dev/tty", "r")) == NULL
)
42 err(1, "could not open /dev/tty");
43 if ((term
= newterm(NULL
, stdout
, ftty
)) == NULL
)
44 errx(1, "could not create /dev/tty terminal");
45 if (initscr() == NULL
)
46 errx(1, "could not initialize screen");
47 if (set_term(term
) == NULL
)
48 errx(1, "could not set /dev/tty terminal");
52 init_pair(1, COLOR_WHITE
, COLOR_BLACK
);
53 init_pair(2, COLOR_GREEN
, COLOR_BLACK
);
54 init_pair(3, COLOR_RED
, COLOR_BLACK
);
55 intrflush(stdscr
, FALSE
);
59 ui_display_quiz(struct ui_model
*model
, struct options
*opts
)
63 assert(model
!= NULL
);
67 print_header("new turn", model
);
69 for (i
= 0; i
< opts
->choices
; i
++) {
74 mvprintw(y
++, 1, "%d. %s\n", i
+ 1, model
->oggfiles
[i
].artist
);
75 mvprintw(y
++, 1, " %s\n", model
->oggfiles
[i
].album
);
76 mvprintw(y
++, 1, " %s\n\n", model
->oggfiles
[i
].title
);
82 mvprintw(y
, 0, " What are you listening to? (1-%d, 'q' to quit) ", opts
->choices
);
89 ui_display_result(struct ui_model
*model
, struct options
*opts
)
93 assert(model
!= NULL
);
97 print_header("result", model
);
99 if (model
->correct
== model
->guess
) {
100 attron(COLOR_PAIR(2));
102 mvprintw(y
++, 1, "You are right!");
105 attron(COLOR_PAIR(3));
107 mvprintw(y
++, 1, "Sorry, you are wrong!");
110 mvprintw(y
++, 1, "Your guess:");
112 print_oggfile(model
->guess
);
114 attron(COLOR_PAIR(1));
117 mvprintw(y
++, 1, "You are listening to:");
119 print_oggfile(model
->correct
);
122 mvprintw(y
++, 1, "Scoreboard:");
125 for (i
= 0; i
< opts
->players
; i
++) {
126 if (i
== model
->current_player
)
130 mvprintw(y
++, 3, "Player %d: %5d", i
+ 1, model
->scores
[i
]);
136 mvaddstr(y
++, 0, " press any key to continue... ");
161 if (close(tty
) == -1)
162 err(1, "could not close fd for /dev/tty");
163 if (fclose(ftty
) == EOF
)
164 err(1, "could not close /dev/tty");
169 print_oggfile(struct oggfile
*oggfile
)
171 assert(oggfile
!=NULL
);
173 mvprintw(y
++, 3, "%s", oggfile
->artist
);
174 mvprintw(y
++, 3, "%s", oggfile
->album
);
175 mvprintw(y
++, 3, "%s", oggfile
->title
);
179 print_header(char const *step
, struct ui_model
*model
)
181 assert(step
!= NULL
);
182 assert(model
!= NULL
);
185 mvprintw(y
, 0, " %s | current turn: %03d | current player: %d ",
186 step
, model
->turn
, model
->current_player
+ 1);