summaryrefslogtreecommitdiff
path: root/src/palette.h
blob: 5eef03e10e6c474f0cff5fc76929506a281c817d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef TERM_PALETTE_H
#define TERM_PALETTE_H

#include <stdbool.h>
#include <stdint.h>

#include "term.h"

/*
 * The colors of one terminal. base holds the colors that the theme gives;
 * colors holds base plus the entries that the program changed with OSC 4,
 * 10, 11, or 12. version changes whenever colors changes.
 */
struct palette {
    uint32_t colors[TERM_PALETTE_SIZE];
    uint32_t base[TERM_PALETTE_SIZE];
    struct term_theme theme;
    uint64_t version;
};

/* Set every entry from theme. An all-zero theme selects the built-in theme. */
void term_palette_init(struct palette *p, const struct term_theme *theme);
/* Change one entry (0-255, TERM_PALETTE_FG, _BG, or _CURSOR). */
void term_palette_set(struct palette *p, int slot, uint32_t argb);
/* Restore one entry, or all entries, to the theme color. */
void term_palette_reset(struct palette *p, int slot);
void term_palette_reset_all(struct palette *p);

static inline uint32_t palette_resolve(const struct palette *p, term_color c)
{
    return term_color_is_slot(c) ? p->colors[c & 0x1FFu] : c;
}

#endif