From 13ac2252200bc208a09c396f6629042f0e49c16a Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 22 May 2015 21:59:35 -0400 Subject: some fixes --- src/globals.h | 3 ++- src/info.c | 4 ++-- src/util.c | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/globals.h b/src/globals.h index f532644..721507c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -113,9 +113,10 @@ void print_usage(int argc, char *argv[]); void print_version(void); void sig_handler(int); int output(const char*, ...); -void heading(const char *text); +void heading(const char *text, ...); void horiz_line(void); + void buy_handler(struct player_t*); void info_handler(struct player_t*); void load_handler(struct player_t*); diff --git a/src/info.c b/src/info.c index 9e93d25..4776540 100644 --- a/src/info.c +++ b/src/info.c @@ -25,8 +25,8 @@ void info_handler(struct player_t *player) free(sym); - output("Transaction history for '%s':\n", stock->symbol); - horiz_line(); + heading("Transaction history for '%s'", stock->symbol); + print_history(stock); horiz_line(); output("Current price: $%llu.%02llu\n", stock->current_price.cents / 100, stock->current_price.cents % 100); diff --git a/src/util.c b/src/util.c index 654e7d8..a3b84ed 100644 --- a/src/util.c +++ b/src/util.c @@ -190,8 +190,7 @@ struct stock_t *find_stock(struct player_t *player, char *sym) void print_handler(struct player_t *player) { - output("Your portfolio:\n"); - horiz_line(); + heading("Your Portfolio"); ullong portfolio_value = 0; @@ -377,16 +376,25 @@ void horiz_line(void) } } -void heading(const char *text) +void heading(const char *fmt, ...) { + char text[128]; + va_list ap; + va_start(ap, fmt); + vsnprintf(text, sizeof(text), fmt, ap); + va_end(ap); + int len = strlen(text) / 2; int beg_x = getmaxx(stdscr) / 2 - len; + int d = 0; + if(strlen(text) & 1) + d++; for(int i = 0; i < beg_x - 1; ++i) output("="); output(" "); output(text); output(" "); - for(int i = 0; i < getmaxx(stdscr) - getmaxx(stdscr) / 2 - len - 1; ++i) + for(int i = 0; i < getmaxx(stdscr) - getmaxx(stdscr) / 2 - len - 1 - d; ++i) output("="); } -- cgit v1.1