version 1.189, 2021/06/10 07:24:10 |
version 1.190, 2021/08/11 20:49:55 |
|
|
struct window_pane *wp; |
struct window_pane *wp; |
struct bufferevent *event; |
struct bufferevent *event; |
struct screen_write_ctx ctx; |
struct screen_write_ctx ctx; |
|
struct colour_palette *palette; |
|
|
struct input_cell cell; |
struct input_cell cell; |
|
|
|
|
|
|
/* Initialise input parser. */ |
/* Initialise input parser. */ |
struct input_ctx * |
struct input_ctx * |
input_init(struct window_pane *wp, struct bufferevent *bev) |
input_init(struct window_pane *wp, struct bufferevent *bev, |
|
struct colour_palette *palette) |
{ |
{ |
struct input_ctx *ictx; |
struct input_ctx *ictx; |
|
|
ictx = xcalloc(1, sizeof *ictx); |
ictx = xcalloc(1, sizeof *ictx); |
ictx->wp = wp; |
ictx->wp = wp; |
ictx->event = bev; |
ictx->event = bev; |
|
ictx->palette = palette; |
|
|
ictx->input_space = INPUT_BUF_START; |
ictx->input_space = INPUT_BUF_START; |
ictx->input_buf = xmalloc(INPUT_BUF_START); |
ictx->input_buf = xmalloc(INPUT_BUF_START); |
|
|
input_esc_dispatch(struct input_ctx *ictx) |
input_esc_dispatch(struct input_ctx *ictx) |
{ |
{ |
struct screen_write_ctx *sctx = &ictx->ctx; |
struct screen_write_ctx *sctx = &ictx->ctx; |
struct window_pane *wp = ictx->wp; |
|
struct screen *s = sctx->s; |
struct screen *s = sctx->s; |
struct input_table_entry *entry; |
struct input_table_entry *entry; |
|
|
|
|
|
|
switch (entry->type) { |
switch (entry->type) { |
case INPUT_ESC_RIS: |
case INPUT_ESC_RIS: |
if (wp != NULL) |
colour_palette_clear(ictx->palette); |
window_pane_reset_palette(wp); |
|
input_reset_cell(ictx); |
input_reset_cell(ictx); |
screen_write_reset(sctx); |
screen_write_reset(sctx); |
|
screen_write_fullredraw(sctx); |
break; |
break; |
case INPUT_ESC_IND: |
case INPUT_ESC_IND: |
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); |
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); |
|
|
case 0: |
case 0: |
case 2: |
case 2: |
screen_pop_title(sctx->s); |
screen_pop_title(sctx->s); |
if (wp != NULL) { |
if (wp == NULL) |
notify_pane("pane-title-changed", wp); |
break; |
server_redraw_window_borders(wp->window); |
notify_pane("pane-title-changed", wp); |
server_status_window(wp->window); |
server_redraw_window_borders(wp->window); |
} |
server_status_window(wp->window); |
break; |
break; |
} |
} |
break; |
break; |
|
|
static void |
static void |
input_osc_4(struct input_ctx *ictx, const char *p) |
input_osc_4(struct input_ctx *ictx, const char *p) |
{ |
{ |
struct window_pane *wp = ictx->wp; |
char *copy, *s, *next = NULL; |
char *copy, *s, *next = NULL; |
long idx; |
long idx; |
int c, bad = 0, redraw = 0; |
int c; |
|
|
|
if (wp == NULL) |
|
return; |
|
|
|
copy = s = xstrdup(p); |
copy = s = xstrdup(p); |
while (s != NULL && *s != '\0') { |
while (s != NULL && *s != '\0') { |
idx = strtol(s, &next, 10); |
idx = strtol(s, &next, 10); |
if (*next++ != ';') |
if (*next++ != ';') { |
goto bad; |
bad = 1; |
if (idx < 0 || idx >= 0x100) |
break; |
goto bad; |
} |
|
if (idx < 0 || idx >= 256) { |
|
bad = 1; |
|
break; |
|
} |
|
|
s = strsep(&next, ";"); |
s = strsep(&next, ";"); |
if ((c = input_osc_parse_colour(s)) == -1) { |
if ((c = input_osc_parse_colour(s)) == -1) { |
s = next; |
s = next; |
continue; |
continue; |
} |
} |
|
if (colour_palette_set(ictx->palette, idx, c)) |
window_pane_set_palette(wp, idx, c); |
redraw = 1; |
s = next; |
s = next; |
} |
} |
|
if (bad) |
|
log_debug("bad OSC 4: %s", p); |
|
if (redraw) |
|
screen_write_fullredraw(&ictx->ctx); |
free(copy); |
free(copy); |
return; |
|
|
|
bad: |
|
log_debug("bad OSC 4: %s", p); |
|
free(copy); |
|
} |
} |
|
|
/* Handle the OSC 10 sequence for setting and querying foreground colour. */ |
/* Handle the OSC 10 sequence for setting and querying foreground colour. */ |
|
|
struct grid_cell defaults; |
struct grid_cell defaults; |
int c; |
int c; |
|
|
if (wp == NULL) |
|
return; |
|
|
|
if (strcmp(p, "?") == 0) { |
if (strcmp(p, "?") == 0) { |
tty_default_colours(&defaults, wp); |
if (wp != NULL) { |
input_osc_colour_reply(ictx, 10, defaults.fg); |
tty_default_colours(&defaults, wp); |
|
input_osc_colour_reply(ictx, 10, defaults.fg); |
|
} |
return; |
return; |
} |
} |
|
|
if ((c = input_osc_parse_colour(p)) == -1) |
if ((c = input_osc_parse_colour(p)) == -1) { |
goto bad; |
log_debug("bad OSC 10: %s", p); |
wp->fg = c; |
return; |
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); |
} |
|
ictx->palette->fg = c; |
return; |
if (wp != NULL) |
|
wp->flags |= PANE_STYLECHANGED; |
bad: |
screen_write_fullredraw(&ictx->ctx); |
log_debug("bad OSC 10: %s", p); |
|
} |
} |
|
|
/* Handle the OSC 110 sequence for resetting background colour. */ |
/* Handle the OSC 110 sequence for resetting background colour. */ |
|
|
{ |
{ |
struct window_pane *wp = ictx->wp; |
struct window_pane *wp = ictx->wp; |
|
|
if (wp == NULL) |
|
return; |
|
|
|
if (*p != '\0') |
if (*p != '\0') |
return; |
return; |
|
ictx->palette->fg = 8; |
wp->fg = 8; |
if (wp != NULL) |
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); |
wp->flags |= PANE_STYLECHANGED; |
|
screen_write_fullredraw(&ictx->ctx); |
} |
} |
|
|
/* Handle the OSC 11 sequence for setting and querying background colour. */ |
/* Handle the OSC 11 sequence for setting and querying background colour. */ |
|
|
struct grid_cell defaults; |
struct grid_cell defaults; |
int c; |
int c; |
|
|
if (wp == NULL) |
|
return; |
|
|
|
if (strcmp(p, "?") == 0) { |
if (strcmp(p, "?") == 0) { |
tty_default_colours(&defaults, wp); |
if (wp != NULL) { |
input_osc_colour_reply(ictx, 11, defaults.bg); |
tty_default_colours(&defaults, wp); |
|
input_osc_colour_reply(ictx, 11, defaults.bg); |
|
} |
return; |
return; |
} |
} |
|
|
if ((c = input_osc_parse_colour(p)) == -1) |
if ((c = input_osc_parse_colour(p)) == -1) { |
goto bad; |
log_debug("bad OSC 11: %s", p); |
wp->bg = c; |
return; |
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); |
} |
|
ictx->palette->bg = c; |
return; |
if (wp != NULL) |
|
wp->flags |= PANE_STYLECHANGED; |
bad: |
screen_write_fullredraw(&ictx->ctx); |
log_debug("bad OSC 11: %s", p); |
|
} |
} |
|
|
/* Handle the OSC 111 sequence for resetting background colour. */ |
/* Handle the OSC 111 sequence for resetting background colour. */ |
|
|
{ |
{ |
struct window_pane *wp = ictx->wp; |
struct window_pane *wp = ictx->wp; |
|
|
if (wp == NULL) |
|
return; |
|
|
|
if (*p != '\0') |
if (*p != '\0') |
return; |
return; |
|
ictx->palette->bg = 8; |
wp->bg = 8; |
if (wp != NULL) |
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); |
wp->flags |= PANE_STYLECHANGED; |
|
screen_write_fullredraw(&ictx->ctx); |
} |
} |
|
|
/* Handle the OSC 52 sequence for setting the clipboard. */ |
/* Handle the OSC 52 sequence for setting the clipboard. */ |
|
|
static void |
static void |
input_osc_104(struct input_ctx *ictx, const char *p) |
input_osc_104(struct input_ctx *ictx, const char *p) |
{ |
{ |
struct window_pane *wp = ictx->wp; |
char *copy, *s; |
char *copy, *s; |
long idx; |
long idx; |
int bad = 0, redraw = 0; |
|
|
if (wp == NULL) |
|
return; |
|
|
|
if (*p == '\0') { |
if (*p == '\0') { |
window_pane_reset_palette(wp); |
colour_palette_clear(ictx->palette); |
|
screen_write_fullredraw(&ictx->ctx); |
return; |
return; |
} |
} |
|
|
copy = s = xstrdup(p); |
copy = s = xstrdup(p); |
while (*s != '\0') { |
while (*s != '\0') { |
idx = strtol(s, &s, 10); |
idx = strtol(s, &s, 10); |
if (*s != '\0' && *s != ';') |
if (*s != '\0' && *s != ';') { |
goto bad; |
bad = 1; |
if (idx < 0 || idx >= 0x100) |
break; |
goto bad; |
} |
|
if (idx < 0 || idx >= 256) { |
window_pane_unset_palette(wp, idx); |
bad = 1; |
|
break; |
|
} |
|
if (colour_palette_set(ictx->palette, idx, -1)) |
|
redraw = 1; |
if (*s == ';') |
if (*s == ';') |
s++; |
s++; |
} |
} |
free(copy); |
if (bad) |
return; |
log_debug("bad OSC 104: %s", p); |
|
if (redraw) |
bad: |
screen_write_fullredraw(&ictx->ctx); |
log_debug("bad OSC 104: %s", p); |
|
free(copy); |
free(copy); |
} |
} |