diff options
| author | Franklin Wei <git@fwei.tk> | 2015-05-29 19:19:49 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-05-29 19:19:49 -0400 |
| commit | e61bc0fe416326a2a9e4c70fb29893df0b4e4b4f (patch) | |
| tree | 0df4346a88d35411e14a2b9493fdffd70bebf4f2 | |
| parent | a7e236db995b22eaf2cb9d355a7f369733bef1aa (diff) | |
| download | market-sim-e61bc0fe416326a2a9e4c70fb29893df0b4e4b4f.zip market-sim-e61bc0fe416326a2a9e4c70fb29893df0b4e4b4f.tar.gz market-sim-e61bc0fe416326a2a9e4c70fb29893df0b4e4b4f.tar.bz2 market-sim-e61bc0fe416326a2a9e4c70fb29893df0b4e4b4f.tar.xz | |
colorize stock prices based on value change
| -rw-r--r-- | src/util.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -206,10 +206,30 @@ void print_handler(struct player_t *player) struct stock_t *stock = player->portfolio + i; if(stock->count) { + struct history_item *last_buy = NULL; + struct history_item *iter = stock->history; + while(iter) + { + if(iter->action == BUY) + last_buy = iter; + iter = iter->next; + } + ullong total_value = stock->count * stock->current_price.cents; - output("%6s %40s %5llu * $%5llu.%02llu = $%6llu.%02llu\n", - stock->symbol, stock->fullname, stock->count, stock->current_price.cents / 100, stock->current_price.cents % 100, - total_value / 100, total_value % 100); + output("%6s %40s %5llu * $", + stock->symbol, stock->fullname, stock->count); + + int col = COL_NORM; + if(last_buy->price.cents < stock->current_price.cents) + col = COL_GREEN; + else if(last_buy->price.cents > stock->current_price.cents) + col = COL_RED; + + use_color(col); + output("%5llu.%02llu", stock->current_price.cents / 100, stock->current_price.cents % 100); + stop_color(col); + + output(" = $%6llu.%02llu\n", total_value / 100, total_value % 100); portfolio_value += stock->current_price.cents * stock->count; } |