mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
config: add color.sixelN options
These options allows you to configure the default sixel color palette.
This commit is contained in:
parent
e891abdd6a
commit
511aad419b
8 changed files with 64 additions and 38 deletions
|
|
@ -63,6 +63,8 @@
|
|||
* `strikeout-thickness` option.
|
||||
* Implemented the new `xdg-toplevel-icon-v1` protocol.
|
||||
* Implemented `CSI 21 t`: report window title.
|
||||
* `colors.sixelNN` option, controlling the default sixel color
|
||||
palette.
|
||||
|
||||
[1807]: https://codeberg.org/dnkl/foot/issues/1807
|
||||
|
||||
|
|
|
|||
29
config.c
29
config.c
|
|
@ -86,6 +86,26 @@ static const uint32_t default_color_table[256] = {
|
|||
0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
|
||||
};
|
||||
|
||||
/* VT330/VT340 Programmer Reference Manual - Table 2-3 VT340 Default Color Map */
|
||||
static const uint32_t default_sixel_colors[16] = {
|
||||
0xff000000,
|
||||
0xff3333cc,
|
||||
0xffcc2121,
|
||||
0xff33cc33,
|
||||
0xffcc33cc,
|
||||
0xff33cccc,
|
||||
0xffcccc33,
|
||||
0xff878787,
|
||||
0xff424242,
|
||||
0xff545499,
|
||||
0xff994242,
|
||||
0xff549954,
|
||||
0xff995499,
|
||||
0xff549999,
|
||||
0xff999954,
|
||||
0xffcccccc,
|
||||
};
|
||||
|
||||
static const char *const binding_action_map[] = {
|
||||
[BIND_ACTION_NONE] = NULL,
|
||||
[BIND_ACTION_NOOP] = "noop",
|
||||
|
|
@ -1309,6 +1329,14 @@ parse_section_colors(struct context *ctx)
|
|||
return true;
|
||||
}
|
||||
|
||||
else if (str_has_prefix(key, "sixel") &&
|
||||
((key_len == 6 && last_digit < 10) ||
|
||||
(key_len == 7 && key[5] == '1' && last_digit < 6)))
|
||||
{
|
||||
size_t idx = key_len == 6 ? last_digit : 10 + last_digit;
|
||||
return value_to_color(ctx, &conf->colors.sixel[idx], false);
|
||||
}
|
||||
|
||||
else if (streq(key, "flash")) color = &conf->colors.flash;
|
||||
else if (streq(key, "foreground")) color = &conf->colors.fg;
|
||||
else if (streq(key, "background")) color = &conf->colors.bg;
|
||||
|
|
@ -3247,6 +3275,7 @@ config_load(struct config *conf, const char *conf_path,
|
|||
};
|
||||
|
||||
memcpy(conf->colors.table, default_color_table, sizeof(default_color_table));
|
||||
memcpy(conf->colors.sixel, default_sixel_colors, sizeof(default_sixel_colors));
|
||||
parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers);
|
||||
|
||||
tokenize_cmdline(
|
||||
|
|
|
|||
1
config.h
1
config.h
|
|
@ -228,6 +228,7 @@ struct config {
|
|||
uint32_t url;
|
||||
|
||||
uint32_t dim[8];
|
||||
uint32_t sixel[16];
|
||||
|
||||
struct {
|
||||
uint32_t fg;
|
||||
|
|
|
|||
2
dcs.c
2
dcs.c
|
|
@ -461,7 +461,7 @@ dcs_hook(struct terminal *term, uint8_t final)
|
|||
break;
|
||||
}
|
||||
int p1 = vt_param_get(term, 0, 0);
|
||||
int p2 = vt_param_get(term, 1,0);
|
||||
int p2 = vt_param_get(term, 1, 0);
|
||||
int p3 = vt_param_get(term, 2, 0);
|
||||
|
||||
term->vt.dcs.put_handler = sixel_init(term, p1, p2, p3);
|
||||
|
|
|
|||
|
|
@ -915,6 +915,12 @@ can configure the background transparency with the _alpha_ option.
|
|||
https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit for an
|
||||
explanation of the remainder.
|
||||
|
||||
*sixel0* *..* *sixel15*
|
||||
The default sixel color palette. Default: _000000_, _3333cc_,
|
||||
_cc2121_, _33cc33_, _cc33cc_, _33cccc_, _cccc33_, _878787_,
|
||||
_424242_, _545499_, _994242_, _549954_, _995499_, _549999_,
|
||||
_999954_, _cccccc_.
|
||||
|
||||
*alpha*
|
||||
Background translucency. A value in the range 0.0-1.0, where 0.0
|
||||
means completely transparent, and 1.0 is opaque. Default: _1.0_.
|
||||
|
|
|
|||
18
foot.ini
18
foot.ini
|
|
@ -120,6 +120,24 @@
|
|||
# ...
|
||||
# 255 = <256-color palette #255>
|
||||
|
||||
## Sixel colors
|
||||
# sixel0 = 000000
|
||||
# sixel1 = 3333cc
|
||||
# sixel2 = cc2121
|
||||
# sixel3 = 33cc33
|
||||
# sixel4 = cc33cc
|
||||
# sixel5 = 33cccc
|
||||
# sixel6 = cccc33
|
||||
# sixel7 = 878787
|
||||
# sixel8 = 424242
|
||||
# sixel9 = 545499
|
||||
# sixel10 = 994242
|
||||
# sixel11 = 549954
|
||||
# sixel12 = 995499
|
||||
# sixel13 = 549999
|
||||
# sixel14 = 999954
|
||||
# sixel15 = cccccc
|
||||
|
||||
## Misc colors
|
||||
# selection-foreground=<inverse foreground/background>
|
||||
# selection-background=<inverse foreground/background>
|
||||
|
|
|
|||
43
sixel.c
43
sixel.c
|
|
@ -19,29 +19,6 @@ static size_t count;
|
|||
static void sixel_put_generic(struct terminal *term, uint8_t c);
|
||||
static void sixel_put_ar_11(struct terminal *term, uint8_t c);
|
||||
|
||||
/* VT330/VT340 Programmer Reference Manual - Table 2-3 VT340 Default Color Map */
|
||||
static const uint32_t vt340_default_colors[16] = {
|
||||
0xff000000,
|
||||
0xff3333cc,
|
||||
0xffcc2121,
|
||||
0xff33cc33,
|
||||
0xffcc33cc,
|
||||
0xff33cccc,
|
||||
0xffcccc33,
|
||||
0xff878787,
|
||||
0xff424242,
|
||||
0xff545499,
|
||||
0xff994242,
|
||||
0xff549954,
|
||||
0xff995499,
|
||||
0xff549999,
|
||||
0xff999954,
|
||||
0xffcccccc,
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(vt340_default_colors) / sizeof(vt340_default_colors[0]) == 16,
|
||||
"wrong number of elements");
|
||||
|
||||
void
|
||||
sixel_fini(struct terminal *term)
|
||||
{
|
||||
|
|
@ -105,8 +82,8 @@ sixel_init(struct terminal *term, int p1, int p2, int p3)
|
|||
term->sixel.palette_size, sizeof(term->sixel.private_palette[0]));
|
||||
|
||||
memcpy(
|
||||
term->sixel.private_palette, vt340_default_colors,
|
||||
min(sizeof(vt340_default_colors),
|
||||
term->sixel.private_palette, term->conf->colors.sixel,
|
||||
min(sizeof(term->conf->colors.sixel),
|
||||
term->sixel.palette_size * sizeof(term->sixel.private_palette[0])));
|
||||
|
||||
term->sixel.palette = term->sixel.private_palette;
|
||||
|
|
@ -117,8 +94,8 @@ sixel_init(struct terminal *term, int p1, int p2, int p3)
|
|||
term->sixel.palette_size, sizeof(term->sixel.shared_palette[0]));
|
||||
|
||||
memcpy(
|
||||
term->sixel.shared_palette, vt340_default_colors,
|
||||
min(sizeof(vt340_default_colors),
|
||||
term->sixel.shared_palette, term->conf->colors.sixel,
|
||||
min(sizeof(term->conf->colors.sixel),
|
||||
term->sixel.palette_size * sizeof(term->sixel.shared_palette[0])));
|
||||
} else {
|
||||
/* Shared palette - do *not* reset palette for new sixels */
|
||||
|
|
@ -127,12 +104,6 @@ sixel_init(struct terminal *term, int p1, int p2, int p3)
|
|||
term->sixel.palette = term->sixel.shared_palette;
|
||||
}
|
||||
|
||||
if (term->sixel.transparent_bg)
|
||||
term->sixel.default_bg = 0x00000000u;
|
||||
else
|
||||
term->sixel.default_bg = term->sixel.palette[0];
|
||||
|
||||
|
||||
count = 0;
|
||||
return pan == 1 && pad == 1 ? &sixel_put_ar_11 : &sixel_put_generic;
|
||||
}
|
||||
|
|
@ -1419,7 +1390,7 @@ resize_horizontally(struct terminal *term, int new_width_mutable)
|
|||
/* Width (and thus stride) change - need to allocate a new buffer */
|
||||
uint32_t *new_data = xmalloc(new_width * alloc_height * sizeof(uint32_t));
|
||||
|
||||
uint32_t bg = term->sixel.default_bg;
|
||||
uint32_t bg = term->sixel.transparent_bg ? 0 : term->sixel.palette[0];
|
||||
|
||||
/* Copy old rows, and initialize new columns to background color */
|
||||
const uint32_t *end = &new_data[alloc_height * new_width];
|
||||
|
|
@ -1476,7 +1447,7 @@ resize_vertically(struct terminal *term, const int new_height)
|
|||
return false;
|
||||
}
|
||||
|
||||
const uint32_t bg = term->sixel.default_bg;
|
||||
const uint32_t bg = term->sixel.transparent_bg ? 0 : term->sixel.palette[0];
|
||||
|
||||
memset_u32(&new_data[old_height * width],
|
||||
bg,
|
||||
|
|
@ -1529,7 +1500,7 @@ resize(struct terminal *term, int new_width_mutable, int new_height_mutable)
|
|||
xassert(alloc_new_height - new_height < sixel_row_height);
|
||||
|
||||
uint32_t *new_data = NULL;
|
||||
const uint32_t bg = term->sixel.default_bg;
|
||||
const uint32_t bg = term->sixel.transparent_bg ? 0 : term->sixel.palette[0];
|
||||
|
||||
/*
|
||||
* If the image is resized horizontally, or if it's opaque, we
|
||||
|
|
|
|||
|
|
@ -770,7 +770,6 @@ struct terminal {
|
|||
unsigned repeat_count;
|
||||
|
||||
bool transparent_bg;
|
||||
uint32_t default_bg;
|
||||
|
||||
/* Application configurable */
|
||||
unsigned palette_size; /* Number of colors in palette */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue