diff options
| author | Franklin Wei <git@fwei.tk> | 2015-05-23 18:56:45 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-05-23 18:56:45 -0400 |
| commit | 65420c45267df9289990cb3befa078753160ab1b (patch) | |
| tree | ce02944cedb0ad28b129355506b1d842a376e4ad /src | |
| parent | c09f5635ce6edda4a93025a556565921cadc300e (diff) | |
| download | market-sim-65420c45267df9289990cb3befa078753160ab1b.zip market-sim-65420c45267df9289990cb3befa078753160ab1b.tar.gz market-sim-65420c45267df9289990cb3befa078753160ab1b.tar.bz2 market-sim-65420c45267df9289990cb3befa078753160ab1b.tar.xz | |
better support for no curses mode
Diffstat (limited to 'src')
| -rw-r--r-- | src/globals.h | 4 | ||||
| -rw-r--r-- | src/main.c | 5 | ||||
| -rw-r--r-- | src/util.c | 11 |
3 files changed, 16 insertions, 4 deletions
diff --git a/src/globals.h b/src/globals.h index c2bb8cc..b9d6e0c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -10,6 +10,8 @@ #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <sys/ioctl.h> +#include <unistd.h> #include <curl/curl.h> #include <ncurses.h> @@ -90,7 +92,7 @@ struct command_t { extern bool have_color; -void do_menu(struct player_t*, const struct command_t*, uint len, const char *prompt); +void do_menu(struct player_t*, const struct command_t*, uint, const char*); bool get_stock_info(char *sym, struct money_t*, char **name); char *csv_read(char**); char *(*read_string)(void); @@ -41,6 +41,11 @@ int main(int argc, char *argv[]) else player->cash.cents = 1000 * 100; + if(args_status & ARG_VERBOSE) + { + output("Verbose operation enabled.\n"); + } + while(1) { const struct command_t commands[] = { @@ -394,7 +394,9 @@ void horiz_line_curses(void) void horiz_line_nocurses(void) { - for(int i = 0; i < 80; ++i) + struct winsize sz; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &sz); + for(int i = 0; i < sz.ws_col; ++i) output("="); output("\n"); } @@ -432,8 +434,11 @@ void heading_nocurses(const char *fmt, ...) vsnprintf(text, sizeof(text), fmt, ap); va_end(ap); + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + int len = strlen(text) / 2; - int beg_x = 40 - len; + int beg_x = w.ws_col / 2 - len; int d = 0; if(strlen(text) & 1) d++; @@ -443,7 +448,7 @@ void heading_nocurses(const char *fmt, ...) output(" "); output(text); output(" "); - for(int i = 0; i < 40 - len - 1 - d; ++i) + for(int i = 0; i < w.ws_col / 2 - len - 1 - d; ++i) output("="); output("\n"); } |