ui: the sidebar is back, and it says where splinter runs
Removing it went too far: the conversation area should be plain appended
text, but the sidebar carries what no line of the transcript should repeat -
agent, provider and model, what is left of the allowance, the plugin widget
lines, the session and now the directory the tools act in ("~" for $HOME,
wrapped at the slashes). A narrow terminal drops it and gives the width to
the conversation.
No status bar: the running time and the tool lead the prompt, and /usage,
/status and /widgets print the same numbers on demand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5054393e17
commit
32a214aee3
8 files changed
+342
-53
No files matched your search
@@ -3,9 +3,10 @@
|
||||
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: 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.
|
||||
A C99/POSIX agent harness with a curses interface: the conversation on three
|
||||
quarters, a sidebar on the last one that says which agent, provider, model and
|
||||
allowance you are on and where the tools will act, the prompt below it. The
|
||||
conversation starts clear at the top and only ever grows.
|
||||
|
||||
make # libsplinter.so, the binary, the plugins
|
||||
make check # the tests, no network, no model
|
||||
@@ -58,12 +59,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: one transcript, one input line
|
||||
src/ui.c curses UI: transcript, sidebar, prompt
|
||||
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: a clock widget line + a tool
|
||||
plugins/clock/ example plugin: a sidebar clock + 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
|
||||
@@ -82,8 +83,8 @@ 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. 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`.
|
||||
publishes a line of text, which the sidebar shows; `/widgets` prints the same
|
||||
lines into the transcript. See `docs/PLUGINS.md`.
|
||||
|
||||
The default theme is `Xresources`: it takes `*foreground`, `*background` and
|
||||
`*color0`..`*color15` from `xrdb -query` (or `~/.Xresources` without X) and
|
||||
|
||||
+2
-2
@@ -398,8 +398,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_<tool>`; with several they are
|
||||
`mcp_<server>_<tool>`, 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. Its widget line says how many tools came back and
|
||||
when a server stops answering; `/widgets` shows it.
|
||||
not pretend to know better. The sidebar widget shows how many tools came back
|
||||
and says so when a server stops answering.
|
||||
|
||||
The handshake is `initialize` + `notifications/initialized` + `tools/list`; a
|
||||
server that fails it is reported and skipped, and the others still load. The
|
||||
|
||||
+4
-3
@@ -102,9 +102,10 @@ static const struct sp_widget w = {
|
||||
sp_host_add_widget(host, &w);
|
||||
```
|
||||
|
||||
`/widgets` in the chat prints one line per widget, `name: text`. The UI has no
|
||||
sidebar any more, and `draw()` is not called at all: a widget that wants to say
|
||||
something publishes text with `tick()`, and that is what `/widgets` shows.
|
||||
The sidebar lists one line per widget, `name: text`; `/widgets` prints the same
|
||||
lines into the transcript. `draw()` exists for widgets that need more than one
|
||||
line; it runs on the UI thread and must be fast, because it holds up the rest of
|
||||
the screen while it runs.
|
||||
|
||||
## Threads, honestly
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
*
|
||||
* 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 segments go to sp_host_add_status(): /status shows them in the
|
||||
* transcript and the Telegram gateway sends them with its replies. The chat has
|
||||
* no status bar - the prompt carries the running time and the tool.
|
||||
*
|
||||
* The numbers come from the harness (struct sp_meter), never from the plugin
|
||||
* counting for itself: two counters that disagree are worse than none.
|
||||
|
||||
@@ -8,6 +8,10 @@ ui.ready = bereit. Enter sendet, Ctrl-D beendet.
|
||||
ui.working = laeuft...
|
||||
ui.steering_queued = Steuerung eingereiht
|
||||
|
||||
sidebar.session = Sitzung
|
||||
sidebar.cwd = Verzeichnis
|
||||
sidebar.last_turn = letzter Turn
|
||||
sidebar.tokens = %zu Tok (ein %zu)
|
||||
|
||||
|
||||
role.you = du
|
||||
@@ -165,6 +169,13 @@ connect.later = Spaeter
|
||||
reply.empty = (leer)
|
||||
|
||||
# Agent-Profile, Kontingent, Seitenleiste (mit den Profilen dazugekommen)
|
||||
sidebar.model = Modell
|
||||
sidebar.usage = Kontingent
|
||||
sidebar.turn_line = %.1f s, %zu Schritte, %zu Tools
|
||||
widget.focus = Ziel
|
||||
widget.plan = Plan
|
||||
widget.tasks = Aufgaben
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = Nutzungslimit: weiter um %s (Strg-C stoppt, /resume macht weiter)
|
||||
agent.switched = Agent: %s - %s %s
|
||||
agent.readonly = [nur lesen]
|
||||
|
||||
@@ -7,6 +7,10 @@ ui.ready = ready. Enter sends, Ctrl-D quits.
|
||||
ui.working = working...
|
||||
ui.steering_queued = steering queued
|
||||
|
||||
sidebar.session = session
|
||||
sidebar.cwd = dir
|
||||
sidebar.last_turn = last turn
|
||||
sidebar.tokens = %zu tok (in %zu)
|
||||
|
||||
|
||||
role.you = you
|
||||
@@ -164,6 +168,13 @@ connect.later = Later
|
||||
reply.empty = (empty)
|
||||
|
||||
# agent profiles, usage, sidebar (added with the profiles)
|
||||
sidebar.model = model
|
||||
sidebar.usage = usage
|
||||
sidebar.turn_line = %.1f s, %zu steps, %zu tools
|
||||
widget.focus = goal
|
||||
widget.plan = plan
|
||||
widget.tasks = tasks
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = usage limit: continuing at %s (Ctrl-C stops, /resume goes on)
|
||||
agent.switched = agent: %s - %s %s
|
||||
agent.readonly = [read-only]
|
||||
|
||||
@@ -12,6 +12,10 @@ ui.steer_mark = direcionar>
|
||||
ui.swarm_locked = [enxame bloqueado]
|
||||
ui.approve = executar %s (%s) %.60s? y/N
|
||||
|
||||
sidebar.session = sessao
|
||||
sidebar.cwd = diretorio
|
||||
sidebar.last_turn = ultimo turno
|
||||
sidebar.tokens = %zu tok (entrada %zu)
|
||||
|
||||
|
||||
role.you = voce
|
||||
@@ -168,6 +172,13 @@ connect.later = Depois
|
||||
reply.empty = (vazio)
|
||||
|
||||
# perfis de agente, uso, barra lateral (junto com os perfis)
|
||||
sidebar.model = modelo
|
||||
sidebar.usage = uso
|
||||
sidebar.turn_line = %.1f s, %zu passos, %zu ferramentas
|
||||
widget.focus = meta
|
||||
widget.plan = plano
|
||||
widget.tasks = tarefas
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = limite de uso: continua as %s (Ctrl-C para, /resume continua)
|
||||
agent.switched = agente: %s - %s %s
|
||||
agent.readonly = [somente leitura]
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Layout, fixed and deliberate: one text field, and the input below it.
|
||||
* Layout, fixed and deliberate:
|
||||
*
|
||||
* +----------------------------------------------+
|
||||
* | ready. |
|
||||
* | you wie gross ist ../xsrc? |
|
||||
* | splinter Etwa 1,2 GB. |
|
||||
* | |
|
||||
* +----------------------------------------------+
|
||||
* | build> |
|
||||
* +---------------------------------+------------+
|
||||
* | history | sidebar |
|
||||
* | three quarters | one quarter|
|
||||
* | starts clear, only ever grows | model |
|
||||
* | | usage |
|
||||
* | | widgets |
|
||||
* | | session |
|
||||
* | | directory |
|
||||
* +---------------------------------+------------+
|
||||
* | build> prompt, or "12s tool steer>" |
|
||||
* +----------------------------------------------+
|
||||
*
|
||||
* The conversation starts clear at the top and only ever grows: a turn
|
||||
* appends what it has, nothing that is already on screen moves, and the
|
||||
* terminal's own scrollback is the history above. There is no sidebar and no
|
||||
* status bar to fill; a plugin publishes widget text and /widgets shows it.
|
||||
* No status bar: the running time and the tool lead the prompt, and /usage,
|
||||
* /status and /widgets put the same numbers into the transcript on demand.
|
||||
*
|
||||
* Only the UI thread ever calls into curses. Anything that wants to appear on
|
||||
* screen hands over finished text and never touches a WINDOW.
|
||||
* Only the UI thread ever calls into curses. Anything that wants to appear in
|
||||
* the sidebar hands over finished text and never touches a WINDOW.
|
||||
*
|
||||
* Redraws happen when something changed -- after a turn, after a key -- so an
|
||||
* idle splinter burns no CPU.
|
||||
@@ -125,6 +126,7 @@ sp_ui_start_agent(const char *name)
|
||||
}
|
||||
|
||||
static WINDOW *ui_hist;
|
||||
static WINDOW *ui_side;
|
||||
static WINDOW *ui_input;
|
||||
/*
|
||||
* The agent whose profile is active. The sidebar used to show it; with one
|
||||
@@ -1210,6 +1212,235 @@ draw_history(struct ui_state *s, int reserve)
|
||||
wnoutrefresh(ui_hist);
|
||||
}
|
||||
|
||||
/*
|
||||
* The streaming turn is drawn as the last thing in the history pane: the tail
|
||||
* of what has arrived so far. It is not an entry yet - entries are what was
|
||||
* completed, and mixing the two would make the log look like it changed.
|
||||
*/
|
||||
/*
|
||||
* While a turn runs, the left pane shows what the harness is doing, in the same
|
||||
* place the conversation lives: the model's reasoning dimmed above, the answer
|
||||
* as it arrives below. The sidebar keeps the counters - numbers are not text.
|
||||
*/
|
||||
static void
|
||||
sidebar_heading(int *y, int cols, const char *text)
|
||||
{
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM) | A_BOLD);
|
||||
mvwaddnstr(ui_side, *y, 0, text, cols - 1);
|
||||
wattroff(ui_side, A_BOLD);
|
||||
(*y)++;
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
}
|
||||
|
||||
/* wrap 'text' into the sidebar from row *y, at most 'maxrows' rows */
|
||||
static void
|
||||
side_text(int *y, int cols, const char *text, int maxrows)
|
||||
{
|
||||
int rows = 0;
|
||||
|
||||
while (*text != '\0' && rows < maxrows && *y < getmaxy(ui_side)) {
|
||||
size_t n = strlen(text), take = n;
|
||||
|
||||
if (take > (size_t)cols - 1) {
|
||||
take = (size_t)cols - 1;
|
||||
while (take > 0 && text[take] != ' ')
|
||||
take--;
|
||||
if (take == 0)
|
||||
take = (size_t)cols - 1;
|
||||
}
|
||||
mvwaddnstr(ui_side, (*y)++, 0, text, (int)take);
|
||||
rows++;
|
||||
text += take;
|
||||
while (*text == ' ')
|
||||
text++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A path, wrapped at its slashes: "/home/k/src/splinter/plugins" cuts after a
|
||||
* "/", never in the middle of a name. A path is what the operator checks first
|
||||
* when a tool wrote somewhere it should not have.
|
||||
*/
|
||||
static void
|
||||
side_path(int *y, int cols, const char *path, int maxrows)
|
||||
{
|
||||
int rows = 0;
|
||||
size_t len = strlen(path), off = 0;
|
||||
size_t width = (size_t)cols - 1;
|
||||
|
||||
if (width < 4)
|
||||
width = 4;
|
||||
while (off < len && rows < maxrows && *y < getmaxy(ui_side)) {
|
||||
size_t take = len - off, cut;
|
||||
|
||||
if (take > width) {
|
||||
take = width;
|
||||
cut = take;
|
||||
while (cut > 0 && path[off + cut] != '/')
|
||||
cut--;
|
||||
if (cut == 0)
|
||||
take = width; /* no slash in reach: hard cut */
|
||||
else
|
||||
take = cut + 1; /* keep the slash on this line */
|
||||
}
|
||||
mvwaddnstr(ui_side, (*y)++, 0, path + off, (int)take);
|
||||
off += take;
|
||||
rows++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
struct sp_host *host)
|
||||
{
|
||||
int cols, y = 0;
|
||||
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);
|
||||
|
||||
/* who is answering: the profile, the provider, the model */
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.model"));
|
||||
if (s->agents.n > 0) {
|
||||
wattron(ui_side, A_BOLD);
|
||||
{
|
||||
char tag[64];
|
||||
|
||||
snprintf(tag, sizeof(tag), "[%s]",
|
||||
s->agents.v[s->agent_cur].name);
|
||||
mvwaddnstr(ui_side, y++, 0, tag, cols - 1);
|
||||
}
|
||||
wattroff(ui_side, A_BOLD);
|
||||
}
|
||||
{
|
||||
char line[300];
|
||||
|
||||
snprintf(line, sizeof(line), "%s%s%s", act,
|
||||
g_model[0] != '\0' ? " / " : "", g_model);
|
||||
side_text(&y, cols, line, 2);
|
||||
}
|
||||
y++;
|
||||
|
||||
/* how much of each allowance is used: the provider in use, and any that
|
||||
* has a limit or is benched */
|
||||
{
|
||||
const struct sp_config *cfg = s->conf;
|
||||
struct sp_usage u;
|
||||
size_t i;
|
||||
int printed = 0;
|
||||
char brief[96], line[200];
|
||||
|
||||
for (i = 0; i <= (cfg != NULL ? cfg->ndelegates : 0); i++) {
|
||||
const char *pid = i == 0 ? act : cfg->delegate[i - 1].id;
|
||||
|
||||
if (i > 0 && strcmp(pid, act) == 0)
|
||||
continue;
|
||||
sp_usage_for(cfg, pid, &u);
|
||||
if (i > 0 && u.frac < 0 && u.benched_until == 0)
|
||||
continue;
|
||||
if (!printed) {
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.usage"));
|
||||
printed = 1;
|
||||
}
|
||||
sp_usage_brief(&u, brief, sizeof(brief));
|
||||
snprintf(line, sizeof(line), "%-9.9s %s", pid, brief);
|
||||
if (u.frac >= 0.9 || u.benched_until > 0)
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_ACCENT) | A_BOLD);
|
||||
if (y < getmaxy(ui_side))
|
||||
mvwaddnstr(ui_side, y++, 0, line, cols - 1);
|
||||
wattrset(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
}
|
||||
if (printed)
|
||||
y++;
|
||||
}
|
||||
|
||||
/* what the plugins want to show: the goal, the plan, tasks ... */
|
||||
if (host != NULL && sp_host_widget_count(host) > 0) {
|
||||
char snap[1024], *line, *save = NULL;
|
||||
|
||||
sp_host_widget_snapshot(host, snap, sizeof(snap));
|
||||
for (line = strtok_r(snap, "\n", &save); line != NULL;
|
||||
line = strtok_r(NULL, "\n", &save)) {
|
||||
char name[48], *colon = strchr(line, ':');
|
||||
char *text;
|
||||
size_t nl;
|
||||
|
||||
if (colon == NULL)
|
||||
continue;
|
||||
nl = (size_t)(colon - line);
|
||||
if (nl >= sizeof(name))
|
||||
continue;
|
||||
memcpy(name, line, nl);
|
||||
name[nl] = '\0';
|
||||
text = colon + 1;
|
||||
while (*text == ' ')
|
||||
text++;
|
||||
/* a text that repeats its own name ("plan: 0 tasks") */
|
||||
if (strncmp(text, name, nl) == 0 && text[nl] == ':') {
|
||||
text += nl + 1;
|
||||
while (*text == ' ')
|
||||
text++;
|
||||
}
|
||||
if (*text == '\0' || y >= getmaxy(ui_side) - 2)
|
||||
continue;
|
||||
snprintf(key, sizeof(key), "widget.%s", name);
|
||||
sidebar_heading(&y, cols, sp_td(key, name));
|
||||
side_text(&y, cols, text, 4);
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/* the last turn, in one line */
|
||||
if (s->last_ms > 0 && y < getmaxy(ui_side) - 2) {
|
||||
char line[160];
|
||||
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.last_turn"));
|
||||
snprintf(line, sizeof(line), sp_t("sidebar.turn_line"),
|
||||
(double)s->last_ms / 1000.0, s->last_steps, s->last_calls);
|
||||
side_text(&y, cols, line, 1);
|
||||
if (s->tokens_out > 0) {
|
||||
snprintf(line, sizeof(line), sp_t("sidebar.tokens"),
|
||||
s->tokens_out, s->tokens_in);
|
||||
side_text(&y, cols, line, 1);
|
||||
}
|
||||
y++;
|
||||
}
|
||||
|
||||
if (id != NULL && y < getmaxy(ui_side) - 2) {
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.session"));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
side_text(&y, cols, id, 1);
|
||||
}
|
||||
/*
|
||||
* Where this splinter runs. Every tool acts relative to it, so it has to
|
||||
* be on screen: a delegate that wrote into the wrong tree was the one
|
||||
* question nobody could answer from the screen. $HOME is shown as ~.
|
||||
*/
|
||||
{
|
||||
char cwd[700], shown[760];
|
||||
const char *home = getenv("HOME");
|
||||
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
if (home != NULL && *home != '\0' &&
|
||||
strncmp(cwd, home, strlen(home)) == 0 &&
|
||||
(cwd[strlen(home)] == '/' || cwd[strlen(home)] == '\0'))
|
||||
snprintf(shown, sizeof(shown), "~%s", cwd + strlen(home));
|
||||
else
|
||||
snprintf(shown, sizeof(shown), "%s", cwd);
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.cwd"));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
side_path(&y, cols, shown, 4);
|
||||
}
|
||||
}
|
||||
wattrset(ui_side, A_NORMAL);
|
||||
|
||||
wnoutrefresh(ui_side);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feed the meter the status plugins read. The harness counts; a plugin must not
|
||||
@@ -1456,11 +1687,22 @@ layout(void)
|
||||
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
/*
|
||||
* 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.
|
||||
* The conversation on three quarters, the sidebar on the last one, the
|
||||
* input below both. The conversation starts at the top and grows
|
||||
* downward; what was written stays where it is.
|
||||
*/
|
||||
ui_hist = newwin(rows - 1, cols, 0, 0);
|
||||
{
|
||||
int side_w = cols / 4;
|
||||
int chat_w = cols - side_w - 1;
|
||||
|
||||
if (side_w < 18)
|
||||
side_w = cols > 50 ? 18 : 0;
|
||||
if (side_w == 0)
|
||||
chat_w = cols;
|
||||
ui_hist = newwin(rows - 1, chat_w, 0, 0);
|
||||
ui_side = side_w > 0 ?
|
||||
newwin(rows - 1, side_w, 0, chat_w + 1) : NULL;
|
||||
}
|
||||
wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
ui_input = newwin(1, cols, rows - 1, 0);
|
||||
wbkgd(ui_input, COLOR_PAIR(PAIR_INPUT));
|
||||
@@ -1471,31 +1713,34 @@ layout(void)
|
||||
|
||||
/*
|
||||
* The terminal changed size: the windows were cut for the old one. layout()
|
||||
* used to run once, so after a resize the panes kept their old geometry and
|
||||
* drew over each other.
|
||||
* used to run once, so after a resize the four windows kept their old
|
||||
* geometry and drew over each other.
|
||||
*/
|
||||
static void
|
||||
relayout(int input_timeout_ms)
|
||||
{
|
||||
if (ui_hist != NULL)
|
||||
delwin(ui_hist);
|
||||
if (ui_side != NULL)
|
||||
delwin(ui_side);
|
||||
if (ui_input != NULL)
|
||||
delwin(ui_input);
|
||||
ui_hist = ui_input = NULL;
|
||||
ui_hist = ui_side = ui_input = NULL;
|
||||
layout();
|
||||
wtimeout(ui_input, input_timeout_ms);
|
||||
clearok(curscr, TRUE);
|
||||
}
|
||||
|
||||
/* the session id and directory, NULL-safe */
|
||||
/* the session id and directory the sidebar shows, NULL-safe */
|
||||
#define SESS_ID(ag) ((ag)->sess != NULL ? (ag)->sess->id : NULL)
|
||||
#define SESS_DIR(ag) ((ag)->sess != NULL ? (ag)->sess->dir : NULL)
|
||||
|
||||
/* the history and one doupdate() */
|
||||
/* history, sidebar and status line, then one doupdate() */
|
||||
static void
|
||||
redraw(struct ui_state *s)
|
||||
redraw(struct ui_state *s, struct sp_agent *ag, struct sp_host *host)
|
||||
{
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
doupdate();
|
||||
}
|
||||
|
||||
@@ -1552,8 +1797,8 @@ draw_prompt(const char *input)
|
||||
|
||||
/*
|
||||
* Read one line at the prompt. Enter ends it; Ctrl-D sets s->quit. While no
|
||||
* key comes, the read times out every 500 ms, which is when the fleet and the
|
||||
* running turn are polled: a widget that ticks is useless if nothing looks.
|
||||
* key comes, the read times out every 500 ms and repaints sidebar and status
|
||||
* line: a widget that ticks is useless if the screen only refreshes on a key.
|
||||
*/
|
||||
static int
|
||||
slash_add_match(char matches[][64], int *n, int max, const char *name)
|
||||
@@ -1662,6 +1907,7 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
if (got)
|
||||
draw_history(s, 0);
|
||||
}
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -1690,6 +1936,7 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
else
|
||||
clearok(curscr, TRUE);
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -1735,6 +1982,7 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
if (ch == KEY_PPAGE || ch == KEY_SR) {
|
||||
s->scroll += (ch == KEY_SR ? 1 : 10);
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -1749,6 +1997,7 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
|
||||
s->scroll = s->scroll > step ? s->scroll - step : 0;
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -1784,6 +2033,7 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
(s->agent_cur + (int)s->agents.n - 1) % (int)s->agents.n,
|
||||
1);
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
draw_prompt(input);
|
||||
wnoutrefresh(ui_input);
|
||||
doupdate();
|
||||
@@ -2555,8 +2805,8 @@ turn_approval(struct turn *tu, int c)
|
||||
* which is what a jumping block feels like.
|
||||
*/
|
||||
static void
|
||||
turn_paint(struct ui_state *s, struct sp_host *host, struct turn *tu,
|
||||
struct turn_view *v)
|
||||
turn_paint(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
struct turn *tu, struct turn_view *v)
|
||||
{
|
||||
char *think = NULL, *live = NULL;
|
||||
struct timespec now;
|
||||
@@ -2585,6 +2835,7 @@ turn_paint(struct ui_state *s, struct sp_host *host, struct turn *tu,
|
||||
free(think);
|
||||
free(live);
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
/* a fleet moves on while a turn runs; nothing draws it any more */
|
||||
if (s->sw != NULL)
|
||||
swarm_poll(s->sw);
|
||||
@@ -2633,24 +2884,25 @@ turn_paint(struct ui_state *s, struct sp_host *host, struct turn *tu,
|
||||
* cancels and quits. Returns 1 when the turn was cancelled.
|
||||
*/
|
||||
static int
|
||||
turn_key(struct ui_state *s, struct turn *tu, struct turn_view *v, int c,
|
||||
char *pending_steer, size_t ps_cap)
|
||||
turn_key(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
struct turn *tu, struct turn_view *v, int c, char *pending_steer,
|
||||
size_t ps_cap)
|
||||
{
|
||||
if (c == KEY_PPAGE || c == KEY_SR) {
|
||||
s->scroll += (c == KEY_SR ? 1 : 10);
|
||||
redraw(s);
|
||||
redraw(s, ag, host);
|
||||
return 0;
|
||||
}
|
||||
if (c == KEY_NPAGE || c == KEY_SF) {
|
||||
size_t step = (c == KEY_SF ? 1 : 10);
|
||||
|
||||
s->scroll = s->scroll > step ? s->scroll - step : 0;
|
||||
redraw(s);
|
||||
redraw(s, ag, host);
|
||||
return 0;
|
||||
}
|
||||
if (c == KEY_RESIZE) {
|
||||
relayout(100);
|
||||
redraw(s);
|
||||
redraw(s, ag, host);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
@@ -2767,10 +3019,10 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
if (turn_approval(&tu, c))
|
||||
continue;
|
||||
if (c == ERR) {
|
||||
turn_paint(s, host, &tu, &v);
|
||||
turn_paint(s, ag, host, &tu, &v);
|
||||
continue;
|
||||
}
|
||||
if (turn_key(s, &tu, &v, c, pending_steer,
|
||||
if (turn_key(s, ag, host, &tu, &v, c, pending_steer,
|
||||
ps_cap)) {
|
||||
cancelled = 1;
|
||||
break;
|
||||
@@ -2806,7 +3058,7 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
_exit(1);
|
||||
}
|
||||
if (c2 == ERR)
|
||||
turn_paint(s, host, &tu, &v);
|
||||
turn_paint(s, ag, host, &tu, &v);
|
||||
}
|
||||
wtimeout(ui_input, -1);
|
||||
}
|
||||
@@ -3017,7 +3269,8 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model,
|
||||
if (ui_start(&s, ag, host, endpoint, model, theme_name, sw, conf) != 0)
|
||||
return 1;
|
||||
for (;;) {
|
||||
redraw(&s);
|
||||
draw_history(&s, 0);
|
||||
draw_sidebar(&s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, prompt_mark());
|
||||
wnoutrefresh(ui_input);
|
||||
@@ -3058,6 +3311,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model,
|
||||
s.scroll = 0;
|
||||
add_entry(&s, "you", input);
|
||||
draw_history(&s, 0);
|
||||
draw_sidebar(&s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.working"));
|
||||
wrefresh(ui_input);
|
||||
@@ -3079,7 +3333,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model,
|
||||
snprintf(input, sizeof(input), "%s", pending);
|
||||
s.scroll = 0;
|
||||
add_entry(&s, "you", input);
|
||||
redraw(&s);
|
||||
redraw(&s, ag, host);
|
||||
(void)ui_turn(&s, ag, host, input, pending,
|
||||
sizeof(pending));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user