Files
Konrad Lother 226fff3461 interview: the model opens the conversation; light is the default
--interview opened the chat and then waited: the system prompt told the model
to interview the operator, but nobody sent a turn. The UI now sends the same
kickoff the Telegram daemon sends, and with piped input --interview runs that
one turn instead of waiting for a profile.

The default theme is the flat light one, and the language is English unless a
config or SPLINTER_LOCALE says otherwise - the desktop's LANG no longer
decides what the tool speaks.
2026-11-20 16:45:36 +00:00

145 lines
5.2 KiB
C

/* splinter -- CDE theme derivation tests. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "theme.h"
#include "palettes.h"
static int failures;
#define CHECK(cond) do { \
if (!(cond)) { \
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
failures++; \
} \
} while (0)
static int
luma(const unsigned char *c)
{
return 299 * c[0] + 587 * c[1] + 114 * c[2];
}
int
main(void)
{
struct sp_theme t, t2;
struct sp_buf err;
const char **names;
size_t count, i;
if (sp_buf_init(&err) != 0)
return 1;
/* Xresources first, then every palette of the CDE tree, then the flat two */
CHECK(sp_theme_list(&names, &count) == count);
CHECK(count == sp_palette_count + 3);
CHECK(count >= 43);
CHECK(strcmp(names[0], "Xresources") == 0);
for (i = 2; i < count; i++)
CHECK(strcmp(names[i - 1], names[i]) < 0);
CHECK(strcmp(names[count - 2], "dark") == 0);
CHECK(strcmp(names[count - 1], "light") == 0);
/* the default is the flat light theme, and NULL means the default */
CHECK(sp_theme_load(NULL, &t, &err) == 0);
CHECK(strcmp(t.name, SP_THEME_DEFAULT) == 0);
CHECK(strcmp(t.name, "light") == 0);
/* a CDE palette paints with its colour sets: set 5 is the window */
CHECK(sp_theme_load("Default", &t, &err) == 0);
CHECK(strcmp(t.name, "Default") == 0);
CHECK(memcmp(t.bg, "\xc6\xb2\xa8", 3) == 0);
CHECK(memcmp(t.input_bg, "\x68\x6f\x82", 3) == 0); /* set 4 */
CHECK(t.indexed == 0);
/* names are case-blind: "default" is the CDE Default, too */
CHECK(sp_theme_load("default", &t2, &err) == 0);
CHECK(memcmp(&t, &t2, sizeof(t)) == 0);
CHECK(sp_theme_load("Delphinium", &t2, &err) == 0);
/* in every palette the text stands off its surface (CDE's black/white) */
for (i = 1; i < count - 2; i++) {
CHECK(sp_theme_load(names[i], &t, &err) == 0);
CHECK(abs(luma(t.fg) - luma(t.bg)) >= 100000 ||
luma(t.bg) == luma(t.fg));
CHECK(abs(luma(t.input_fg) - luma(t.input_bg)) >= 100000 ||
luma(t.input_bg) == luma(t.input_fg));
/* every role colour stands off the chat surface */
CHECK(abs(luma(t.accent) - luma(t.bg)) >= 30000);
CHECK(abs(luma(t.agent) - luma(t.bg)) >= 32000);
CHECK(abs(luma(t.think) - luma(t.bg)) >= 28000);
CHECK(abs(luma(t.tool) - luma(t.bg)) >= 34000);
CHECK(abs(luma(t.notice) - luma(t.bg)) >= 36000);
}
/*
* The flat themes: the operator asked for the simple thing. The chat
* and the sidebar share one page colour (white/black), the text is the
* opposite, the input keeps the same page, and only the status line is
* allowed to be a different surface.
*/
CHECK(sp_theme_load("light", &t, &err) == 0);
CHECK(strcmp(t.name, SP_THEME_LIGHT) == 0);
CHECK(memcmp(t.bg, "\xff\xff\xff", 3) == 0);
CHECK(memcmp(t.fg, "\x00\x00\x00", 3) == 0);
CHECK(memcmp(t.input_bg, t.bg, 3) == 0);
CHECK(memcmp(t.input_fg, t.fg, 3) == 0);
CHECK(memcmp(t.status, t.bg, 3) != 0);
CHECK(memcmp(t.status_fg, t.fg, 3) == 0);
CHECK(t.indexed == 0);
CHECK(sp_theme_load("Light", &t2, &err) == 0);
CHECK(strcmp(t2.name, SP_THEME_LIGHT) == 0);
CHECK(sp_theme_load("dark", &t, &err) == 0);
CHECK(strcmp(t.name, SP_THEME_DARK) == 0);
CHECK(memcmp(t.bg, "\x00\x00\x00", 3) == 0);
CHECK(memcmp(t.fg, "\xeb\xeb\xeb", 3) == 0);
CHECK(memcmp(t.input_bg, t.bg, 3) == 0);
CHECK(memcmp(t.input_fg, t.fg, 3) == 0);
CHECK(memcmp(t.status, t.bg, 3) != 0);
/* role text is legible on the page in both directions */
CHECK(luma(t.accent) - luma(t.bg) >= 50000);
CHECK(luma(t.agent) - luma(t.bg) >= 50000);
CHECK(luma(t.tool) - luma(t.bg) >= 50000);
CHECK(sp_theme_load("LIGHT", &t2, &err) == 0);
CHECK(memcmp(t2.bg, "\xff\xff\xff", 3) == 0);
/* X resources: the tight binding wins, 48-bit colours are read */
CHECK(sp_theme_from_xrdb("*.background:\t#6e1e7d\n"
"*.foreground:\t#acdcb4\n*.color12:\t#7f6c6c\n"
"*background:\t#B8B86F6F4B4B\n*foreground:\t#FFFFFFFFFFFF\n"
"URxvt.background: #000000\n", &t) == 0);
CHECK(t.indexed == 0);
CHECK(memcmp(t.bg, "\x6e\x1e\x7d", 3) == 0);
CHECK(memcmp(t.fg, "\xac\xdc\xb4", 3) == 0);
CHECK(sp_theme_from_xrdb("*background: #B8B86F6F4B4B\n", &t) == 0);
CHECK(memcmp(t.bg, "\xb8\x6f\x4b", 3) == 0);
CHECK(sp_theme_from_xrdb("*background: rgb:1d/1f/21\n", &t) == 0);
CHECK(memcmp(t.bg, "\x1d\x1f\x21", 3) == 0);
/* no resources: the terminal's own colours, by index */
CHECK(sp_theme_from_xrdb(NULL, &t) == 0);
CHECK(t.indexed == 1);
CHECK(t.idx_agent == 10 && t.idx_think == 11);
CHECK(t.idx_tool == 14 && t.idx_notice == 13);
CHECK(sp_theme_from_xrdb("URxvt.background: #000000\n", &t) == 0);
CHECK(t.indexed == 1);
/* an unknown theme is an error, never a silent fallback */
sp_buf_clear(&err);
CHECK(sp_theme_load("NoSuchPalette", &t, &err) == -1);
CHECK(strstr(err.p, "unknown theme") != NULL);
/* colour mapping stays inside the terminal's palette */
CHECK(sp_color_rgb(0, 0, 0, 256) >= 16);
CHECK(sp_color_rgb(0, 0, 0, 256) <= 255);
CHECK(sp_color_rgb(255, 255, 255, 256) >= 16);
CHECK(sp_color_rgb(255, 255, 255, 256) <= 255);
CHECK(sp_color_rgb(0, 0, 0, 8) >= 0 && sp_color_rgb(0, 0, 0, 8) < 8);
CHECK(sp_color_rgb(255, 255, 255, 16) >= 0);
CHECK(sp_color_rgb(255, 255, 255, 16) < 16);
sp_buf_free(&err);
if (failures == 0)
printf("test_theme: ok (%zu palettes)\n", count);
return failures == 0 ? 0 : 1;
}