aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-05-22 21:59:35 -0400
committerFranklin Wei <git@fwei.tk>2015-05-22 21:59:35 -0400
commit13ac2252200bc208a09c396f6629042f0e49c16a (patch)
treef56ead900ca7ecefe825d440fac161467139798b /src
parent2ad946d048a38a1e3ef3c49843f60444c7c661ae (diff)
downloadmarket-sim-13ac2252200bc208a09c396f6629042f0e49c16a.zip
market-sim-13ac2252200bc208a09c396f6629042f0e49c16a.tar.gz
market-sim-13ac2252200bc208a09c396f6629042f0e49c16a.tar.bz2
market-sim-13ac2252200bc208a09c396f6629042f0e49c16a.tar.xz
some fixes
Diffstat (limited to 'src')
-rw-r--r--src/globals.h3
-rw-r--r--src/info.c4
-rw-r--r--src/util.c16
3 files changed, 16 insertions, 7 deletions
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("=");
}