Instead of loads of little screen_write_*_on and off functions which

just change mode flags, just have screen_write_mode_set and
screen_write_mode_clear.
This commit is contained in:
Nicholas Marriott 2013-03-21 18:47:56 +00:00
parent c5504af4a6
commit 10682b9e7e
3 changed files with 44 additions and 125 deletions

37
input.c
View File

@ -1033,10 +1033,10 @@ input_esc_dispatch(struct input_ctx *ictx)
screen_write_reverseindex(sctx); screen_write_reverseindex(sctx);
break; break;
case INPUT_ESC_DECKPAM: case INPUT_ESC_DECKPAM:
screen_write_kkeypadmode(sctx, 1); screen_write_mode_set(sctx, MODE_KKEYPAD);
break; break;
case INPUT_ESC_DECKPNM: case INPUT_ESC_DECKPNM:
screen_write_kkeypadmode(sctx, 0); screen_write_mode_clear(sctx, MODE_KKEYPAD);
break; break;
case INPUT_ESC_DECSC: case INPUT_ESC_DECSC:
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell); memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
@ -1232,7 +1232,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_RM: case INPUT_CSI_RM:
switch (input_get(ictx, 0, 0, -1)) { switch (input_get(ictx, 0, 0, -1)) {
case 4: /* IRM */ case 4: /* IRM */
screen_write_insertmode(&ictx->ctx, 0); screen_write_mode_clear(&ictx->ctx, MODE_INSERT);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1242,23 +1242,23 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_RM_PRIVATE: case INPUT_CSI_RM_PRIVATE:
switch (input_get(ictx, 0, 0, -1)) { switch (input_get(ictx, 0, 0, -1)) {
case 1: /* GATM */ case 1: /* GATM */
screen_write_kcursormode(&ictx->ctx, 0); screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR);
break; break;
case 3: /* DECCOLM */ case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(&ictx->ctx, 0, 0);
screen_write_clearscreen(&ictx->ctx); screen_write_clearscreen(&ictx->ctx);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
screen_write_cursormode(&ictx->ctx, 0); screen_write_mode_clear(&ictx->ctx, MODE_CURSOR);
break; break;
case 1000: case 1000:
case 1001: case 1001:
case 1002: case 1002:
case 1003: case 1003:
screen_write_mousemode_off(&ictx->ctx); screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
break; break;
case 1005: case 1005:
screen_write_utf8mousemode(&ictx->ctx, 0); screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_UTF8);
break; break;
case 47: case 47:
case 1047: case 1047:
@ -1268,7 +1268,7 @@ input_csi_dispatch(struct input_ctx *ictx)
window_pane_alternate_off(wp, &ictx->cell, 1); window_pane_alternate_off(wp, &ictx->cell, 1);
break; break;
case 2004: case 2004:
screen_write_bracketpaste(&ictx->ctx, 0); screen_write_mode_clear(&ictx->ctx, MODE_BRACKETPASTE);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1286,7 +1286,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_SM: case INPUT_CSI_SM:
switch (input_get(ictx, 0, 0, -1)) { switch (input_get(ictx, 0, 0, -1)) {
case 4: /* IRM */ case 4: /* IRM */
screen_write_insertmode(&ictx->ctx, 1); screen_write_mode_set(&ictx->ctx, MODE_INSERT);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1296,28 +1296,29 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_SM_PRIVATE: case INPUT_CSI_SM_PRIVATE:
switch (input_get(ictx, 0, 0, -1)) { switch (input_get(ictx, 0, 0, -1)) {
case 1: /* GATM */ case 1: /* GATM */
screen_write_kcursormode(&ictx->ctx, 1); screen_write_mode_set(&ictx->ctx, MODE_KCURSOR);
break; break;
case 3: /* DECCOLM */ case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(&ictx->ctx, 0, 0);
screen_write_clearscreen(&ictx->ctx); screen_write_clearscreen(&ictx->ctx);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
screen_write_cursormode(&ictx->ctx, 1); screen_write_mode_set(&ictx->ctx, MODE_CURSOR);
break; break;
case 1000: case 1000:
screen_write_mousemode_on( screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
&ictx->ctx, MODE_MOUSE_STANDARD); screen_write_mode_set(&ictx->ctx, MODE_MOUSE_STANDARD);
break; break;
case 1002: case 1002:
screen_write_mousemode_on( screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
&ictx->ctx, MODE_MOUSE_BUTTON); screen_write_mode_set(&ictx->ctx, MODE_MOUSE_BUTTON);
break; break;
case 1003: case 1003:
screen_write_mousemode_on(&ictx->ctx, MODE_MOUSE_ANY); screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_ANY);
break; break;
case 1005: case 1005:
screen_write_utf8mousemode(&ictx->ctx, 1); screen_write_mode_set(&ictx->ctx, MODE_MOUSE_UTF8);
break; break;
case 47: case 47:
case 1047: case 1047:
@ -1327,7 +1328,7 @@ input_csi_dispatch(struct input_ctx *ictx)
window_pane_alternate_on(wp, &ictx->cell, 1); window_pane_alternate_on(wp, &ictx->cell, 1);
break; break;
case 2004: case 2004:
screen_write_bracketpaste(&ictx->ctx, 1); screen_write_mode_set(&ictx->ctx, MODE_BRACKETPASTE);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);

View File

@ -52,14 +52,11 @@ screen_write_stop(unused struct screen_write_ctx *ctx)
void void
screen_write_reset(struct screen_write_ctx *ctx) screen_write_reset(struct screen_write_ctx *ctx)
{ {
screen_reset_tabs(ctx->s); struct screen *s = ctx->s;
screen_write_scrollregion(ctx, 0, screen_size_y(ctx->s) - 1); screen_reset_tabs(s);
screen_write_scrollregion(ctx, 0, screen_size_y(s) - 1);
screen_write_insertmode(ctx, 0); s->mode &= ~(MODE_INSERT|MODE_KCURSOR|MODE_KKEYPAD|ALL_MOUSE_MODES);
screen_write_kcursormode(ctx, 0);
screen_write_kkeypadmode(ctx, 0);
screen_write_mousemode_off(ctx);
screen_write_clearscreen(ctx); screen_write_clearscreen(ctx);
screen_write_cursormove(ctx, 0, 0); screen_write_cursormove(ctx, 0, 0);
@ -454,6 +451,24 @@ screen_write_initctx(
memcpy(&ttyctx->last_cell, gc, sizeof ttyctx->last_cell); memcpy(&ttyctx->last_cell, gc, sizeof ttyctx->last_cell);
} }
/* Set a mode. */
void
screen_write_mode_set(struct screen_write_ctx *ctx, int mode)
{
struct screen *s = ctx->s;
s->mode |= mode;
}
/* Clear a mode. */
void
screen_write_mode_clear(struct screen_write_ctx *ctx, int mode)
{
struct screen *s = ctx->s;
s->mode &= ~mode;
}
/* Cursor up by ny. */ /* Cursor up by ny. */
void void
screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny) screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny)
@ -805,18 +820,6 @@ screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py)
s->cy = py; s->cy = py;
} }
/* Set cursor mode. */
void
screen_write_cursormode(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_CURSOR;
else
s->mode &= ~MODE_CURSOR;
}
/* Reverse index (up with scroll). */ /* Reverse index (up with scroll). */
void void
screen_write_reverseindex(struct screen_write_ctx *ctx) screen_write_reverseindex(struct screen_write_ctx *ctx)
@ -856,61 +859,6 @@ screen_write_scrollregion(
s->rlower = rlower; s->rlower = rlower;
} }
/* Set insert mode. */
void
screen_write_insertmode(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_INSERT;
else
s->mode &= ~MODE_INSERT;
}
/* Set UTF-8 mouse mode. */
void
screen_write_utf8mousemode(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_MOUSE_UTF8;
else
s->mode &= ~MODE_MOUSE_UTF8;
}
/* Set mouse mode off. */
void
screen_write_mousemode_off(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
s->mode &= ~ALL_MOUSE_MODES;
}
/* Set mouse mode on. */
void
screen_write_mousemode_on(struct screen_write_ctx *ctx, int mode)
{
struct screen *s = ctx->s;
s->mode &= ~ALL_MOUSE_MODES;
s->mode |= mode;
}
/* Set bracketed paste mode. */
void
screen_write_bracketpaste(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_BRACKETPASTE;
else
s->mode &= ~MODE_BRACKETPASTE;
}
/* Line feed. */ /* Line feed. */
void void
screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped)
@ -945,30 +893,6 @@ screen_write_carriagereturn(struct screen_write_ctx *ctx)
s->cx = 0; s->cx = 0;
} }
/* Set keypad cursor keys mode. */
void
screen_write_kcursormode(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_KCURSOR;
else
s->mode &= ~MODE_KCURSOR;
}
/* Set keypad number keys mode. */
void
screen_write_kkeypadmode(struct screen_write_ctx *ctx, int state)
{
struct screen *s = ctx->s;
if (state)
s->mode |= MODE_KKEYPAD;
else
s->mode &= ~MODE_KKEYPAD;
}
/* Clear to end of screen from cursor. */ /* Clear to end of screen from cursor. */
void void
screen_write_clearendofscreen(struct screen_write_ctx *ctx) screen_write_clearendofscreen(struct screen_write_ctx *ctx)

12
tmux.h
View File

@ -1206,7 +1206,7 @@ struct tty {
#define TTY_NOCURSOR 0x1 #define TTY_NOCURSOR 0x1
#define TTY_FREEZE 0x2 #define TTY_FREEZE 0x2
#define TTY_ESCAPE 0x4 #define TTY_TIMER 0x4
#define TTY_UTF8 0x8 #define TTY_UTF8 0x8
#define TTY_STARTED 0x10 #define TTY_STARTED 0x10
#define TTY_OPENED 0x20 #define TTY_OPENED 0x20
@ -2016,6 +2016,8 @@ void screen_write_putc(
void screen_write_copy(struct screen_write_ctx *, void screen_write_copy(struct screen_write_ctx *,
struct screen *, u_int, u_int, u_int, u_int); struct screen *, u_int, u_int, u_int, u_int);
void screen_write_backspace(struct screen_write_ctx *); void screen_write_backspace(struct screen_write_ctx *);
void screen_write_mode_set(struct screen_write_ctx *, int);
void screen_write_mode_clear(struct screen_write_ctx *, int);
void screen_write_cursorup(struct screen_write_ctx *, u_int); void screen_write_cursorup(struct screen_write_ctx *, u_int);
void screen_write_cursordown(struct screen_write_ctx *, u_int); void screen_write_cursordown(struct screen_write_ctx *, u_int);
void screen_write_cursorright(struct screen_write_ctx *, u_int); void screen_write_cursorright(struct screen_write_ctx *, u_int);
@ -2030,18 +2032,11 @@ void screen_write_clearline(struct screen_write_ctx *);
void screen_write_clearendofline(struct screen_write_ctx *); void screen_write_clearendofline(struct screen_write_ctx *);
void screen_write_clearstartofline(struct screen_write_ctx *); void screen_write_clearstartofline(struct screen_write_ctx *);
void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int); void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int);
void screen_write_cursormode(struct screen_write_ctx *, int);
void screen_write_reverseindex(struct screen_write_ctx *); void screen_write_reverseindex(struct screen_write_ctx *);
void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
void screen_write_insertmode(struct screen_write_ctx *, int);
void screen_write_utf8mousemode(struct screen_write_ctx *, int);
void screen_write_mousemode_on(struct screen_write_ctx *, int);
void screen_write_mousemode_off(struct screen_write_ctx *);
void screen_write_linefeed(struct screen_write_ctx *, int); void screen_write_linefeed(struct screen_write_ctx *, int);
void screen_write_linefeedscreen(struct screen_write_ctx *, int); void screen_write_linefeedscreen(struct screen_write_ctx *, int);
void screen_write_carriagereturn(struct screen_write_ctx *); void screen_write_carriagereturn(struct screen_write_ctx *);
void screen_write_kcursormode(struct screen_write_ctx *, int);
void screen_write_kkeypadmode(struct screen_write_ctx *, int);
void screen_write_clearendofscreen(struct screen_write_ctx *); void screen_write_clearendofscreen(struct screen_write_ctx *);
void screen_write_clearstartofscreen(struct screen_write_ctx *); void screen_write_clearstartofscreen(struct screen_write_ctx *);
void screen_write_clearscreen(struct screen_write_ctx *); void screen_write_clearscreen(struct screen_write_ctx *);
@ -2049,7 +2044,6 @@ void screen_write_clearhistory(struct screen_write_ctx *);
void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *); void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
void screen_write_setselection(struct screen_write_ctx *, u_char *, u_int); void screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
void screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int); void screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
void screen_write_bracketpaste(struct screen_write_ctx *, int);
/* screen-redraw.c */ /* screen-redraw.c */
void screen_redraw_screen(struct client *, int, int); void screen_redraw_screen(struct client *, int, int);