Three things the screen and the goal were getting wrong. Colours. The theme had one accent for the user and grey for everything else. theme.h now carries agent, think, tool and notice colours. A CDE palette maps them to sets 7 (answer), 3 (reasoning), 6 (tool) and 8 (status); Xresources uses colour10/11/14/13 on dark and 2/3/6/5 on light. Role colours keep their hue and are pushed from the surface only when they would disappear; each role has a slightly different minimum, so even a monochrome palette yields distinguishable steps. The 256-colour mapping now takes the nearest cube/ramp entry instead of rounding each channel down, which turned a dark orange into grey 240. Usage. sp_usage_get() only counted requests inside a declared window. A provider without limit= therefore always read "0 calls" in the sidebar, although every call was in its log. Calls are now counted when no window is declared; test_usage covers it. Goal. /goal <text> set a variable and answered "goal set" without starting a turn. The engine now starts the recap prompt: the model writes a short recap, the focus plugin remembers that answer and injects it every seventh turn (SPLINTER_FOCUS_EVERY still overrides). /recap is gone as a command; its old behaviour is what /goal does now. A palette and a wiki page are not enough to make that visible: the prompt, the confirmation entry and the sidebar goal all show up in the chat. Tests: palette role separation and indexed roles in test_theme, four unlimited calls in test_usage, recap capture/injection and the missing /recap in test_focus, and a settle delay so the UI tests type after ui_read_line() owns the keyboard. make check: all tests passed.
112 lines
3.8 KiB
C
112 lines
3.8 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, by name */
|
|
CHECK(sp_theme_list(&names, &count) == count);
|
|
CHECK(count == sp_palette_count + 1);
|
|
CHECK(count >= 41);
|
|
CHECK(strcmp(names[0], "Xresources") == 0);
|
|
for (i = 2; i < count; i++)
|
|
CHECK(strcmp(names[i - 1], names[i]) < 0);
|
|
|
|
/* the default is the X resource 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, "Xresources") == 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; 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);
|
|
}
|
|
/* 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;
|
|
}
|