ui: drop the sidebar and the status bar for good
They were already invisible (the windows were NULL and every draw returned early); keeping the code around meant two layouts in one file and four windows worth of thinking for a screen that has one text field. draw_sidebar, draw_status, their helpers and usage_line go, together with the ui_side and ui_status windows; the fleet is polled where the status bar used to poll it. The file header now shows the layout it has, not the one it used to have. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c215fd8101
commit
fdf8b2888d
2 files changed
+50
-377
No files matched your search
+1
-1
@@ -57,7 +57,7 @@ struct sp_plugin_kv {
|
||||
*/
|
||||
struct sp_exit {
|
||||
char id[32];
|
||||
char label[64]; /* what shows up in the sidebar */
|
||||
char label[64]; /* the short name /usage and the logs show */
|
||||
char endpoint[512];
|
||||
char model[256];
|
||||
char key_env[64];
|
||||
|
||||
@@ -4,17 +4,24 @@
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Layout, fixed and deliberate:
|
||||
* Layout, fixed and deliberate: one text field, and the input below it.
|
||||
*
|
||||
* +---------------------------------+------------+
|
||||
* | history | sidebar |
|
||||
* | three quarters | one quarter|
|
||||
* +---------------------------------+------------+
|
||||
* | status bar |
|
||||
* +----------------------------------------------+
|
||||
* | ready. |
|
||||
* | you wie gross ist ../xsrc? |
|
||||
* | splinter Etwa 1,2 GB. |
|
||||
* | |
|
||||
* +----------------------------------------------+
|
||||
* | build> |
|
||||
* +----------------------------------------------+
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* Only the UI thread ever calls into curses. Anything that wants to appear on
|
||||
* screen 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.
|
||||
@@ -118,9 +125,7 @@ sp_ui_start_agent(const char *name)
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -1205,189 +1210,6 @@ 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++;
|
||||
}
|
||||
}
|
||||
|
||||
/* names of widgets the sidebar does not repeat: the status line has them */
|
||||
static int
|
||||
widget_hidden(const char *name)
|
||||
{
|
||||
return !strcmp(name, "clock") || !strcmp(name, "cps") ||
|
||||
!strcmp(name, "scheduler");
|
||||
}
|
||||
|
||||
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' || widget_hidden(name) || 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) - 1) {
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.session"));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
side_text(&y, cols, id, 1);
|
||||
}
|
||||
wattrset(ui_side, A_NORMAL);
|
||||
|
||||
wnoutrefresh(ui_side);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feed the meter the status plugins read. The harness counts; a plugin must not
|
||||
@@ -1419,101 +1241,6 @@ update_meter(struct ui_state *s, struct sp_host *host)
|
||||
sp_host_meter_update(host, set_ui_fields, s);
|
||||
}
|
||||
|
||||
/*
|
||||
* What is left of each allowance, for the status line: the provider the run is
|
||||
* on, then every delegate that has a limit or is benched. Read from the usage
|
||||
* logs at most every few seconds -- the line repaints twice a second.
|
||||
*/
|
||||
static void
|
||||
usage_line(struct ui_state *s, char *buf, size_t cap)
|
||||
{
|
||||
static char cache[160];
|
||||
static time_t at;
|
||||
time_t now = time(NULL);
|
||||
|
||||
if (now - at >= 5 || cache[0] == '\0') {
|
||||
struct sp_usage u;
|
||||
char b[96];
|
||||
|
||||
at = now;
|
||||
cache[0] = '\0';
|
||||
sp_usage_for(s->conf, sp_usage_active(), &u);
|
||||
/* the sidebar has the figures; here only a warning */
|
||||
if (u.benched_until > 0 || u.frac >= 0.8) {
|
||||
sp_usage_brief(&u, b, sizeof(b));
|
||||
snprintf(cache, sizeof(cache), "%s: %s",
|
||||
sp_usage_active(), b);
|
||||
}
|
||||
}
|
||||
snprintf(buf, cap, "%s", cache);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_status(struct ui_state *s, const char *running)
|
||||
{
|
||||
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); /* 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));
|
||||
mvwhline(ui_status, 0, 0, ' ', cols);
|
||||
mvwprintw(ui_status, 0, 1, sp_t("status.title"), SP_VERSION);
|
||||
if (s->agents.n > 0) {
|
||||
char tag[80];
|
||||
|
||||
snprintf(tag, sizeof(tag), "[%s]", s->agents.v[s->agent_cur].name);
|
||||
wattron(ui_status, A_BOLD);
|
||||
mvwaddnstr(ui_status, 0, at, tag, cols - at - 1);
|
||||
wattroff(ui_status, A_BOLD);
|
||||
at += (int)strlen(tag) + 1;
|
||||
}
|
||||
if (running != NULL && *running != '\0') {
|
||||
mvwaddnstr(ui_status, 0, at, running, cols - at - 1);
|
||||
at += (int)strlen(running) + 1;
|
||||
} else if (g_status_host != NULL) {
|
||||
char seg[512];
|
||||
size_t n;
|
||||
|
||||
update_meter(s, g_status_host);
|
||||
n = sp_host_status_text(g_status_host, seg, sizeof(seg));
|
||||
if (n > 0 && at + (int)n < cols) {
|
||||
mvwaddnstr(ui_status, 0, at, seg, cols - at);
|
||||
at += (int)n + 1;
|
||||
}
|
||||
}
|
||||
if (swbuf[0] != '\0' && at < cols - 2)
|
||||
mvwaddnstr(ui_status, 0, at, swbuf, cols - at - 1);
|
||||
{
|
||||
char right[96], use[256];
|
||||
int ulen, pos;
|
||||
|
||||
if (s->last_ms > 0)
|
||||
snprintf(right, sizeof(right), "%.1fs ",
|
||||
(double)s->last_ms / 1000.0);
|
||||
else
|
||||
right[0] = '\0';
|
||||
usage_line(s, use, sizeof(use));
|
||||
ulen = (int)strlen(use);
|
||||
pos = cols - (int)strlen(right) - 2 - ulen;
|
||||
if (ulen > 0 && pos > at + 1)
|
||||
mvwaddnstr(ui_status, 0, pos, use, ulen);
|
||||
if (right[0] != '\0' && (int)strlen(right) + 1 < cols)
|
||||
mvwaddnstr(ui_status, 0, cols - (int)strlen(right) - 1,
|
||||
right, cols - 1);
|
||||
}
|
||||
wattroff(ui_status, COLOR_PAIR(PAIR_STATUS));
|
||||
wnoutrefresh(ui_status);
|
||||
}
|
||||
|
||||
static void
|
||||
hist_load(struct ui_state *s, const char *dir)
|
||||
@@ -1735,8 +1462,6 @@ layout(void)
|
||||
*/
|
||||
ui_hist = newwin(rows - 1, cols, 0, 0);
|
||||
wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
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);
|
||||
@@ -1746,37 +1471,31 @@ layout(void)
|
||||
|
||||
/*
|
||||
* The terminal changed size: the windows were cut for the old one. layout()
|
||||
* used to run once, so after a resize the four windows kept their old
|
||||
* geometry and drew over each other.
|
||||
* used to run once, so after a resize the panes 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_status != NULL)
|
||||
delwin(ui_status);
|
||||
if (ui_input != NULL)
|
||||
delwin(ui_input);
|
||||
ui_hist = ui_side = ui_status = ui_input = NULL;
|
||||
ui_hist = ui_input = NULL;
|
||||
layout();
|
||||
wtimeout(ui_input, input_timeout_ms);
|
||||
clearok(curscr, TRUE);
|
||||
}
|
||||
|
||||
/* the session id and directory the sidebar shows, NULL-safe */
|
||||
/* the session id and directory, NULL-safe */
|
||||
#define SESS_ID(ag) ((ag)->sess != NULL ? (ag)->sess->id : NULL)
|
||||
#define SESS_DIR(ag) ((ag)->sess != NULL ? (ag)->sess->dir : NULL)
|
||||
|
||||
/* history, sidebar and status line, then one doupdate() */
|
||||
/* the history and one doupdate() */
|
||||
static void
|
||||
redraw(struct ui_state *s, struct sp_agent *ag, struct sp_host *host)
|
||||
redraw(struct ui_state *s)
|
||||
{
|
||||
draw_history(s, 0);
|
||||
draw_sidebar(s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
draw_status(s, NULL);
|
||||
doupdate();
|
||||
}
|
||||
|
||||
@@ -1833,8 +1552,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 and repaints sidebar and status
|
||||
* line: a widget that ticks is useless if the screen only refreshes on a key.
|
||||
* 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.
|
||||
*/
|
||||
static int
|
||||
slash_add_match(char matches[][64], int *n, int max, const char *name)
|
||||
@@ -1943,8 +1662,6 @@ 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);
|
||||
draw_status(s, NULL);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -1973,8 +1690,6 @@ 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);
|
||||
draw_status(s, NULL);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -2020,8 +1735,6 @@ 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);
|
||||
draw_status(s, NULL);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -2036,8 +1749,6 @@ 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);
|
||||
draw_status(s, NULL);
|
||||
if (locked) {
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_td("ui.swarm_locked", "[swarm locked] "));
|
||||
@@ -2073,8 +1784,6 @@ 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_status(s, NULL);
|
||||
draw_prompt(input);
|
||||
wnoutrefresh(ui_input);
|
||||
doupdate();
|
||||
@@ -2116,16 +1825,14 @@ ui_read_line(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
for (i2 = 0; i2 < k && off + 2 < sizeof(hint); i2++)
|
||||
off += snprintf(hint + off, sizeof(hint) - off, "/%s ", m[i2]);
|
||||
{
|
||||
WINDOW *hw = ui_status != NULL ?
|
||||
ui_status : ui_hist;
|
||||
int hy = ui_status != NULL ? 0 :
|
||||
getmaxy(ui_hist) - 1;
|
||||
/* no status bar: the last row */
|
||||
int hy = 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);
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_STATUS));
|
||||
mvwhline(ui_hist, hy, 0, ' ', getmaxx(ui_hist));
|
||||
mvwaddnstr(ui_hist, hy, 0, hint, getmaxx(ui_hist) - 1);
|
||||
wattroff(ui_hist, COLOR_PAIR(PAIR_STATUS));
|
||||
wnoutrefresh(ui_hist);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2848,8 +2555,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_agent *ag, struct sp_host *host,
|
||||
struct turn *tu, struct turn_view *v)
|
||||
turn_paint(struct ui_state *s, struct sp_host *host, struct turn *tu,
|
||||
struct turn_view *v)
|
||||
{
|
||||
char *think = NULL, *live = NULL;
|
||||
struct timespec now;
|
||||
@@ -2878,49 +2585,20 @@ turn_paint(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
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);
|
||||
|
||||
/*
|
||||
* Running state lives in the status bar; the prompt becomes the steering
|
||||
* line. One row for input, never wrapped - wrapped input scrolls the screen.
|
||||
* The prompt becomes the steering line: elapsed seconds, the tool that
|
||||
* is running, then what is typed. One row, never wrapped - wrapped input
|
||||
* scrolls the screen.
|
||||
*/
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
ms = (long)((now.tv_sec - v->t0.tv_sec) * 1000 +
|
||||
(now.tv_nsec - v->t0.tv_nsec) / 1000000);
|
||||
s->last_ms = ms;
|
||||
{
|
||||
char run[320];
|
||||
char tname[80] = "";
|
||||
char ctx[96] = "";
|
||||
|
||||
pthread_mutex_lock(&tu->lock);
|
||||
if (tu->tool_line[0] != '\0')
|
||||
snprintf(tname, sizeof(tname), " | %.60s", tu->tool_line);
|
||||
pthread_mutex_unlock(&tu->lock);
|
||||
update_meter(s, host);
|
||||
if (host != NULL) {
|
||||
struct sp_meter m;
|
||||
|
||||
sp_host_meter_get(host, &m);
|
||||
if (m.ctx_max > 0) {
|
||||
unsigned pct = (unsigned)(100.0 *
|
||||
(double)m.ctx_used / (double)m.ctx_max);
|
||||
char bar[13];
|
||||
size_t f = pct >= 100 ? 12 : (pct * 12 / 100), i;
|
||||
for (i = 0; i < 12; i++)
|
||||
bar[i] = i < f ? '|' : '.';
|
||||
bar[12] = '\0';
|
||||
snprintf(ctx, sizeof(ctx),
|
||||
" ctx %zu/%zu [%s] %u%% |",
|
||||
m.ctx_used, m.ctx_max, bar, pct);
|
||||
} else if (m.ctx_used > 0)
|
||||
snprintf(ctx, sizeof(ctx),
|
||||
" ctx %zu tok |", m.ctx_used);
|
||||
}
|
||||
snprintf(run, sizeof(run),
|
||||
sp_t("ui.running"), ms / 1000, tname, ctx);
|
||||
draw_status(s, run);
|
||||
}
|
||||
update_meter(s, host);
|
||||
werase(ui_input);
|
||||
w = getmaxx(ui_input) - 1;
|
||||
{
|
||||
@@ -2955,25 +2633,24 @@ turn_paint(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
* cancels and quits. Returns 1 when the turn was cancelled.
|
||||
*/
|
||||
static int
|
||||
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)
|
||||
turn_key(struct ui_state *s, 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, ag, host);
|
||||
redraw(s);
|
||||
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, ag, host);
|
||||
redraw(s);
|
||||
return 0;
|
||||
}
|
||||
if (c == KEY_RESIZE) {
|
||||
relayout(100);
|
||||
redraw(s, ag, host);
|
||||
redraw(s);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
@@ -3090,10 +2767,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, ag, host, &tu, &v);
|
||||
turn_paint(s, host, &tu, &v);
|
||||
continue;
|
||||
}
|
||||
if (turn_key(s, ag, host, &tu, &v, c, pending_steer,
|
||||
if (turn_key(s, &tu, &v, c, pending_steer,
|
||||
ps_cap)) {
|
||||
cancelled = 1;
|
||||
break;
|
||||
@@ -3129,7 +2806,7 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
_exit(1);
|
||||
}
|
||||
if (c2 == ERR)
|
||||
turn_paint(s, ag, host, &tu, &v);
|
||||
turn_paint(s, host, &tu, &v);
|
||||
}
|
||||
wtimeout(ui_input, -1);
|
||||
}
|
||||
@@ -3340,9 +3017,7 @@ 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 (;;) {
|
||||
draw_history(&s, 0);
|
||||
draw_sidebar(&s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
draw_status(&s, NULL);
|
||||
redraw(&s);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, prompt_mark());
|
||||
wnoutrefresh(ui_input);
|
||||
@@ -3383,8 +3058,6 @@ 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);
|
||||
draw_status(&s, NULL);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.working"));
|
||||
wrefresh(ui_input);
|
||||
@@ -3406,7 +3079,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, ag, host);
|
||||
redraw(&s);
|
||||
(void)ui_turn(&s, ag, host, input, pending,
|
||||
sizeof(pending));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user