static unsigned scroll_position;
-static bool curses_active;
static pid_t cmd_pid;
static int command_fds[2] = {-1, -1};
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);
return -1;
}
+/* isendwin() returns false before initscr() was called */
+static bool curses_active(void)
+{
+ return top.win && !isendwin();
+}
+
/* taken from mutt */
static char *km_keyname(int c)
{
char *msg;
va_list ap;
- if (!curses_active)
+ if (!curses_active())
return;
wattron(in.win, COLOR_PAIR(color));
va_start(ap, fmt);
char *msg;
va_list ap;
- if (!curses_active)
+ if (!curses_active())
return;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
{
int color = *(int *)data? COLOR_ERRMSG : COLOR_OUTPUT;
- if (!curses_active)
+ if (!curses_active())
return 1;
rb_add_entry(color, para_strdup(line));
return 1;
va_list ap;
unsigned bytes;
- if (ll < loglevel || !curses_active)
+ if (ll < loglevel || !curses_active())
return;
switch (ll) {
case LL_DEBUG:
static void shutdown_curses(void)
{
- if (!curses_active)
- return;
def_prog_mode();
- curses_active = false;
endwin();
}
struct stat_item_data d = theme.data[i];
char *c = stat_content[i];
- if (!curses_active || !d.len || !c)
+ if (!curses_active() || !d.len || !c)
return;
tmp = make_message("%s%s%s", d.prefix, c, d.postfix);
wmove(top.win, d.y * top.lines / 100, d.x * COLS / 100);
{
int i;
- if (!curses_active)
+ if (!curses_active())
return;
FOR_EACH_STATUS_ITEM(i)
print_stat_item(i);
/* (Re-)initialize the curses library. */
static void init_curses(void)
{
- curses_active = true;
+ if (curses_active())
+ return;
if (top.win && refresh() == ERR) /* refresh is really needed */
msg_n_exit(EXIT_FAILURE, "refresh() failed\n");
if (LINES < theme.lines_min || COLS < theme.cols_min)
"only the good die young (caught SIGTERM))\n");
return;
case SIGWINCH:
- if (curses_active) {
+ if (curses_active()) {
shutdown_curses();
init_curses();
redraw_bot_win();
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.
return;
}
init_wins(top.lines - 1);
- wclear(top.win);
print_all_items();
print_in_bar(COLOR_MSG, "%s", "decreased top window");
}
return;
}
init_wins(top.lines + 1);
- wclear(top.win);
print_all_items();
print_in_bar(COLOR_MSG, "increased top window");
}
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);