The harness now has the interface it was missing: a chat pane on three quarters of the screen, a sidebar on one quarter, a status bar underneath. - vendor/netbsd-curses: NetBSD's curses and terminfo, ported edition, vendored with PROVENANCE.md. The build of that one directory needs GNU make; splinter's own Makefile stays POSIX make. - tools/genpalettes.py turns CDE's *.dp palette files into a C table. 42 palettes, generated, checked in with the generator, so the source of every colour is a file in the CDE tree and not a guess. - themes: roles are derived, not invented - background is the darkest of the eight colour sets, foreground the lightest, border the second darkest, accent the most saturated of the rest, status the accent darkened by a third. Delphinium is the default. Unknown palette is an error. - colours map to the terminal through xterm's 256-colour cube when available, the 16 basic colours otherwise, so a palette looks the same everywhere within what the terminal can show. - ui.c redraws only on change; the sidebar shows session, transport, theme and last-turn numbers. Widgets are a labelled empty area - the registry lands next. Six test binaries green, including test_theme (42 palettes, ordering invariants, unknown name rejected, colour indices in range).
77 lines
2.1 KiB
C
77 lines
2.1 KiB
C
/* splinter -- CDE theme derivation tests. */
|
|
#include <stdio.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;
|
|
int seen_delphinium = 0;
|
|
|
|
if (sp_buf_init(&err) != 0)
|
|
return 1;
|
|
|
|
/* every palette in the CDE tree is present, and sorted by name */
|
|
CHECK(sp_theme_list(&names, &count) == count);
|
|
CHECK(count == sp_palette_count);
|
|
CHECK(count >= 40);
|
|
for (i = 1; i < count; i++)
|
|
CHECK(strcmp(names[i - 1], names[i]) < 0);
|
|
|
|
/* the default is Delphinium, 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, "Delphinium") == 0);
|
|
CHECK(sp_theme_load("Delphinium", &t2, &err) == 0);
|
|
CHECK(memcmp(&t, &t2, sizeof(t)) == 0);
|
|
|
|
/* roles are derived by luminance, so bg is darker than fg in every one */
|
|
for (i = 0; i < count; i++) {
|
|
CHECK(sp_theme_load(names[i], &t, &err) == 0);
|
|
CHECK(luma(t.bg) <= luma(t.fg));
|
|
CHECK(luma(t.border) >= luma(t.bg));
|
|
CHECK(luma(t.status) <= luma(t.accent));
|
|
}
|
|
(void)seen_delphinium;
|
|
|
|
/* an unknown palette is an error, never a silent fallback */
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_theme_load("NoSuchPalette", &t, &err) == -1);
|
|
CHECK(strstr(err.p, "unknown palette") != 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;
|
|
}
|