Major rework of prompts. The basic prompt mechanics (draw, editing, etc)

are now wrapped up in prompt*.c and do not depend on a client. These
functions are used to provide the original client prompt but also to
allow panes to have their own prompts, which works much much better for
floating panes. The mode prompts for both the tree modes and copy mode
are switched over to be per pane.

There are some visible changes (some of these may be changed if they
don't seem to be working well):

- Prompts in modes now appear in the bottom line, covering whatever
  content was there.

- command-prompt has a -P flag to open a pane prompt.

- Because they cover the content, the default style for prompts in modes
  now does not fill the entire line; the main command prompt stays the
  same.

- The old completion menu has gone, and completions are now shown after
  the text. Builtin aliases are no longer completed.

- Clicking the mouse on the prompt now moves the cursor or selects a
  completion.
This commit is contained in:
nicm
2026-06-25 11:39:11 +00:00
parent 6b1219b370
commit 51d037e881
19 changed files with 2811 additions and 1733 deletions

View File

@@ -489,10 +489,7 @@ server_client_lost(struct client *c)
free(c->message_string);
if (event_initialized(&c->message_timer))
evtimer_del(&c->message_timer);
free(c->prompt_saved);
free(c->prompt_string);
free(c->prompt_buffer);
prompt_free(c->prompt);
format_lost_client(c);
environ_free(c->environ);
@@ -1464,6 +1461,7 @@ server_client_handle_key0(struct client *c, struct key_event *event,
{
struct session *s = c->session;
struct cmdq_item *item;
struct window_pane *wp;
/* Check the client is good to accept input. */
if (s == NULL || (c->flags & CLIENT_UNATTACHEDFLAGS))
@@ -1493,6 +1491,7 @@ server_client_handle_key0(struct client *c, struct key_event *event,
return (0);
status_message_clear(c);
}
if (c->overlay_key != NULL) {
switch (c->overlay_key(c, c->overlay_data, event)) {
case 0:
@@ -1502,9 +1501,10 @@ server_client_handle_key0(struct client *c, struct key_event *event,
return (0);
}
}
server_client_clear_overlay(c);
if (c->prompt_string != NULL) {
switch (status_prompt_key(c, event->key)) {
if (c->prompt != NULL) {
switch (status_prompt_key(c, event->key, &event->m)) {
case PROMPT_KEY_HANDLED:
case PROMPT_KEY_CLOSE:
return (0);
@@ -1513,6 +1513,29 @@ server_client_handle_key0(struct client *c, struct key_event *event,
break;
}
}
wp = s->curw->window->active;
if (wp == NULL || !window_pane_has_prompt(wp)) {
TAILQ_FOREACH(wp, &s->curw->window->panes, entry) {
if (window_pane_has_prompt(wp) &&
window_pane_is_visible(wp))
break;
}
}
if (wp != NULL &&
window_pane_has_prompt(wp) &&
window_pane_is_visible(wp)) {
switch (window_pane_prompt_key(wp, c, event->key, &event->m)) {
case PROMPT_KEY_HANDLED:
case PROMPT_KEY_CLOSE:
case PROMPT_KEY_MOVE:
return (0);
case PROMPT_KEY_NOT_HANDLED:
if (KEYC_IS_MOUSE(event->key))
return (0);
break;
}
}
}
/*
@@ -1784,6 +1807,42 @@ out:
bufferevent_enable(wp->event, EV_READ);
}
/* Move cursor for pane prompt. */
static int
server_client_prompt_cursor(struct client *c, struct window_pane *wp, int *mode,
u_int *cx, u_int *cy)
{
struct tty *tty = &c->tty;
struct visible_ranges *r;
u_int ox, oy, sx, sy;
int px, py;
if (!window_pane_has_prompt(wp))
return (0);
*mode &= ~MODE_CURSOR;
tty_window_offset(tty, &ox, &oy, &sx, &sy);
if (status_at_line(c) == 0)
py = wp->yoff;
else
py = wp->yoff + wp->sy - 1;
px = wp->xoff + wp->prompt_cx;
if (px < (int)ox || px > (int)(ox + sx) ||
py < (int)oy || py > (int)(oy + sy))
return (1);
*cx = px - ox;
*cy = py - oy;
r = window_visible_ranges(wp, *cx, *cy, 1, NULL);
if (window_position_is_visible(r, *cx)) {
if (status_at_line(c) == 0)
*cy += status_line_size(c);
*mode |= MODE_CURSOR;
}
return (1);
}
/*
* Update cursor position and mode settings. The scroll region and attributes
* are cleared when idle (waiting for an event) as this is the most likely time
@@ -1802,7 +1861,7 @@ server_client_reset_state(struct client *c)
struct screen *s = NULL;
struct options *oo = c->session->options;
int mode = 0, cursor, flags, pane_mode = 0;
u_int cx = 0, cy = 0, ox, oy, sx, sy, n;
u_int cx = 0, cy = 0, ox, oy, sx, sy, prompt = 0;
struct visible_ranges *r;
if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED))
@@ -1816,7 +1875,7 @@ server_client_reset_state(struct client *c)
if (c->overlay_draw != NULL) {
if (c->overlay_mode != NULL)
s = c->overlay_mode(c, c->overlay_data, &cx, &cy);
} else if (wp != NULL && c->prompt_string == NULL)
} else if (wp != NULL && c->prompt == NULL)
s = wp->screen;
else
s = c->status.active;
@@ -1832,42 +1891,36 @@ server_client_reset_state(struct client *c)
tty_margin_off(tty);
/* Move cursor to pane cursor and offset. */
if (c->prompt_string != NULL) {
n = options_get_number(oo, "status-position");
if (n == 0)
cy = status_prompt_line_at(c);
else {
n = status_line_size(c) - status_prompt_line_at(c);
if (n <= tty->sy)
cy = tty->sy - n;
else
cy = tty->sy - 1;
}
cx = c->prompt_cursor;
if (c->prompt != NULL) {
prompt = 1;
status_prompt_cursor(c, &cx, &cy);
} else if (wp != NULL && c->overlay_draw == NULL) {
cursor = 0;
pane_mode = wp->base.mode;
prompt = server_client_prompt_cursor(c, wp, &mode, &cx, &cy);
if (!prompt) {
cursor = 0;
pane_mode = wp->base.mode;
tty_window_offset(tty, &ox, &oy, &sx, &sy);
if (wp->xoff + (int)s->cx >= (int)ox &&
wp->xoff + (int)s->cx <= (int)ox + (int)sx &&
wp->yoff + (int)s->cy >= (int)oy &&
wp->yoff + (int)s->cy <= (int)oy + (int)sy) {
cursor = 1;
tty_window_offset(tty, &ox, &oy, &sx, &sy);
if (wp->xoff + (int)s->cx >= (int)ox &&
wp->xoff + (int)s->cx <= (int)ox + (int)sx &&
wp->yoff + (int)s->cy >= (int)oy &&
wp->yoff + (int)s->cy <= (int)oy + (int)sy) {
cursor = 1;
cx = wp->xoff + (int)s->cx - (int)ox;
cy = wp->yoff + (int)s->cy - (int)oy;
cx = wp->xoff + (int)s->cx - (int)ox;
cy = wp->yoff + (int)s->cy - (int)oy;
r = window_visible_ranges(wp, cx, cy, 1, NULL);
if (!window_position_is_visible(r, cx))
cursor = 0;
r = window_visible_ranges(wp, cx, cy, 1, NULL);
if (!window_position_is_visible(r, cx))
cursor = 0;
if (status_at_line(c) == 0)
cy += status_line_size(c);
if (status_at_line(c) == 0)
cy += status_line_size(c);
}
if ((pane_mode & MODE_SYNC) || !cursor)
mode &= ~MODE_CURSOR;
}
if ((pane_mode & MODE_SYNC) || !cursor)
mode &= ~MODE_CURSOR;
} else if (c->overlay_mode == NULL || s == NULL)
mode &= ~MODE_CURSOR;
if (~pane_mode & MODE_SYNC) {
@@ -1895,7 +1948,7 @@ server_client_reset_state(struct client *c)
}
/* Clear bracketed paste mode if at the prompt. */
if (c->overlay_draw == NULL && c->prompt_string != NULL)
if (c->overlay_draw == NULL && prompt)
mode &= ~MODE_BRACKETPASTE;
/* Set the terminal mode and reset attributes. */