Rearrange some UI code

weechat-hashes
C. McEnroe 2020-02-02 19:38:37 -05:00
parent 5c328c7a88
commit 5398a6ac9d
1 changed files with 30 additions and 28 deletions

58
ui.c
View File

@ -41,32 +41,6 @@
#define RIGHT (COLS - 1)
#define WINDOW_LINES (LINES - 2)
static short colorPairs;
static void colorInit(void) {
start_color();
use_default_colors();
for (short pair = 0; pair < 16; ++pair) {
init_pair(1 + pair, pair % COLORS, -1);
}
colorPairs = 17;
}
static attr_t colorAttr(short fg) {
return (fg >= COLORS ? A_BOLD : A_NORMAL);
}
static short colorPair(short fg, short bg) {
if (bg == -1) return 1 + fg;
for (short pair = 17; pair < colorPairs; ++pair) {
short f, b;
pair_content(pair, &f, &b);
if (f == fg && b == bg) return pair;
}
init_pair(colorPairs, fg % COLORS, bg % COLORS);
return colorPairs++;
}
enum {
InputCols = 512,
PadLines = 512,
@ -115,18 +89,46 @@ static struct Window *windowFor(size_t id) {
}
window = malloc(sizeof(*window));
if (!window) err(EX_OSERR, "malloc");
window->id = id;
window->pad = newpad(PadLines, COLS);
scrollok(window->pad, true);
wmove(window->pad, PadLines - 1, 0);
window->heat = Cold;
window->unread = 0;
window->scroll = PadLines;
window->mark = true;
scrollok(window->pad, true);
wmove(window->pad, PadLines - 1, 0);
windowAdd(window);
return window;
}
static short colorPairs;
static void colorInit(void) {
start_color();
use_default_colors();
for (short pair = 0; pair < 16; ++pair) {
init_pair(1 + pair, pair % COLORS, -1);
}
colorPairs = 17;
}
static attr_t colorAttr(short fg) {
return (fg >= COLORS ? A_BOLD : A_NORMAL);
}
static short colorPair(short fg, short bg) {
if (bg == -1) return 1 + fg;
for (short pair = 17; pair < colorPairs; ++pair) {
short f, b;
pair_content(pair, &f, &b);
if (f == fg && b == bg) return pair;
}
init_pair(colorPairs, fg % COLORS, bg % COLORS);
return colorPairs++;
}
enum {
KeyFocusIn = KEY_MAX + 1,
KeyFocusOut,