summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-11 17:12:31 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-11 17:12:31 -0700
commit0e49915f3bb4e12656eda150a44649de83ace440 (patch)
tree3f6cc4a0f9b26a5a369304a93d6709c727194792
parent630c3d810172fb06ee406cd3a6e57a45673b5886 (diff)
downloaddartboat-0e49915f3bb4e12656eda150a44649de83ace440.tar.gz
dartboat-0e49915f3bb4e12656eda150a44649de83ace440.tar.xz
separate status bar from prompt
-rw-r--r--dartbot.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/dartbot.c b/dartbot.c
index c1db96d..ae64b7f 100644
--- a/dartbot.c
+++ b/dartbot.c
@@ -85,7 +85,7 @@ void init_sectors()
M(0, 196, 0) \
M(DARTS, 235, 0) \
M(VISIT, 244, 0) \
- M(PROMPT, 0, 7)
+ M(STATUS, 7, 4)
#define GEN_COLOUR_ENUM(X, FG, BG) C_ ## X,
#define GEN_COLOUR_INIT_PAIR(X, FG, BG) init_pair(C_ ## X, FG, BG);
@@ -99,7 +99,7 @@ void init_colours()
FOREACH_COLOUR(GEN_COLOUR_INIT_PAIR)
}
-WINDOW *w, *statw;
+WINDOW *w, *statw, *promptw;
struct ccoords {
double x, y;
@@ -363,31 +363,43 @@ void curses_status(char *status)
wrefresh(statw);
}
+void curses_prompt(char *prompt)
+{
+ wmove(promptw, 0, 0);
+ wclrtoeol(promptw);
+ waddstr(promptw, prompt);
+ wrefresh(promptw);
+}
+
void user_visit(struct leg *l)
{
struct visit *v = l->visits + l->n_visits++;
- char prompt[] = " Enter points: ";
- curses_status(prompt);
+ char status[100];
+ sprintf(status, "%d remaining", l->rem);
+ char prompt[] = "enter points> ";
+ curses_status(status);
+ curses_prompt(prompt);
char buf[100] = { 0 };
int buflen = 0;
int c;
- while((c = wgetch(statw)) != 10) {
+ while((c = wgetch(promptw)) != 10) {
if (c == 127) {
if (buflen > 0) {
buf[--buflen] = 0;
- wmove(statw, 0, sizeof(prompt) - 1 + buflen);
- wclrtoeol(statw);
- wrefresh(statw);
+ wmove(promptw, 0, sizeof(prompt) - 1 + buflen);
+ wclrtoeol(promptw);
+ wrefresh(promptw);
}
} else if (c >= '0' && c <= '9') {
buf[buflen++] = c;
- wechochar(statw, c);
+ wechochar(promptw, c);
}
}
+ curses_prompt("");
v->points = atoi(buf);
l->rem -= v->points;
v->rem = l->rem;
@@ -431,7 +443,7 @@ void curses_draw(struct leg *l1, struct leg *l2)
char buf[100];
int buflen = 0;
- int wlines = LINES - 3;
+ int wlines = LINES - 4;
int n_visits = l1->n_visits > l2->n_visits ? l1->n_visits : l2->n_visits;
int start_visit = (wlines > n_visits) ? 0 : (n_visits - wlines);
int offset = 0;
@@ -495,9 +507,10 @@ void curses_match(int start_points, void (*f1)(struct leg *),
curs_set(0);
noecho();
- w = newwin(LINES-3, COLS-2, 1, 1);
- statw = newwin(1, COLS-2, LINES-2, 1);
- wbkgd(statw, COLOR_PAIR(C_PROMPT));
+ w = newwin(LINES-4, COLS-2, 1, 1);
+ statw = newwin(1, COLS-2, LINES-3, 1);
+ promptw = newwin(1, COLS-2, LINES-2, 1);
+ wbkgd(statw, COLOR_PAIR(C_STATUS));
struct leg *l1 = leg_init(start_points);
struct leg *l2 = leg_init(start_points);
@@ -522,6 +535,7 @@ void curses_match(int start_points, void (*f1)(struct leg *),
leg_free(l1);
leg_free(l2);
wgetch(w);
+ delwin(promptw);
delwin(statw);
delwin(w);
endwin();