summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorwrmr2025-10-11 17:57:42 -0400
committerwrmr2025-10-11 17:57:42 -0400
commit86ee7ac60d85eb3609adc02152bd54188ca4be04 (patch)
tree1bfd1d995b9b9f1dc0b8cd658cb77c73935a0bfa /main.c
parentb35b8b8f9a918c5f7a679cdb39e32342cb816f77 (diff)
use_color()
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/main.c b/main.c
index 4c8e958..3fa481e 100644
--- a/main.c
+++ b/main.c
@@ -95,6 +95,10 @@ Str cpair_name[CPAIR_MAX] = {
CPAIR_LIST(CPAIR_NAME_X)
};
+void use_color(ColorPair cp) {
+ color_set(cp, 0);
+}
+
/* dynamic arrays */
#define DYNARR(T) struct { ptrdiff_t len, cap; T *data; }
@@ -150,7 +154,7 @@ int utf8_cp_to_byte(Str s, int dest) {
* If the high bit of fg or bg is set, the lower 24 bits are a RGB value.
*/
typedef struct {
- int fg, bg, init;
+ int fg, bg, attr, init;
} ColorOpt;
typedef struct {
@@ -562,7 +566,7 @@ int gfx_post_height(GfxPost *post) {
}
void gfx_draw_box(int y, int x, int height, int width) {
- color_set(CPAIR_BORDER, 0);
+ use_color(CPAIR_BORDER);
int right = x + width - 1, bottom = y + height - 1;
gfx_hline(y, x, right - x, ACS_HLINE);
gfx_vline(y, x, height - 1, ACS_VLINE);
@@ -631,7 +635,7 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
gfx_draw_box(top, left, height, width);
if (opt.post.date) {
- color_set(CPAIR_DATE, 0);
+ use_color(CPAIR_DATE);
char time_buf[256] = { 0 };
Str time_str = { 0 };
time_t timep = post->src->timestamp.tv_sec;
@@ -647,7 +651,7 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
}
if (opt.post.pfp) {
- color_set(self ? CPAIR_PFP_SELF : CPAIR_PFP, 0);
+ use_color(self ? CPAIR_PFP_SELF : CPAIR_PFP);
Pic *pfp = &u->pfp;
int pfpy = y;
int h = MIN(pfp->lines, GFX_PFP_MAX_LINES);
@@ -660,15 +664,15 @@ void gfx_draw_post(GfxPost *post, int y, int x, int width, Arena *scratch) {
PIC_LEFT);
}
- color_set(CPAIR_USER, 0);
+ use_color(CPAIR_USER);
mvaddnstr(top, left + 2, u->name.s, u->name.n);
if (opt.post.pronouns && u->pronouns.n) {
- color_set(CPAIR_PRONOUNS, 0);
+ use_color(CPAIR_PRONOUNS);
mvaddstr(top, left + 2 + fast_utf8_width(u->name) + GFX_PRONOUNS_MARGIN, cstr_fmt(scratch, GFX_PRONOUNS_FMT, u->pronouns));
}
- color_set(post->has_mention ? CPAIR_MENTION : CPAIR_TEXT, 0);
+ use_color(post->has_mention ? CPAIR_MENTION : CPAIR_TEXT);
Str txt = post->text;
for (int i = 0; i < post->lines; i++) {
@@ -745,7 +749,7 @@ void gfx_draw_user(User *user, Arena *scratch) {
cy -= (total_height >> 1);
if (bh > 0) {
- color_set(CPAIR_BANNER, 0);
+ use_color(CPAIR_BANNER);
gfx_draw_pic(&user->banner, cy, cx, bh, bw, PIC_CTR_X);
cy += bh + 1;
}
@@ -754,13 +758,13 @@ void gfx_draw_user(User *user, Arena *scratch) {
if (bw > box_width + user->pfp.cols) left += (bw - box_width - user->pfp.cols) >> 1;
- color_set(CPAIR_PFP, 0);
+ use_color(CPAIR_PFP);
int pfpy = cy;
if (box_height > user->pfp.lines) {
pfpy += (box_height - user->pfp.lines) >> 1;
}
gfx_draw_pic(&user->pfp, pfpy, left, GFX_PFP_MAX_LINES, GFX_PFP_MAX_COLS, 0);
- color_set(CPAIR_USER, 0);
+ use_color(CPAIR_USER);
left += user->pfp.cols + 2;
if (user->pfp.lines > box_height) {
@@ -770,10 +774,10 @@ void gfx_draw_user(User *user, Arena *scratch) {
int y = cy;
mvaddnstr(y++, left + opt.margin.text_x, user->name.s, user->name.n);
if (user->pronouns.n > 0) {
- color_set(CPAIR_PRONOUNS, 0);
+ use_color(CPAIR_PRONOUNS);
mvaddnstr(y++, left + opt.margin.text_x, user->pronouns.s, user->pronouns.n);
}
- color_set(CPAIR_TEXT, 0);
+ use_color(CPAIR_TEXT);
mvaddstr(y++, left + opt.margin.text_x, binks);
}
@@ -1146,9 +1150,9 @@ int main(void) {
arena_reset(&temp_arena);
gfx_draw(&gfx, cur, &temp_arena);
switch (msg_status) {
- case MSG_OK: color_set(CPAIR_MSG_OK, 0); break;
- case MSG_WARN: color_set(CPAIR_MSG_WARN, 0); break;
- case MSG_ERR: color_set(CPAIR_MSG_ERR, 0); break;
+ case MSG_OK: use_color(CPAIR_MSG_OK); break;
+ case MSG_WARN: use_color(CPAIR_MSG_WARN); break;
+ case MSG_ERR: use_color(CPAIR_MSG_ERR); break;
}
mvaddstr(getmaxy(stdscr) - 1, getmaxx(stdscr) - strlen(msg), msg);
msg[0] = '\0';