aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-05-27 20:58:07 -0400
committerFranklin Wei <git@fwei.tk>2015-05-27 20:58:07 -0400
commit34b11c33ff5b0df5466642b577bf32b529fc66fd (patch)
treecd079ea23e7c46de1421f9b990abf96e70d41f0b
parent8b61f947daa7b64a2dd8ee7d6340c64fa7787f07 (diff)
downloadmarket-sim-34b11c33ff5b0df5466642b577bf32b529fc66fd.zip
market-sim-34b11c33ff5b0df5466642b577bf32b529fc66fd.tar.gz
market-sim-34b11c33ff5b0df5466642b577bf32b529fc66fd.tar.bz2
market-sim-34b11c33ff5b0df5466642b577bf32b529fc66fd.tar.xz
add colorized html output
-rw-r--r--src/globals.h2
-rw-r--r--src/help.c1
-rw-r--r--src/main.c3
-rw-r--r--src/util.c32
4 files changed, 38 insertions, 0 deletions
diff --git a/src/globals.h b/src/globals.h
index bb5450e..6403327 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -28,6 +28,7 @@
#define ARG_NOCURSES (1<<3)
#define ARG_BATCHMODE (1<<4)
#define ARG_RESTRICTED (1<<5)
+#define ARG_HTML (1<<6)
/* don't change this, it will corrupt existing saves */
#define EPOCH_YEAR 2000
@@ -94,6 +95,7 @@ struct command_t {
/*** prototypes ***/
extern bool have_color;
+extern bool html_out;
/* restricted mode disables things that would be considered "dangerous" when
used in a web-facing script such as interactive loading/saving */
diff --git a/src/help.c b/src/help.c
index f82616f..b6a0011 100644
--- a/src/help.c
+++ b/src/help.c
@@ -10,6 +10,7 @@ void print_usage(int argc, char *argv[])
output("Options:\n");
output(" --batch\tEnables batch operation, taking commands from standard input\n");
output(" -h, --help\tShow this help and exit\n");
+ output(" --html\tUse HTML formatting for output (implies --nocurses)\n");
output(" --nocurses\tOperate without curses\n");
output(" -r, --restrict\tOperate in restricted mode, suitable for use as a CGI program\n");
output(" -v, --verbose\tEnable verbose operation\n");
diff --git a/src/main.c b/src/main.c
index b40765c..3c65505 100644
--- a/src/main.c
+++ b/src/main.c
@@ -44,6 +44,9 @@ int main(int argc, char *argv[])
if(args_status & ARG_RESTRICTED)
restricted = true;
+ if(args_status & ARG_HTML)
+ html_out = true;
+
if(args_status & ARG_LOADED)
load_portfolio(player, save_file);
else
diff --git a/src/util.c b/src/util.c
index 25b9e43..7f58436 100644
--- a/src/util.c
+++ b/src/util.c
@@ -319,6 +319,11 @@ uint parse_args(int argc, char *argv[], char **port_file)
ret |= ARG_FAILURE;
break;
}
+ else if(strcmp(arg, "--html") == 0)
+ {
+ ret |= ARG_HTML;
+ ret |= ARG_NOCURSES;
+ }
else if(strcmp(arg, "--nocurses") == 0)
{
ret |= ARG_NOCURSES;
@@ -483,12 +488,35 @@ void (*heading)(const char*, ...) = heading_nocurses;
bool have_color = false;
+bool html_out = false;
+
void use_color(int col)
{
if(have_color)
{
attron(COLOR_PAIR(col));
}
+ else if(html_out)
+ {
+ uchar r, g, b;
+ switch(col)
+ {
+ case COL_NORM:
+ r = g = b = 0;
+ break;
+ case COL_RED:
+ r = 255;
+ g = b = 0;
+ break;
+ case COL_GREEN:
+ r = b = 0;
+ g = 255;
+ break;
+ default:
+ assert(0);
+ }
+ output("<font color=\"#%02x%02x%02x\">", r, g, b);
+ }
}
void stop_color(int col)
@@ -497,6 +525,10 @@ void stop_color(int col)
{
attroff(COLOR_PAIR(col));
}
+ else if(html_out)
+ {
+ output("</font>");
+ }
}
void curses_init(void)