static struct gui_theme theme;
-static int _argc;
-static char **_argv;
-
static void com_help(void);
static void com_reread_conf(void);
static void com_enlarge_top_win(void);
int rbe_lines;
if (!rbe)
return i - 1;
-// fprintf(stderr, "found: %s\n", rbe->msg);
rbe_lines = NUM_LINES(rbe->len);
if (rbe_lines > bot.lines)
return -1;
new->len = len;
new->msg = msg;
old = ringbuffer_add(bot_win_rb, new);
-// fprintf(stderr, "added: %s\n", new->msg);
if (old) {
free(old->msg);
free(old);
static __printf_2_3 void curses_log(int ll, const char *fmt,...)
{
- int color;
- char *msg;
va_list ap;
- unsigned bytes;
- if (ll < loglevel || !curses_active())
+ if (ll < loglevel)
return;
- switch (ll) {
- case LL_DEBUG:
- case LL_INFO:
- case LL_NOTICE:
- color = COLOR_MSG;
- break;
- default:
- color = COLOR_ERRMSG;
- }
va_start(ap, fmt);
- bytes = xvasprintf(&msg, fmt, ap);
+ if (curses_active()) {
+ int color = ll <= LL_NOTICE? COLOR_MSG : COLOR_ERRMSG;
+ char *msg;
+ unsigned bytes = xvasprintf(&msg, fmt, ap);
+ if (bytes > 0 && msg[bytes - 1] == '\n')
+ msg[bytes - 1] = '\0'; /* cut trailing newline */
+ rb_add_entry(color, msg);
+ wrefresh(bot.win);
+ } else if (cmd_pid <= 0) /* no external command running */
+ vfprintf(stderr, fmt, ap);
va_end(ap);
- if (bytes > 0 && msg[bytes - 1] == '\n')
- msg[bytes - 1] = '\0'; /* cut trailing newline */
- rb_add_entry(color, msg);
- wrefresh(bot.win);
}
__printf_2_3 void (*para_log)(int, const char*, ...) = curses_log;
break;
rbe_lines = NUM_LINES(rbe->len);
lines += rbe_lines;
-// fprintf(stderr, "msg: %s\n", rbe->msg);
wattron(bot.win, COLOR_PAIR(rbe->color));
waddstr(bot.win, "\n");
waddstr(bot.win, rbe->msg);
return;
}
PARA_INFO_LOG("rereading command line options and config file\n");
- gui_cmdline_parser_ext(_argc, _argv, &conf, ¶ms);
/*
* Despite .print_errors is set to 0, gengetopt will print to stderr
* anyway, and exit on errors. So we have to shutdown curses first.
int ret;
char *cf;
- _argc = argc;
- _argv = argv;
-
gui_cmdline_parser(argc, argv, &conf); /* exits on errors */
loglevel = get_loglevel_by_name(conf.loglevel_arg);
version_handle_flag("gui", conf.version_given);
if (conf.help_given || conf.detailed_help_given)
print_help_and_die();
cf = configfile_exists();
- if (!cf && conf.config_file_given) {
- fprintf(stderr, "can not read config file %s\n",
+ if (!cf && conf.config_file_given)
+ msg_n_exit(EXIT_FAILURE, "can not read config file %s\n",
conf.config_file_arg);
- exit(EXIT_FAILURE);
- }
if (cf) {
struct gui_cmdline_parser_params params = {
.override = 0,
gui_cmdline_parser_config_file(cf, &conf, ¶ms);
loglevel = get_loglevel_by_name(conf.loglevel_arg);
}
- if (check_key_map_args() < 0) {
- fprintf(stderr, "invalid key map\n");
- exit(EXIT_FAILURE);
- }
+ if (check_key_map_args() < 0)
+ msg_n_exit(EXIT_FAILURE, "invalid key map\n");
theme_init(conf.theme_arg, &theme);
setup_signal_handling();
bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);