There is no need to store this information as we can easily compute it.
shutdown_curses() needed to be changed to cope with early failures:
On fatal errors that happen after initscr() was called but before
the top window exists, we must shut down the curses subsystem albeit
curses_active() returns false in this case.
static unsigned scroll_position;
static unsigned scroll_position;
-static bool curses_active;
static pid_t cmd_pid;
static int command_fds[2] = {-1, -1};
static pid_t cmd_pid;
static int command_fds[2] = {-1, -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)
{
/* taken from mutt */
static char *km_keyname(int c)
{
return;
wattron(in.win, COLOR_PAIR(color));
va_start(ap, fmt);
return;
wattron(in.win, COLOR_PAIR(color));
va_start(ap, fmt);
return;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
return;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
{
int color = *(int *)data? COLOR_ERRMSG : COLOR_OUTPUT;
{
int color = *(int *)data? COLOR_ERRMSG : COLOR_OUTPUT;
return 1;
rb_add_entry(color, para_strdup(line));
return 1;
return 1;
rb_add_entry(color, para_strdup(line));
return 1;
va_list ap;
unsigned bytes;
va_list ap;
unsigned bytes;
- if (ll < loglevel || !curses_active)
+ if (ll < loglevel || !curses_active())
return;
switch (ll) {
case LL_DEBUG:
return;
switch (ll) {
case LL_DEBUG:
static void shutdown_curses(void)
{
static void shutdown_curses(void)
{
- if (!curses_active)
- return;
struct stat_item_data d = theme.data[i];
char *c = stat_content[i];
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);
return;
tmp = make_message("%s%s%s", d.prefix, c, d.postfix);
wmove(top.win, d.y * top.lines / 100, d.x * COLS / 100);
return;
FOR_EACH_STATUS_ITEM(i)
print_stat_item(i);
return;
FOR_EACH_STATUS_ITEM(i)
print_stat_item(i);
/* (Re-)initialize the curses library. */
static void init_curses(void)
{
/* (Re-)initialize the curses library. */
static void init_curses(void)
{
+ 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)
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:
"only the good die young (caught SIGTERM))\n");
return;
case SIGWINCH:
shutdown_curses();
init_curses();
redraw_bot_win();
shutdown_curses();
init_curses();
redraw_bot_win();