/* * Print a `one-liner' status message at the bottom of the screen. Messages are * trimmed to fit within the console length (ANSI coloring not accounted for). */ void status_printf(const char *fmt, ...) { int n, attrs; chtype color = dlg_color_pair(dlg_color_table[BUTTON_ACTIVE_ATTR].fg, dlg_color_table[SCREEN_ATTR].bg) | A_BOLD; va_list args; status_row = tty_maxrows() - 1; status_width = tty_maxcols(); /* NULL is a special convention meaning "erase the old stuff" */ if (fmt == NULL) { move(status_row, 0); clrtoeol(); return; } /* Resize buffer if terminal width is greater */ if ((status_width + 1) > status_bufsize) { status_buf = realloc(status_buf, status_width + 1); if (status_buf == NULL) { status_bufsize = -1; return; } status_bufsize = status_width + 1; } /* Print the message within a space-filled buffer */ memset(status_buf, ' ', status_width); va_start(args, fmt); n = vsnprintf(status_buf, status_width + 1, fmt, args); va_end(args); /* If vsnprintf(3) produced less bytes than the maximum, change the * implicitly-added NUL-terminator into a space and terminate at max */ if (n < status_width) { status_buf[n] = ' '; status_buf[status_width] = '\0'; } /* Print text in screen bg, button active fg, and bold */ attrs = getattrs(stdscr); attrset(color); mvaddstr(status_row, 0, status_buf); attrset(attrs); /* Seat the cursor over the last character at absolute lower-right */ move(status_row, status_width - 1); refresh(); }
static chtype merge_colors(chtype foreground, chtype background) { chtype result = foreground; if ((foreground & A_COLOR) != (background & A_COLOR)) { short fg_f, bg_f; short fg_b, bg_b; short fg_pair = (short) PAIR_NUMBER(foreground); short bg_pair = (short) PAIR_NUMBER(background); if (pair_content(fg_pair, &fg_f, &bg_f) != ERR && pair_content(bg_pair, &fg_b, &bg_b) != ERR) { result &= ~A_COLOR; result |= dlg_color_pair(fg_f, bg_b); } } return result; }