diff --git a/.gitignore b/.gitignore index ca994cf..d60d237 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,7 @@ tests/test_* # python bytecode from the test helpers __pycache__/ src/catalogs.c + +# Claude Code worktrees and local session state +.claude/ +.splinter-swarm.sock diff --git a/README.md b/README.md index 4d4eacd..7a1b73c 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Named after Master Splinter: the one who knows which tools exist, who may use them, and what happened — and trains the ones that do the fighting. -A C99/POSIX agent harness with a curses interface: chat on three quarters of -the screen, a sidebar on one quarter, plugins that can put tools and widgets -into both. +A C99/POSIX agent harness with a curses interface: one text field that starts +clear at the top and only ever grows, the prompt below it, and plugins that can +add tools and publish widget lines. make # libsplinter.so, the binary, the plugins make check # the tests, no network, no model @@ -58,12 +58,12 @@ transport replays replies. src/openai.c request shaping + reply parsing, pure functions src/transport_openai.c HTTP to /v1/chat/completions via curl(1) src/json.c libmcp's JSON, instantiated once - src/ui.c curses UI: chat 3/4, sidebar 1/4, status bar + src/ui.c curses UI: one transcript, one input line src/md.c markdown tables as aligned text src/theme.c CDE palettes -> terminal colours src/palettes.c generated from CDE's *.dp files tools/genpalettes.py the generator - plugins/clock/ example plugin: sidebar clock + a tool + plugins/clock/ example plugin: a clock widget line + a tool vendor/netbsd-curses/ NetBSD curses and terminfo, vendored docs/PLUGINS.md the ABI, the threading rules src/buf.c growable buffer, JSON escaping @@ -81,14 +81,21 @@ transport replays replies. A plugin is a `.so` against `libsplinter.so`, exporting `sp_plugin_describe()`. It can register tools (with authorization classes the -loop enforces) and widgets (rendered in the sidebar). A widget's `tick()` runs -on its own thread and publishes text; only the UI thread draws. See -`docs/PLUGINS.md`. +loop enforces) and widgets. A widget's `tick()` runs on its own thread and +publishes a line of text; `/widgets` shows those lines in the transcript, so a +plugin never needs screen space of its own. See `docs/PLUGINS.md`. -Themes are CDE palettes: 42 of them, generated from the desktop's own `.dp` -files. Roles are derived from the eight colour sets — darkest is the -background, lightest the foreground, the most saturated the accent. Default is -Delphinium. `--list-themes` prints the names, `--theme NAME` picks one. +The default theme is `Xresources`: it takes `*foreground`, `*background` and +`*color0`..`*color15` from `xrdb -query` (or `~/.Xresources` without X) and +paints the UI with them, so the harness looks like the terminal it runs in. +Without any of those resources it keeps the terminal's own colour indices. + +Every CDE palette from the desktop's `.dp` files is a theme as well, 43 of them +including `Default` and `MakroSlate`. A palette is used the way the desktop +uses it: set 5 is the chat background, set 4 the input area, set 6 hints, set 1 +the user's lines and set 2 secondary text, with black or white text by CDE's +own rule. `--list-themes` prints the names, `--theme NAME` picks one, and +`theme = NAME` in the config makes it the default. ## Talking to a model @@ -205,9 +212,9 @@ window, pools that balance or fail over) and agent profiles are in ## Streaming Answers arrive as they are produced, not as one block: the adapter reads SSE, -turns text deltas into the chat pane and tool-call starts into the sidebar, and -a reasoning model's own `reasoning_content` is shown dimmed one line above the -answer instead of being hidden. In one-shot mode the text goes straight to +appends text deltas to the transcript as they arrive and a tool call as its own +line, and a reasoning model's own `reasoning_content` is shown dimmed, in +sequence, instead of being hidden. In one-shot mode the text goes straight to stdout as it comes. Both directions are covered by `test_sse`, which feeds recorded lines: plain @@ -216,11 +223,11 @@ data line, and the keepalive lines that carry nothing. ## Colour, measured -A CDE palette is eight mid-tones; painted literally, the accent sat 8% away -from the background and nothing was readable. Two fixes, both in `init_colors`: -the background is darkened until it is a terminal background, and every role is -pushed away from it until it is legible. Delphinium ends up with a white-on-slate -text contrast of 14:1, accents at 7.7:1 and labels at 4.7:1 instead of ~1.1:1. +A CDE palette is eight mid-tones; painted literally, the accent can sit 8% away +from the background, and nothing is readable. Two safeguards live in +`theme.c`: text on a surface follows CDE's rule (black on light, white on +dark), and a role that is too close to the background is pushed away from it +until it is legible. `Xresources` themes are used as they are. The other half was a real bug: `COLORS` was read before `start_color()`, so it was 0, the code took the eight-basic-colour path, and the whole palette diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 2e824e0..86865e0 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -24,7 +24,7 @@ harness will not start. An error names the line you wrote. ``` core { default = main # a provider or a pool, below - theme = Delphinium + theme = Xresources autonomous = true steps = 60 on_limit = wait # a usage limit is waited out (or: fail) @@ -123,8 +123,9 @@ Without `-m`, `default` in `core` decides. ## Agent profiles: build, plan and your own Tab in the chat (Shift-Tab back) switches the agent profile, like opencode. -The status line shows it (`[plan]`), `/agent` lists them, `/agent NAME` picks -one, `splinter --agent NAME` starts in one and `--agent-list` prints them. +The prompt carries the name (`plan> `), the transcript notes the switch, +`/agent` lists them, `/agent NAME` picks one, `splinter --agent NAME` starts in +one and `--agent-list` prints them. - `build` is the default: every tool. - `plan` reads, searches and analyses, changes nothing (tools of the class @@ -229,7 +230,7 @@ lies about what it does. | `transport` | a transport a plugin provides, e.g. `cli` | | `cli_cmd` | command for the `cli` transport, e.g. `claude -p` | | `plugin` | a plugin to load, one line each; absolute paths survive a `cd` | -| `theme` | CDE palette name (`splinter --list-themes`) | +| `theme` | `Xresources` (the default: `*foreground`, `*background`, `*color0..15` from `xrdb`) or a CDE palette name (`splinter --list-themes`) | | `locale` | language code (`de`, `en`); catalogues live in `share/locale` | | `autonomous` | `1` runs mutating/destructive tools without asking | | `steps` | tool rounds per turn (default 150) | @@ -290,8 +291,8 @@ delegate = cloud | ollama.com | endpoint=... | model=... | tags=code | toke What it does with that: -- the status line shows how full each allowance is (`claude-a 5h 62%`), a - benched one shows when it is back; `/usage` lists all with bars; +- `/usage` shows how full each allowance is (`claude-a 5h 62%`), a benched + one shows when it is back; - delegation skips a provider whose allowance is used up, and among providers that fit the task equally well (same tags: a pool of accounts) it takes the one with the most left; @@ -358,8 +359,8 @@ it is never in `ps`. A literal token in the file is a secret in the file: Tool names: with one server they are `mcp_`; with several they are `mcp__`, so two servers that both offer `search` stay apart. They are all in the `mutate` class - a server can do anything, and the harness does -not pretend to know better. The sidebar widget shows how many tools came back -and says so when a server stops answering. +not pretend to know better. Its widget line says how many tools came back and +when a server stops answering; `/widgets` shows it. The handshake is `initialize` + `notifications/initialized` + `tools/list`; a server that fails it is reported and skipped, and the others still load. The @@ -371,7 +372,7 @@ single-server environment variable from before still works: ``` endpoint = http://127.0.0.1:8080/v1 model = /models/unsloth/Qwen3.6-35B-A3B-MTP-GGUF/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf -theme = Delphinium +theme = Xresources autonomous = 1 plugin = /home/lotherk/src/splinter/plugins/lcm/lcm.so plugin = /home/lotherk/src/splinter/plugins/cps/cps.so @@ -386,7 +387,7 @@ transport = cli cli_cmd = claude -p cli_timeout = 1800 plugin = /home/lotherk/src/splinter/plugins/cli/cli.so -theme = Delphinium +theme = Xresources ``` `cli_env = NAME=VALUE` (repeatable, up to 8) sets a variable for the cli diff --git a/plugins/status/status.c b/plugins/status/status.c index bf4962b..a57e56c 100644 --- a/plugins/status/status.c +++ b/plugins/status/status.c @@ -8,6 +8,10 @@ * * clock: 17:20:01 | ctx 12.3k/32k [|||||||...] | 41 tok/s | 1.2k tok | $0.0042 * + * The line is not painted by the UI (one text field has no status bar): the + * segments go to sp_host_add_status(), which /status shows in the transcript + * and the Telegram gateway sends with its replies. + * * The numbers come from the harness (struct sp_meter), never from the plugin * counting for itself: two counters that disagree are worse than none. * diff --git a/share/locale/de.msg b/share/locale/de.msg index aba47e6..cdc7403 100644 --- a/share/locale/de.msg +++ b/share/locale/de.msg @@ -23,6 +23,7 @@ role.error = fehler cmd.unknown = unbekanntes Kommando: /%s cmd.available = verfuegbar: +widgets.none = kein Plugin hat eine Widget-Zeile veröffentlicht err.oom = kein Speicher err.theme = Farbschema diff --git a/share/locale/en.msg b/share/locale/en.msg index 7cdd5b0..3b6e3c3 100644 --- a/share/locale/en.msg +++ b/share/locale/en.msg @@ -22,6 +22,7 @@ role.error = error cmd.unknown = unknown command: /%s cmd.available = available: +widgets.none = no plugin published a widget line err.oom = out of memory err.theme = theme diff --git a/share/locale/pt_BR.msg b/share/locale/pt_BR.msg index e4943e6..e42f9ea 100644 --- a/share/locale/pt_BR.msg +++ b/share/locale/pt_BR.msg @@ -29,6 +29,7 @@ role.diff = alteracao cmd.unknown = comando desconhecido: /%s cmd.available = disponiveis: +widgets.none = nenhum plugin publicou uma linha de widget err.oom = sem memoria err.theme = tema diff --git a/src/main.c b/src/main.c index 1185737..3a7eb9d 100644 --- a/src/main.c +++ b/src/main.c @@ -67,7 +67,8 @@ usage(FILE *f) " --kind NAME vendor shape of --endpoint: openai (default)\n" " or anthropic\n" " --chat interactive curses UI instead of one turn\n" - " --theme NAME CDE palette for the UI (default Delphinium)\n" + " --theme NAME UI theme: Xresources (default) or a CDE\n" + " palette, e.g. Default, Delphinium, MakroSlate\n" " --list-themes print the palette names and exit\n" " --resume load the session's history into the conversation\n" " --choose TEXT print which delegate fits TEXT, then exit\n" diff --git a/src/theme.c b/src/theme.c index 2ec1bef..2ff0001 100644 --- a/src/theme.c +++ b/src/theme.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "theme.h" #include "palettes.h" @@ -18,20 +19,15 @@ luma(const unsigned char *c) return 299 * c[0] + 587 * c[1] + 114 * c[2]; } -static int -saturation(const unsigned char *c) -{ - int hi = c[0], lo = c[0]; +#define LIGHT 127500 /* luma above this: a light surface, black text */ - if (c[1] > hi) - hi = c[1]; - if (c[2] > hi) - hi = c[2]; - if (c[1] < lo) - lo = c[1]; - if (c[2] < lo) - lo = c[2]; - return hi - lo; +/* CDE's rule for the text on a colour set: black on light, white on dark */ +static void +cde_fg(const unsigned char bg[3], unsigned char fg[3]) +{ + unsigned char v = luma(bg) > LIGHT ? 0 : 255; + + fg[0] = fg[1] = fg[2] = v; } static const struct sp_palette * @@ -40,78 +36,286 @@ find_palette(const char *name) size_t i; for (i = 0; i < sp_palette_count; i++) { - if (strcmp(sp_palettes[i].name, name) == 0) + if (strcasecmp(sp_palettes[i].name, name) == 0) return &sp_palettes[i]; } return NULL; } +/* the roles of a CDE palette, by the colour set the desktop uses for each */ +static void +load_cde(const struct sp_palette *p, struct sp_theme *out) +{ + memset(out, 0, sizeof(*out)); + out->name = p->name; + memcpy(out->bg, p->c[4], 3); /* set 5: main windows */ + cde_fg(out->bg, out->fg); + memcpy(out->accent, p->c[0], 3); /* set 1: active frame */ + memcpy(out->border, p->c[1], 3); /* set 2: inactive frame */ + memcpy(out->input_bg, p->c[3], 3); /* set 4: text areas */ + cde_fg(out->input_bg, out->input_fg); + memcpy(out->status, p->c[5], 3); /* set 6: dialogs, menus */ + cde_fg(out->status, out->status_fg); + if (luma(out->bg) > LIGHT) { + out->error[0] = 0xa0; out->error[1] = 0x10; out->error[2] = 0x10; + } else { + out->error[0] = 0xff; out->error[1] = 0x70; out->error[2] = 0x70; + } + /* a frame colour as text on the window colour: legible, or pushed */ + sp_color_separate(out->accent, out->bg, 70000); + sp_color_separate(out->border, out->bg, 50000); + sp_color_separate(out->error, out->bg, 60000); +} + +/* "#rgb", "#rrggbb", "#rrrrggggbbbb" or "rgb:r/g/b"; 0 when it is none */ +static int +parse_color(const char *v, unsigned char c[3]) +{ + unsigned int x[3]; + size_t n, i, w; + char part[8]; + + while (*v == ' ' || *v == '\t') + v++; + if (strncmp(v, "rgb:", 4) == 0) { + const char *q = v + 4; + + for (i = 0; i < 3; i++) { + n = strspn(q, "0123456789abcdefABCDEF"); + if (n == 0 || n > 4) + return 0; + memcpy(part, q, n); + part[n] = '\0'; + x[i] = (unsigned int)strtoul(part, NULL, 16); + /* scale 1..4 hex digits to 8 bits */ + x[i] = (unsigned int)(x[i] * 255 / ((1u << (4 * n)) - 1)); + q += n; + if (i < 2 && *q++ != '/') + return 0; + } + } else if (*v == '#') { + v++; + n = strspn(v, "0123456789abcdefABCDEF"); + if (n != 3 && n != 6 && n != 12) + return 0; + w = n / 3; + for (i = 0; i < 3; i++) { + memcpy(part, v + i * w, w); + part[w] = '\0'; + x[i] = (unsigned int)strtoul(part, NULL, 16); + x[i] = (unsigned int)(x[i] * 255 / ((1u << (4 * w)) - 1)); + } + } else + return 0; + for (i = 0; i < 3; i++) + c[i] = (unsigned char)x[i]; + return 1; +} + +/* + * One resource line: "*background:\t#1d1f21". Only the generic names count + * ("*name" or "*.name"); "URxvt.background" belongs to one program. + */ +static int +xrdb_line(const char *line, char *name, size_t ncap, const char **val, + int *tight) +{ + const char *colon = strchr(line, ':'); + size_t n; + + if (line[0] != '*' || colon == NULL) + return 0; + line++; + *tight = *line == '.'; + if (*tight) + line++; + n = (size_t)(colon - line); + while (n > 0 && (line[n - 1] == ' ' || line[n - 1] == '\t')) + n--; + if (n == 0 || n >= ncap || memchr(line, '.', n) != NULL || + memchr(line, '*', n) != NULL) + return 0; + memcpy(name, line, n); + name[n] = '\0'; + *val = colon + 1; + return 1; +} + +int +sp_theme_from_xrdb(const char *text, struct sp_theme *out) +{ + unsigned char col[16][3], fg[3], bg[3]; + int have[16], hfg = 0, hbg = 0, any = 0, i, dark, tight; + /* + * "*.background" beats "*background" (a tight binding is the closer + * match), whatever order the lines come in -- xrdb -query sorts them. + * have/hfg/hbg: 0 none, 1 from a loose line, 2 from a tight one. + */ + const char *p = text; + + memset(out, 0, sizeof(*out)); + memset(have, 0, sizeof(have)); + out->name = SP_THEME_XRESOURCES; + while (p != NULL && *p != '\0') { + const char *nl = strchr(p, '\n'), *val; + char line[512], name[64]; + size_t n = nl != NULL ? (size_t)(nl - p) : strlen(p); + + if (n >= sizeof(line)) + n = sizeof(line) - 1; + memcpy(line, p, n); + line[n] = '\0'; + p = nl != NULL ? nl + 1 : NULL; + if (!xrdb_line(line, name, sizeof(name), &val, &tight)) + continue; + if (strcasecmp(name, "foreground") == 0) { + if (hfg < 1 + tight && parse_color(val, fg)) + hfg = 1 + tight; + } else if (strcasecmp(name, "background") == 0) { + if (hbg < 1 + tight && parse_color(val, bg)) + hbg = 1 + tight; + } else if (strncasecmp(name, "color", 5) == 0 && + name[5] >= '0' && name[5] <= '9') { + int k = atoi(name + 5); + unsigned char c[3]; + + if (k >= 0 && k < 16 && have[k] < 1 + tight && + parse_color(val, c)) { + memcpy(col[k], c, 3); + have[k] = 1 + tight; + any = 1; + } + } + if (hfg || hbg) + any = 1; + } + if (!any) { + /* the terminal's own colours, by index: its palette shows */ + out->indexed = 1; + out->idx_fg = 7; + out->idx_bg = 0; + out->idx_border = 8; + out->idx_accent = 12; + out->idx_error = 9; + return 0; + } + if (!hbg) { + if (have[0]) + memcpy(bg, col[0], 3); + else + memset(bg, 0, 3); + } + if (!hfg) { + if (have[7]) + memcpy(fg, col[7], 3); + else + memset(fg, 0xc0, 3); + } + dark = luma(bg) <= LIGHT; + memcpy(out->bg, bg, 3); + memcpy(out->fg, fg, 3); + memcpy(out->input_bg, bg, 3); + memcpy(out->input_fg, fg, 3); + /* the bright blue on a dark background, the plain one on a light one */ + i = dark ? (have[12] ? 12 : 4) : (have[4] ? 4 : 12); + if (have[i]) + memcpy(out->accent, col[i], 3); + else + memcpy(out->accent, fg, 3); + i = have[8] ? 8 : 7; + if (have[i]) + memcpy(out->border, col[i], 3); + else + memcpy(out->border, fg, 3); + i = dark ? (have[9] ? 9 : 1) : (have[1] ? 1 : 9); + if (have[i]) + memcpy(out->error, col[i], 3); + else { + out->error[0] = 0xff; out->error[1] = 0x50; out->error[2] = 0x50; + } + i = dark ? (have[8] ? 8 : 0) : (have[7] ? 7 : 15); + if (have[i]) + memcpy(out->status, col[i], 3); + else + memcpy(out->status, fg, 3); + memcpy(out->status_fg, fg, 3); + sp_color_separate(out->status_fg, out->status, 90000); + sp_color_separate(out->accent, out->bg, 50000); + sp_color_separate(out->border, out->bg, 40000); + sp_color_separate(out->error, out->bg, 50000); + return 0; +} + +/* the resource text: the X server's database, or the file it is loaded from */ +static char * +xrdb_text(void) +{ + struct sp_buf b; + char chunk[4096], path[700]; + const char *home = getenv("HOME"); + FILE *f = NULL; + size_t n; + int k; + + if (sp_buf_init(&b) != 0) + return NULL; + if (getenv("DISPLAY") != NULL && *getenv("DISPLAY") != '\0') { + f = popen("xrdb -query 2>/dev/null 0) + (void)sp_buf_add(&b, chunk, n); + (void)pclose(f); + } + } + for (k = 0; b.len == 0 && home != NULL && k < 2; k++) { + snprintf(path, sizeof(path), "%s/%s", home, + k == 0 ? ".Xresources" : ".Xdefaults"); + if ((f = fopen(path, "r")) == NULL) + continue; + while ((n = fread(chunk, 1, sizeof(chunk), f)) > 0) + (void)sp_buf_add(&b, chunk, n); + fclose(f); + } + if (b.len == 0) { + sp_buf_free(&b); + return NULL; + } + return b.p; /* the caller frees it */ +} + int sp_theme_load(const char *name, struct sp_theme *out, struct sp_buf *err) { const struct sp_palette *p; - int order[8], i, j; - int darkest, lightest, second, accent; - int best; if (name == NULL || *name == '\0') name = SP_THEME_DEFAULT; + if (strcasecmp(name, SP_THEME_XRESOURCES) == 0) { + char *text = xrdb_text(); + int rc = sp_theme_from_xrdb(text, out); + + free(text); + return rc; + } p = find_palette(name); if (p == NULL) { - sp_buf_printf(err, "theme: unknown palette '%s' (%zu known)", - name, sp_palette_count); + sp_buf_printf(err, "theme: unknown theme '%s' (Xresources or " + "one of %zu CDE palettes; --list-themes)", name, + sp_palette_count); return -1; } - - for (i = 0; i < 8; i++) - order[i] = i; - for (i = 1; i < 8; i++) { - int v = order[i]; - - for (j = i - 1; j >= 0 && luma(p->c[order[j]]) > luma(p->c[v]); - j--) - order[j + 1] = order[j]; - order[j + 1] = v; - } - - darkest = order[0]; - lightest = order[7]; - second = order[1]; - - accent = -1; - best = -1; - for (i = 0; i < 8; i++) { - int idx = order[i], s; - - if (idx == darkest || idx == lightest || idx == second) - continue; - s = saturation(p->c[idx]); - if (s > best) { - best = s; - accent = idx; - } - } - if (accent < 0) - accent = lightest; /* a fully grey palette has no accent */ - - memset(out, 0, sizeof(*out)); - out->name = p->name; - memcpy(out->bg, p->c[darkest], 3); - memcpy(out->fg, p->c[lightest], 3); - memcpy(out->border, p->c[second], 3); - memcpy(out->accent, p->c[accent], 3); - for (i = 0; i < 3; i++) - out->status[i] = (unsigned char)(p->c[accent][i] * 2 / 3); + load_cde(p, out); return 0; } size_t sp_theme_list(const char ***names, size_t *count) { - static const char *list[256]; + static const char *list[257]; size_t i, n = 0; - for (i = 0; i < sp_palette_count && n < 256; i++) + list[n++] = SP_THEME_XRESOURCES; + for (i = 0; i < sp_palette_count && n < 257; i++) list[n++] = sp_palettes[i].name; *names = list; *count = n; diff --git a/src/theme.h b/src/theme.h index 9340755..5ec8b63 100644 --- a/src/theme.h +++ b/src/theme.h @@ -1,20 +1,28 @@ /* - * splinter -- CDE palettes as terminal themes. + * splinter -- themes: the X resources, or a CDE palette. * * Copyright (c) 2026 Konrad Lother * SPDX-License-Identifier: BSD-3-Clause * - * A CDE palette is eight colour sets, not a set of named roles. Roles are - * therefore derived, not looked up, and the derivation is stated so it can be - * checked: + * Two kinds of theme. * - * background darkest of the eight - * foreground lightest of the eight - * border second darkest - * accent the most saturated of the remaining six - * status the accent, darkened by a third (a bar has to read as a bar) + * "Xresources" (the default) takes *foreground, *background and *color0..15 + * from the X resource database (xrdb -query). Without X, or without those + * resources, it uses the terminal's own colour indices 0..15 -- which are + * the same resources in an X terminal. * - * The default palette is Delphinium, the CDE desktop default. + * A CDE palette is eight colour sets, numbered by what the desktop paints with + * them (dtstyle, "High Color" use): + * + * set 1 active window frame -> accent (the user's own lines) + * set 2 inactive window frame -> secondary text + * set 4 text and list areas -> the input line + * set 5 main window background -> the chat background + * set 6 dialogs and menus -> hints and questions + * + * The foreground on each surface follows CDE's rule: black on a light colour, + * white on a dark one. Colours that a terminal cannot tell apart from their + * background are pushed apart -- that is the one liberty taken with a palette. */ #ifndef SPLINTER_THEME_H #define SPLINTER_THEME_H @@ -25,30 +33,45 @@ struct sp_theme { const char *name; - unsigned char bg[3]; - unsigned char fg[3]; - unsigned char border[3]; - unsigned char accent[3]; - unsigned char status[3]; + unsigned char bg[3]; /* the chat background */ + unsigned char fg[3]; /* text on it */ + unsigned char border[3]; /* secondary text: labels, tool lines */ + unsigned char accent[3]; /* the user's lines */ + unsigned char error[3]; /* errors */ + unsigned char input_bg[3]; /* the input line */ + unsigned char input_fg[3]; + unsigned char status[3]; /* hint and question surface */ + unsigned char status_fg[3]; + /* + * 1: no RGB is known (no X resources): every role is a terminal colour + * index in idx[], so the terminal's own palette shows. + */ + int indexed; + short idx_fg, idx_bg, idx_border, idx_accent, idx_error; }; -#define SP_THEME_DEFAULT "Delphinium" +#define SP_THEME_DEFAULT "Xresources" +#define SP_THEME_XRESOURCES "Xresources" -/* Load a palette by name; NULL selects the default. Returns 0 or -1. */ +/* Load a theme by name; NULL selects the default. Returns 0 or -1. */ int sp_theme_load(const char *name, struct sp_theme *out, struct sp_buf *err); -/* List palette names, alphabetical. Returns the number written. */ +/* + * The same for the X resource theme, from resource text as xrdb -query prints + * it ("*background:\t#1d1f21"); NULL text means "none found". For the tests. + */ +int sp_theme_from_xrdb(const char *text, struct sp_theme *out); + +/* List theme names: "Xresources", then the palettes, alphabetical. */ size_t sp_theme_list(const char ***names, size_t *count); -/* - * Push a colour until it is at least `min_delta` away (in luma) from `ref`, - * toward white or black depending on which side it already is. A palette that - * is all mid-tones is a nice idea on a 1995 desktop and unreadable in a - * terminal; this is the rule that keeps it legible. - */ /* Scale a colour toward black until its luma is at most `target`. */ void sp_color_darken(unsigned char c[3], int target); +/* + * Push a colour until it is at least `min_delta` away (in luma) from `ref`, + * toward white or black depending on which side it already is. + */ void sp_color_separate(unsigned char c[3], const unsigned char ref[3], int min_delta); diff --git a/src/ui.c b/src/ui.c index 3d9255a..8ce3876 100644 --- a/src/ui.c +++ b/src/ui.c @@ -121,13 +121,20 @@ static WINDOW *ui_hist; static WINDOW *ui_side; static WINDOW *ui_input; static WINDOW *ui_status; +/* + * The agent whose profile is active. The sidebar used to show it; with one + * text field the prompt carries the name, so "build> " says what Tab did. + */ +static char ui_agent[32]; enum { PAIR_MAIN = 1, /* fg on bg */ PAIR_ACCENT, /* accent on bg */ PAIR_DIM, /* border on bg */ - PAIR_STATUS /* bg on status */ + PAIR_STATUS, /* hints and questions */ + PAIR_INPUT, /* the input line */ + PAIR_ERROR /* errors */ }; @@ -443,65 +450,46 @@ turn_thread(void *arg) } /* - * Colour assignment, and the reasoning behind it: - * - * The terminal background stays the terminal's own (-1). Painting every glyph - * on a palette colour looks like a 1995 desktop and is unreadable in a modern - * terminal - it also fights whatever scheme the user already chose. The palette - * supplies the accents, which is where its character is, and every accent is - * pushed until it is legible against black (the usual terminal background). - */ -/* - * Colour assignment. - * - * Two facts drive this: - * 1. this curses port reports COLORS=256 but does not honour -1 in - * init_pair(), so "terminal default" is not available - every pair needs - * real indices, and a failed init_pair silently leaves white on black; - * 2. a CDE palette is eight mid-tones. Painted literally, the accent sits - * 8% away from the background and nobody can read it. - * - * So the palette paints, and every role is pushed away from the background - * until it is legible: foreground far, accent very far, secondary text at - * least visible. + * Colour assignment: the theme paints (theme.h says which role comes from + * where). This curses port does not honour -1 in init_pair(), so every pair + * gets real indices; an X resource theme without RGB uses the terminal's own + * indices 0..15, which is the same palette. */ +static short +rgb(const unsigned char c[3], short n) +{ + return sp_color_rgb(c[0], c[1], c[2], n); +} + static void init_colors(const struct sp_theme *t) { - unsigned char bg[3], fg[3], accent[3], dim[3], status_bg[3]; - short n; + short n; if (!has_colors()) return; - /* COLORS is only valid after start_color(); reading it earlier gave 0, - * which silently fell back to the eight basic colours - the whole palette - * collapsed to white on black. */ + /* COLORS is only valid after start_color() */ start_color(); n = (short)(COLORS > 0 ? COLORS : 8); + if (t->indexed) { + short accent = n >= 16 ? t->idx_accent : COLOR_BLUE; + short dim = n >= 16 ? t->idx_border : COLOR_WHITE; + short errc = n >= 16 ? t->idx_error : COLOR_RED; - memcpy(bg, t->bg, 3); - /* the darkest CDE colour is still a mid-tone: no terminal wants that */ - sp_color_darken(bg, 45000); - memcpy(fg, t->fg, 3); - memcpy(accent, t->accent, 3); - memcpy(dim, t->border, 3); - memcpy(status_bg, t->status, 3); - - sp_color_separate(fg, bg, 120000); /* text */ - sp_color_separate(accent, bg, 100000); /* the user's own lines */ - sp_color_separate(dim, bg, 60000); /* labels: visible, not loud */ - sp_color_darken(status_bg, 60000); /* the bar is a surface, not text */ - - /* the chat area is black: text on a palette surface reads as a block of - * colour, and the operator asked for black, not for a tinted pane */ - init_pair(PAIR_MAIN, sp_color_rgb(fg[0], fg[1], fg[2], n), COLOR_BLACK); - init_pair(PAIR_ACCENT, sp_color_rgb(accent[0], accent[1], accent[2], n), - COLOR_BLACK); - init_pair(PAIR_DIM, sp_color_rgb(dim[0], dim[1], dim[2], n), - COLOR_BLACK); - init_pair(PAIR_STATUS, - sp_color_rgb(fg[0], fg[1], fg[2], n), - sp_color_rgb(status_bg[0], status_bg[1], status_bg[2], n)); + init_pair(PAIR_MAIN, t->idx_fg, t->idx_bg); + init_pair(PAIR_ACCENT, accent, t->idx_bg); + init_pair(PAIR_DIM, dim, t->idx_bg); + init_pair(PAIR_STATUS, t->idx_bg, t->idx_fg); + init_pair(PAIR_INPUT, t->idx_fg, t->idx_bg); + init_pair(PAIR_ERROR, errc, t->idx_bg); + return; + } + init_pair(PAIR_MAIN, rgb(t->fg, n), rgb(t->bg, n)); + init_pair(PAIR_ACCENT, rgb(t->accent, n), rgb(t->bg, n)); + init_pair(PAIR_DIM, rgb(t->border, n), rgb(t->bg, n)); + init_pair(PAIR_STATUS, rgb(t->status_fg, n), rgb(t->status, n)); + init_pair(PAIR_INPUT, rgb(t->input_fg, n), rgb(t->input_bg, n)); + init_pair(PAIR_ERROR, rgb(t->error, n), rgb(t->bg, n)); } /* @@ -1195,7 +1183,7 @@ draw_history(struct ui_state *s, int reserve) else if (strcmp(e->role, "agent") == 0) wattrset(ui_hist, COLOR_PAIR(PAIR_MAIN)); else if (strcmp(e->role, "error") == 0) - wattrset(ui_hist, COLOR_PAIR(PAIR_ACCENT) | A_BOLD); + wattrset(ui_hist, COLOR_PAIR(PAIR_ERROR) | A_BOLD); else wattrset(ui_hist, COLOR_PAIR(PAIR_DIM)); if (lay[idx].blank) { @@ -1277,6 +1265,9 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir, char key[64]; const char *act = sp_usage_active(); + if (ui_side == NULL) + return; /* one text field: no sidebar */ + (void)dir; cols = getmaxx(ui_side); werase(ui_side); @@ -1460,15 +1451,18 @@ usage_line(struct ui_state *s, char *buf, size_t cap) static void draw_status(struct ui_state *s, const char *running) { - int cols = getmaxx(ui_status); + int cols; int at = 1 + (int)strlen("splinter") + 1 + (int)strlen(SP_VERSION) + 2; char swbuf[128]; swbuf[0] = '\0'; if (s->sw != NULL && s->sw->role != SWARM_NONE) { - swarm_poll(s->sw); + swarm_poll(s->sw); /* the swarm moves on, bar or no bar */ swarm_status(s->sw, swbuf, sizeof(swbuf)); } + if (ui_status == NULL) + return; /* one text field: no status bar */ + cols = getmaxx(ui_status); werase(ui_status); wattron(ui_status, COLOR_PAIR(PAIR_STATUS)); @@ -1591,26 +1585,6 @@ entry_set_text(struct ui_state *s, size_t id, const char *text) s->entries[i - 1].text = copy; } -/* keep a live entry at the end: tools drain by appending, the answer follows */ -static void -entry_move_to_end(struct ui_state *s, size_t id) -{ - struct entry tmp; - size_t i; - - if (id == 0 || s->n < 2) - return; - for (i = 0; i < s->n; i++) - if (s->entries[i].id == id) - break; - if (i >= s->n - 1) - return; - tmp = s->entries[i]; - memmove(&s->entries[i], &s->entries[i + 1], - (s->n - i - 1) * sizeof(s->entries[0])); - s->entries[s->n - 1] = tmp; -} - /* * Append an entry and return its id. Callers that update an entry later (the * live answer, the reasoning) keep the id, not the index: at MAX_ENTRIES the @@ -1707,6 +1681,7 @@ agent_switch(struct ui_state *s, struct sp_agent *ag, int idx, int announce) return; d = &s->agents.v[idx]; s->agent_cur = idx; + snprintf(ui_agent, sizeof(ui_agent), "%.24s", d->name); (void)sp_agents_activate(ag, d, s->base_prompt != NULL ? s->base_prompt : "", &s->policy); if (s->conf != NULL) { @@ -1750,32 +1725,23 @@ agent_switch(struct ui_state *s, struct sp_agent *ag, int idx, int announce) static void layout(void) { - int rows, cols, chat_w, side_w; + int rows, cols; getmaxyx(stdscr, rows, cols); /* - * One column of air between the chat and the sidebar, and one inside the - * chat on both sides: text that starts at the very edge of a window reads - * like a terminal dump, not like a conversation. + * One text field over the whole screen and the input line below it -- + * no sidebar, no status bar. The conversation starts at the top and + * grows downward; what was written stays where it is. */ - chat_w = cols * 3 / 4 - 1; - if (chat_w < 20) - chat_w = cols > 40 ? cols * 3 / 4 : cols - 1; - side_w = cols - chat_w - 1; - /* - * Order, top to bottom: chat and sidebar, then the status line, then the - * input. Status above the prompt, the way Hermes shows it - the line you - * read while typing sits directly above what you type. - */ - ui_hist = newwin(rows - 2, chat_w, 0, 0); + ui_hist = newwin(rows - 1, cols, 0, 0); wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN)); - ui_side = newwin(rows - 2, side_w, 0, chat_w + 1); - ui_status = newwin(1, cols, rows - 2, 0); + ui_side = NULL; + ui_status = NULL; ui_input = newwin(1, cols, rows - 1, 0); + wbkgd(ui_input, COLOR_PAIR(PAIR_INPUT)); keypad(ui_input, TRUE); /* a one-line window that may scroll is a screen that jumps */ scrollok(ui_input, FALSE); - scrollok(ui_status, FALSE); } /* @@ -1821,12 +1787,12 @@ redraw(struct ui_state *s, struct sp_agent *ag, struct sp_host *host) static const char * prompt_mark(void) { - static char buf[32]; + static char buf[64]; const char *m = sp_t("ui.prompt_mark"); size_t n = strlen(m); - snprintf(buf, sizeof(buf), "%s%s", m, n > 0 && m[n - 1] == ' ' ? - "" : " "); + snprintf(buf, sizeof(buf), "%s%s%s", ui_agent, m, + n > 0 && m[n - 1] == ' ' ? "" : " "); return buf; } @@ -1893,6 +1859,7 @@ slash_collect(struct sp_agent *ag, struct sp_host *host, slash_add_match(matches, &n, max, "status"); slash_add_match(matches, &n, max, "usage"); + slash_add_match(matches, &n, max, "widgets"); slash_add_match(matches, &n, max, "agent"); slash_add_match(matches, &n, max, "resume"); slash_add_match(matches, &n, max, "swarm"); @@ -2148,12 +2115,18 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, off += snprintf(hint + off, sizeof(hint) - off, " "); for (i2 = 0; i2 < k && off + 2 < sizeof(hint); i2++) off += snprintf(hint + off, sizeof(hint) - off, "/%s ", m[i2]); - werase(ui_status); - wattron(ui_status, COLOR_PAIR(PAIR_STATUS)); - mvwhline(ui_status, 0, 0, ' ', getmaxx(ui_status)); - mvwaddnstr(ui_status, 0, 0, hint, getmaxx(ui_status) - 1); - wattroff(ui_status, COLOR_PAIR(PAIR_STATUS)); - wnoutrefresh(ui_status); + { + WINDOW *hw = ui_status != NULL ? + ui_status : ui_hist; + int hy = ui_status != NULL ? 0 : + getmaxy(ui_hist) - 1; + + wattron(hw, COLOR_PAIR(PAIR_STATUS)); + mvwhline(hw, hy, 0, ' ', getmaxx(hw)); + mvwaddnstr(hw, hy, 0, hint, getmaxx(hw) - 1); + wattroff(hw, COLOR_PAIR(PAIR_STATUS)); + wnoutrefresh(hw); + } } } draw_prompt(input); @@ -2378,6 +2351,22 @@ ui_slash(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, sp_buf_free(&out); return 1; } + /* + * /widgets: what a plugin published. The sidebar used to show these lines + * all the time; one text field shows them when asked, as text. + */ + if (strcmp(name, "widgets") == 0 || strcmp(name, "widget") == 0) { + char buf[4096]; + + if (host == NULL || sp_host_widget_count(host) == 0) + sp_buf_puts(&out, sp_t("widgets.none")); + else if (sp_host_widget_snapshot(host, buf, sizeof(buf)) > 0) + sp_buf_printf(&out, "%s", buf); + snprintf(outbuf, sizeof(outbuf), "%s", out.p != NULL ? out.p : ""); + sp_buf_free(&out); + add_entry(s, "splinter", outbuf); + return 1; + } if (strcmp(name, "usage") == 0) { sp_usage_report(s->conf, &out); snprintf(outbuf, sizeof(outbuf), "%s", out.p ? out.p : ""); @@ -2707,12 +2696,51 @@ struct turn_view { struct timespec t0; int drained; /* tool calls already in the transcript */ int drained_d; /* diffs already in the transcript */ - size_t think_id; /* entry of the reasoning, 0 = none yet */ - size_t ans_id; /* entry of the answer, 0 = none yet */ + struct seg { + size_t id; /* entry showing the open part, 0 = none */ + size_t off; /* bytes already frozen in earlier entries */ + size_t shown; /* bytes in the open entry */ + } think, ans; /* the reasoning, the answer */ char line[1024]; /* steering text being typed */ size_t llen; }; +/* + * One growing text of the turn -- the reasoning, the answer -- shown append + * only. It grows in its entry while that entry is the last one. Once anything + * was appended below it (a tool line, the answer), that entry is left as it + * is and the rest of the text continues in a new entry at the bottom. Nothing + * that is on screen moves; the transcript only gets longer. + */ +static void +seg_show(struct ui_state *s, struct seg *g, const char *role, const char *text) +{ + size_t len = text != NULL ? strlen(text) : 0; + const char *p; + + if (g->off > len) { /* the buffer started over */ + g->off = 0; + g->shown = 0; + g->id = 0; + } + if (g->id != 0 && !(s->n > 0 && s->entries[s->n - 1].id == g->id)) { + g->off += g->shown; + g->shown = 0; + g->id = 0; + } + if (len <= g->off) + return; + p = text + g->off; + while (*p == '\n') + p++; + if (*p == '\0') + return; + if (g->id == 0) + g->id = add_entry(s, role, ""); + entry_set_text(s, g->id, p); + g->shown = len - g->off; +} + /* diffs of the turn into the transcript; tool calls flow in the thinking stream */ static void compact_cb(void *ctx, size_t before, size_t after, size_t mb, size_t ma) @@ -2840,18 +2868,11 @@ turn_paint(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, live = strdup(tu->live.p); pthread_mutex_unlock(&tu->lock); - if (think != NULL) { - if (v->think_id == 0) - v->think_id = add_entry(s, "thinking", ""); - entry_set_text(s, v->think_id, think); - } + if (think != NULL) + seg_show(s, &v->think, "thinking", think); turn_drain(s, tu, v); - if (v->ans_id != 0) - entry_move_to_end(s, v->ans_id); if (live != NULL) { - if (v->ans_id == 0) - v->ans_id = add_entry(s, "agent", ""); - entry_set_text(s, v->ans_id, live); + seg_show(s, &v->ans, "agent", live); s->out_chars = strlen(live); } free(think); @@ -2903,8 +2924,21 @@ turn_paint(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, werase(ui_input); w = getmaxx(ui_input) - 1; { - const char *mark = sp_td("ui.steer_mark", "steer> "); + /* no status bar: the running time and the tool lead the input */ + char mark[160], tool[64] = ""; + pthread_mutex_lock(&tu->lock); + if (tu->tool_line[0] != '\0') + snprintf(tool, sizeof(tool), " %.40s", tu->tool_line); + pthread_mutex_unlock(&tu->lock); + snprintf(mark, sizeof(mark), "%lds%s %s", ms / 1000, tool, + sp_td("ui.steer_mark", "steer> ")); + { + size_t ml = strlen(mark); + + if (ml > 0 && mark[ml - 1] != ' ' && ml + 1 < sizeof(mark)) + snprintf(mark + ml, sizeof(mark) - ml, " "); + } mvwaddnstr(ui_input, 0, 0, mark, w); used = (int)strlen(mark); } @@ -3124,11 +3158,7 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, if (show->len > 0 && show->p != NULL) { sp_logf("thinking", "%s", show->p); - if (v.think_id == 0) - v.think_id = add_entry(s, "thinking", - show->p); - else - entry_set_text(s, v.think_id, show->p); + seg_show(s, &v.think, "thinking", show->p); } } } @@ -3164,16 +3194,19 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host, * would take it away. Keep the streamed text when it ends in the * final answer. */ - if (v.ans_id != 0) { + { size_t lv = tu.live.len, la = strlen(ap); - if (la > 0 && lv >= la && tu.live.p != NULL && - memcmp(tu.live.p + lv - la, ap, la) == 0) - entry_set_text(s, v.ans_id, tu.live.p); - else - entry_set_text(s, v.ans_id, ap); - } else - add_entry(s, "agent", ap); + if (lv > 0 && tu.live.p != NULL) { + /* streamed: show what is left of it, then stop */ + seg_show(s, &v.ans, "agent", tu.live.p); + /* a final answer longer than what streamed was + * not streamed: it gets its own entry */ + if (la > lv) + add_entry(s, "agent", ap); + } else + add_entry(s, "agent", ap); + } s->total_out_chars += strlen(ap); s->out_chars = strlen(ap); } else diff --git a/tests/test_agents_ui.sh b/tests/test_agents_ui.sh index acdb56a..1e07101 100644 --- a/tests/test_agents_ui.sh +++ b/tests/test_agents_ui.sh @@ -38,17 +38,17 @@ tmux new-session -d -s $S -x 120 -y 30 -c "$D/proj" \ "HOME=$D/home SPLINTER_LOCALE=en SPLINTER_USAGE_DIR=$D/u SPLINTER_COOLDOWN_DIR=$D/c \ $PWD/splinter --no-config --endpoint http://127.0.0.1:$P/v1/chat/completions \ --model m --chat 2>/dev/null" -check "starts as build" shows '\[build\]' +check "starts as build" shows '^build>' tmux send-keys -t $S Tab -check "Tab goes to plan" shows '\[plan\]' +check "Tab goes to plan" shows 'agent: plan' tmux send-keys -t $S Tab -check "Tab goes on to a file profile" shows '\[careful\]' +check "Tab goes on to a file profile" shows 'agent: careful' tmux send-keys -t $S Tab -check "and wraps to build" shows '\[build\]' +check "and wraps to build" shows '^build>' tmux send-keys -t $S BTab -check "Shift-Tab goes back" shows '\[careful\]' +check "Shift-Tab goes back" shows 'agent: careful' tmux send-keys -t $S BTab -check "back to plan" shows '\[plan\]' +check "back to plan" shows 'agent: plan' # in plan, the command is refused with the reason; nothing is created tmux send-keys -t $S -l 'mach etwas' diff --git a/tests/test_theme.c b/tests/test_theme.c index b4d9117..cb4a6c9 100644 --- a/tests/test_theme.c +++ b/tests/test_theme.c @@ -1,5 +1,6 @@ /* splinter -- CDE theme derivation tests. */ #include +#include #include #include "theme.h" @@ -27,38 +28,64 @@ main(void) 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 */ + /* Xresources first, then every palette of the CDE tree, by name */ CHECK(sp_theme_list(&names, &count) == count); - CHECK(count == sp_palette_count); - CHECK(count >= 40); - for (i = 1; i < count; i++) + 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 Delphinium, and NULL means the default */ + /* 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, "Delphinium") == 0); - CHECK(sp_theme_load("Delphinium", &t2, &err) == 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); - /* roles are derived by luminance, so bg is darker than fg in every one */ - for (i = 0; i < count; i++) { + /* 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(luma(t.bg) <= luma(t.fg)); - CHECK(luma(t.border) >= luma(t.bg)); - CHECK(luma(t.status) <= luma(t.accent)); + 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)); } - (void)seen_delphinium; + /* 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(sp_theme_from_xrdb("URxvt.background: #000000\n", &t) == 0); + CHECK(t.indexed == 1); - /* an unknown palette is an error, never a silent fallback */ + /* 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 palette") != NULL); + CHECK(strstr(err.p, "unknown theme") != NULL); /* colour mapping stays inside the terminal's palette */ CHECK(sp_color_rgb(0, 0, 0, 256) >= 16); diff --git a/tests/test_ui.sh b/tests/test_ui.sh index 87aa9f4..079a882 100755 --- a/tests/test_ui.sh +++ b/tests/test_ui.sh @@ -108,17 +108,17 @@ check grep -q 'vom gateway' "$D/out.txt" typed 'halb' check shows 'halb' # let the UI consume the keys key C-l; sleep 1 -check shows '^> halb' +check shows '^build> halb' key BSpace BSpace -check shows '^> ha *$' # the backspaces arrived +check shows '^build> ha *$' # the backspaces arrived key C-l; sleep 1 -check shows '^> ha *$' +check shows '^build> ha *$' typed 'zeig eine tabelle'; key Enter check shows '| a | b |' check shows '|---|----|' check shows '| 1 | 22 |' tmux resize-window -t $S -x 70 -y 20; sleep 1 -check shows '^>' +check shows '^build>' check test "$(quit_code)" = 0 start 1 @@ -147,7 +147,7 @@ check shows 'working' sleep 0.5 key C-c check shows 'cancelled' -check shows '^>' +check shows '^build>' check test "$(quit_code)" = 0 if [ "$fails" -eq 0 ]; then echo "test_ui: ok"; exit 0; fi