From 29875bfa308fc52b5faee794145839794b9ab096 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 29 May 2015 21:59:22 -0400 Subject: support bold html output --- src/globals.h | 5 +++++ src/util.c | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/globals.h b/src/globals.h index 58fc0cd..6077057 100644 --- a/src/globals.h +++ b/src/globals.h @@ -43,6 +43,9 @@ #define SAVE_MAGIC "PORTv3" #define MAGIC_LEN 6 +#define BOLD_THRESHOLD 50 +#define ABS(x) (((x)<0)?-(x):(x)) + typedef unsigned long long ullong; typedef unsigned long ulong; typedef unsigned int uint; @@ -143,6 +146,8 @@ void print_history(struct stock_t*); void print_usage(int argc, char *argv[]); void print_version(void); void sig_handler(int); +void use_bold(void); +void stop_bold(void); void use_color(int); void stop_color(int); diff --git a/src/util.c b/src/util.c index bd648cf..f62106b 100644 --- a/src/util.c +++ b/src/util.c @@ -225,10 +225,16 @@ void print_handler(struct player_t *player) else if(last_buy->price.cents > stock->current_price.cents) col = COL_RED; + if(ABS((signed)last_buy->price.cents - (signed)stock->current_price.cents) >= BOLD_THRESHOLD) + use_bold(); + use_color(col); output("%5llu.%02llu", stock->current_price.cents / 100, stock->current_price.cents % 100); stop_color(col); + if(ABS((signed)last_buy->price.cents - (signed)stock->current_price.cents) >= BOLD_THRESHOLD) + stop_bold(); + output(" = $%6llu.%02llu\n", total_value / 100, total_value % 100); portfolio_value += stock->current_price.cents * stock->count; @@ -603,3 +609,20 @@ void batch_init(void) { batch_mode = true; } + +void use_bold(void) +{ + /* curses mode always has A_BOLD set, so this only applies to HTML mode */ + if(html_out) + { + output(""); + } +} + +void stop_bold(void) +{ + if(html_out) + { + output(""); + } +} -- cgit v1.1