mirror of
https://github.com/tmate-io/tmate.git
synced 2024-12-23 23:29:15 +01:00
enum tty_cmd is only used as an index into the array of command function
pointers, so remove it and use the function pointers directly to represent themselves.
This commit is contained in:
parent
6a309c53a8
commit
2ec2837daa
@ -327,7 +327,7 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx)
|
||||
s->rupper = 0;
|
||||
s->rlower = screen_size_y(s) - 1;
|
||||
|
||||
tty_write0(ctx->wp, TTY_ALIGNMENTTEST);
|
||||
tty_write0(ctx->wp, tty_cmd_alignmenttest);
|
||||
}
|
||||
|
||||
/* Insert nx characters. */
|
||||
@ -349,7 +349,7 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
|
||||
if (s->cx <= screen_size_x(s) - 1)
|
||||
grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_INSERTCHARACTER, nx);
|
||||
tty_writenum(ctx->wp, tty_cmd_insertcharacter, nx);
|
||||
}
|
||||
|
||||
/* Delete nx characters. */
|
||||
@ -371,7 +371,7 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
|
||||
if (s->cx <= screen_size_x(s) - 1)
|
||||
grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_DELETECHARACTER, nx);
|
||||
tty_writenum(ctx->wp, tty_cmd_deletecharacter, nx);
|
||||
}
|
||||
|
||||
/* Insert ny lines. */
|
||||
@ -393,7 +393,7 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
|
||||
|
||||
grid_view_insert_lines(s->grid, s->cy, ny);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_INSERTLINE, ny);
|
||||
tty_writenum(ctx->wp, tty_cmd_insertline, ny);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
|
||||
else
|
||||
grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_INSERTLINE, ny);
|
||||
tty_writenum(ctx->wp, tty_cmd_insertline, ny);
|
||||
}
|
||||
|
||||
/* Delete ny lines. */
|
||||
@ -431,7 +431,7 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
|
||||
|
||||
grid_view_delete_lines(s->grid, s->cy, ny);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_DELETELINE, ny);
|
||||
tty_writenum(ctx->wp, tty_cmd_deleteline, ny);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -447,7 +447,7 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
|
||||
else
|
||||
grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_DELETELINE, ny);
|
||||
tty_writenum(ctx->wp, tty_cmd_deleteline, ny);
|
||||
}
|
||||
|
||||
/* Clear line at cursor. */
|
||||
@ -460,7 +460,7 @@ screen_write_clearline(struct screen_write_ctx *ctx)
|
||||
|
||||
grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARLINE, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearline);
|
||||
}
|
||||
|
||||
/* Clear to end of line from cursor. */
|
||||
@ -477,7 +477,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx)
|
||||
if (s->cx <= sx - 1)
|
||||
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARENDOFLINE, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearendofline);
|
||||
}
|
||||
|
||||
/* Clear to start of line from cursor. */
|
||||
@ -496,7 +496,7 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx)
|
||||
else
|
||||
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARSTARTOFLINE, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearstartofline);
|
||||
}
|
||||
|
||||
/* Move cursor to px,py. */
|
||||
@ -539,7 +539,7 @@ screen_write_reverseindex(struct screen_write_ctx *ctx)
|
||||
else if (s->cy > 0)
|
||||
s->cy--;
|
||||
|
||||
tty_writenum(ctx->wp, TTY_REVERSEINDEX, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_reverseindex);
|
||||
}
|
||||
|
||||
/* Set scroll region. */
|
||||
@ -601,7 +601,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx)
|
||||
else if (s->cy < screen_size_y(s) - 1)
|
||||
s->cy++;
|
||||
|
||||
tty_writenum(ctx->wp, TTY_LINEFEED, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_linefeed);
|
||||
}
|
||||
|
||||
/* Carriage return (cursor to start of line). */
|
||||
@ -653,7 +653,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx)
|
||||
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
||||
grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARENDOFSCREEN, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearendofscreen);
|
||||
}
|
||||
|
||||
/* Clear to start of screen. */
|
||||
@ -674,7 +674,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
|
||||
else
|
||||
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARSTARTOFSCREEN, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearstartofscreen);
|
||||
}
|
||||
|
||||
/* Clear entire screen. */
|
||||
@ -687,7 +687,7 @@ screen_write_clearscreen(struct screen_write_ctx *ctx)
|
||||
|
||||
grid_view_clear(s->grid, 0, 0, screen_size_x(s), screen_size_y(s));
|
||||
|
||||
tty_writenum(ctx->wp, TTY_CLEARSCREEN, 0);
|
||||
tty_write0(ctx->wp, tty_cmd_clearscreen);
|
||||
}
|
||||
|
||||
/* Write cell data. */
|
||||
@ -737,7 +737,7 @@ screen_write_cell(
|
||||
memcpy(tmp_gu->data + i, udata, UTF8_SIZE - i);
|
||||
|
||||
/* Assume the previous character has just been input. */
|
||||
tty_writeptr(ctx->wp, TTY_UTF8CHARACTER, udata);
|
||||
tty_writeptr(ctx->wp, tty_cmd_utf8character, udata);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -790,16 +790,16 @@ screen_write_cell(
|
||||
|
||||
/* Draw to the screen if necessary. */
|
||||
if (insert)
|
||||
tty_writenum(ctx->wp, TTY_INSERTCHARACTER, width);
|
||||
tty_writenum(ctx->wp, tty_cmd_insertcharacter, width);
|
||||
ttyctx.wp = ctx->wp;
|
||||
ttyctx.utf8 = &gu;
|
||||
if (screen_check_selection(s, s->cx - width, s->cy)) {
|
||||
s->sel.cell.data = gc->data;
|
||||
ttyctx.cell = &s->sel.cell;
|
||||
tty_write_cmd(TTY_CELL, &ttyctx);
|
||||
tty_write(tty_cmd_cell, &ttyctx);
|
||||
} else {
|
||||
ttyctx.cell = gc;
|
||||
tty_write_cmd(TTY_CELL, &ttyctx);
|
||||
tty_write(tty_cmd_cell, &ttyctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
120
tmux.h
120
tmux.h
@ -273,35 +273,6 @@ struct tty_term_code_entry {
|
||||
const char *name;
|
||||
};
|
||||
|
||||
/* Output commands. */
|
||||
enum tty_cmd {
|
||||
TTY_ALIGNMENTTEST,
|
||||
TTY_CELL,
|
||||
TTY_CLEARENDOFLINE,
|
||||
TTY_CLEARENDOFSCREEN,
|
||||
TTY_CLEARLINE,
|
||||
TTY_CLEARSCREEN,
|
||||
TTY_CLEARSTARTOFLINE,
|
||||
TTY_CLEARSTARTOFSCREEN,
|
||||
TTY_DELETECHARACTER,
|
||||
TTY_DELETELINE,
|
||||
TTY_INSERTCHARACTER,
|
||||
TTY_INSERTLINE,
|
||||
TTY_LINEFEED,
|
||||
TTY_UTF8CHARACTER,
|
||||
TTY_REVERSEINDEX,
|
||||
};
|
||||
|
||||
struct tty_ctx {
|
||||
struct window_pane *wp;
|
||||
|
||||
const struct grid_cell *cell;
|
||||
const struct grid_utf8 *utf8;
|
||||
|
||||
u_int num;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
/* Message codes. */
|
||||
enum hdrtype {
|
||||
MSG_COMMAND,
|
||||
@ -805,6 +776,18 @@ struct tty {
|
||||
RB_HEAD(tty_keys, tty_key) ktree;
|
||||
};
|
||||
|
||||
/* TTY command context and function pointer. */
|
||||
struct tty_ctx {
|
||||
struct window_pane *wp;
|
||||
|
||||
const struct grid_cell *cell;
|
||||
const struct grid_utf8 *utf8;
|
||||
|
||||
u_int num;
|
||||
void *ptr;
|
||||
};
|
||||
typedef void tty_cmd_func(struct tty *, struct tty_ctx *);
|
||||
|
||||
/* Client connection. */
|
||||
struct client {
|
||||
int fd;
|
||||
@ -1032,33 +1015,42 @@ void options_set_number(struct options *, const char *, long long);
|
||||
long long options_get_number(struct options *, const char *);
|
||||
|
||||
/* tty.c */
|
||||
u_char tty_get_acs(struct tty *, u_char);
|
||||
void tty_emulate_repeat(struct tty *,
|
||||
enum tty_code_code, enum tty_code_code, u_int);
|
||||
void tty_reset(struct tty *);
|
||||
void tty_region(struct tty *, u_int, u_int, u_int);
|
||||
void tty_cursor(struct tty *, u_int, u_int, u_int, u_int);
|
||||
void tty_cell(struct tty *,
|
||||
const struct grid_cell *, const struct grid_utf8 *);
|
||||
void tty_putcode(struct tty *, enum tty_code_code);
|
||||
void tty_putcode1(struct tty *, enum tty_code_code, int);
|
||||
void tty_putcode2(struct tty *, enum tty_code_code, int, int);
|
||||
void tty_puts(struct tty *, const char *);
|
||||
void tty_putc(struct tty *, u_char);
|
||||
void tty_pututf8(struct tty *, const struct grid_utf8 *);
|
||||
void tty_init(struct tty *, char *, char *);
|
||||
void tty_start_tty(struct tty *);
|
||||
void tty_stop_tty(struct tty *);
|
||||
void tty_detect_utf8(struct tty *);
|
||||
void tty_set_title(struct tty *, const char *);
|
||||
void tty_update_mode(struct tty *, int);
|
||||
void tty_draw_line(
|
||||
struct tty *, struct screen *, u_int, u_int, u_int);
|
||||
void tty_redraw_region(struct tty *, struct window_pane *);
|
||||
int tty_open(struct tty *, char **);
|
||||
void tty_close(struct tty *, int);
|
||||
void tty_free(struct tty *, int);
|
||||
void tty_write(struct tty *, enum tty_cmd, struct tty_ctx *);
|
||||
u_char tty_get_acs(struct tty *, u_char);
|
||||
void tty_reset(struct tty *);
|
||||
void tty_region(struct tty *, u_int, u_int, u_int);
|
||||
void tty_cursor(struct tty *, u_int, u_int, u_int, u_int);
|
||||
void tty_putcode(struct tty *, enum tty_code_code);
|
||||
void tty_putcode1(struct tty *, enum tty_code_code, int);
|
||||
void tty_putcode2(struct tty *, enum tty_code_code, int, int);
|
||||
void tty_puts(struct tty *, const char *);
|
||||
void tty_putc(struct tty *, u_char);
|
||||
void tty_pututf8(struct tty *, const struct grid_utf8 *);
|
||||
void tty_init(struct tty *, char *, char *);
|
||||
void tty_start_tty(struct tty *);
|
||||
void tty_stop_tty(struct tty *);
|
||||
void tty_detect_utf8(struct tty *);
|
||||
void tty_set_title(struct tty *, const char *);
|
||||
void tty_update_mode(struct tty *, int);
|
||||
void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int);
|
||||
void tty_redraw_region(struct tty *, struct window_pane *);
|
||||
int tty_open(struct tty *, char **);
|
||||
void tty_close(struct tty *, int);
|
||||
void tty_free(struct tty *, int);
|
||||
void tty_cmd_alignmenttest(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_cell(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearendofline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearendofscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearstartofline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearstartofscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_deletecharacter(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_deleteline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_insertcharacter(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_insertline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_linefeed(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_utf8character(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_reverseindex(struct tty *, struct tty_ctx *);
|
||||
|
||||
/* tty-term.c */
|
||||
extern struct tty_terms tty_terms;
|
||||
@ -1074,17 +1066,17 @@ int tty_term_number(struct tty_term *, enum tty_code_code);
|
||||
int tty_term_flag(struct tty_term *, enum tty_code_code);
|
||||
|
||||
/* tty-keys.c */
|
||||
int tty_keys_cmp(struct tty_key *, struct tty_key *);
|
||||
int tty_keys_cmp(struct tty_key *, struct tty_key *);
|
||||
RB_PROTOTYPE(tty_keys, tty_key, entry, tty_keys_cmp);
|
||||
void tty_keys_init(struct tty *);
|
||||
void tty_keys_free(struct tty *);
|
||||
int tty_keys_next(struct tty *, int *, u_char *);
|
||||
void tty_keys_init(struct tty *);
|
||||
void tty_keys_free(struct tty *);
|
||||
int tty_keys_next(struct tty *, int *, u_char *);
|
||||
|
||||
/* tty-write.c */
|
||||
void tty_write0(struct window_pane *, enum tty_cmd);
|
||||
void tty_writenum(struct window_pane *, enum tty_cmd, u_int);
|
||||
void tty_writeptr(struct window_pane *, enum tty_cmd, void *);
|
||||
void tty_write_cmd(enum tty_cmd, struct tty_ctx *);
|
||||
void tty_write0(struct window_pane *, tty_cmd_func *);
|
||||
void tty_writenum(struct window_pane *, tty_cmd_func *, u_int);
|
||||
void tty_writeptr(struct window_pane *, tty_cmd_func *, void *);
|
||||
void tty_write(tty_cmd_func *, struct tty_ctx *);
|
||||
|
||||
/* options-cmd.c */
|
||||
void set_option_string(struct cmd_ctx *,
|
||||
|
19
tty-write.c
19
tty-write.c
@ -23,39 +23,39 @@
|
||||
#include "tmux.h"
|
||||
|
||||
void
|
||||
tty_write0(struct window_pane *wp, enum tty_cmd cmd)
|
||||
tty_write0(struct window_pane *wp, tty_cmd_func *cmdfn)
|
||||
{
|
||||
struct tty_ctx ctx;
|
||||
|
||||
memset(&ctx, 0, sizeof ctx);
|
||||
ctx.wp = wp;
|
||||
tty_write_cmd(cmd, &ctx);
|
||||
tty_write(cmdfn, &ctx);
|
||||
}
|
||||
|
||||
void
|
||||
tty_writenum(struct window_pane *wp, enum tty_cmd cmd, u_int num)
|
||||
tty_writenum(struct window_pane *wp, tty_cmd_func *cmdfn, u_int num)
|
||||
{
|
||||
struct tty_ctx ctx;
|
||||
|
||||
memset(&ctx, 0, sizeof ctx);
|
||||
ctx.wp = wp;
|
||||
ctx.num = num;
|
||||
tty_write_cmd(cmd, &ctx);
|
||||
tty_write(cmdfn, &ctx);
|
||||
}
|
||||
|
||||
void
|
||||
tty_writeptr(struct window_pane *wp, enum tty_cmd cmd, void *ptr)
|
||||
tty_writeptr(struct window_pane *wp, tty_cmd_func *cmdfn, void *ptr)
|
||||
{
|
||||
struct tty_ctx ctx;
|
||||
|
||||
memset(&ctx, 0, sizeof ctx);
|
||||
ctx.wp = wp;
|
||||
ctx.ptr = ptr;
|
||||
tty_write_cmd(cmd, &ctx);
|
||||
tty_write(cmdfn, &ctx);
|
||||
}
|
||||
|
||||
void
|
||||
tty_write_cmd(enum tty_cmd cmd, struct tty_ctx *ctx)
|
||||
tty_write(tty_cmd_func *cmdfn, struct tty_ctx *ctx)
|
||||
{
|
||||
struct window_pane *wp = ctx->wp;
|
||||
struct client *c;
|
||||
@ -77,9 +77,10 @@ tty_write_cmd(enum tty_cmd cmd, struct tty_ctx *ctx)
|
||||
continue;
|
||||
|
||||
if (c->session->curw->window == wp->window) {
|
||||
if (c->tty.flags & TTY_FREEZE || c->tty.term == NULL)
|
||||
continue;
|
||||
tty_update_mode(&c->tty, c->tty.mode & ~MODE_CURSOR);
|
||||
|
||||
tty_write(&c->tty, cmd, ctx);
|
||||
cmdfn(&c->tty, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
46
tty.c
46
tty.c
@ -38,39 +38,10 @@ void tty_attributes(struct tty *, const struct grid_cell *);
|
||||
void tty_attributes_fg(struct tty *, const struct grid_cell *);
|
||||
void tty_attributes_bg(struct tty *, const struct grid_cell *);
|
||||
|
||||
void tty_cmd_alignmenttest(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_cell(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearendofline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearendofscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearstartofline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_clearstartofscreen(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_deletecharacter(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_deleteline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_insertcharacter(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_insertline(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_linefeed(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_utf8character(struct tty *, struct tty_ctx *);
|
||||
void tty_cmd_reverseindex(struct tty *, struct tty_ctx *);
|
||||
|
||||
void (*tty_cmds[])(struct tty *, struct tty_ctx *) = {
|
||||
tty_cmd_alignmenttest,
|
||||
tty_cmd_cell,
|
||||
tty_cmd_clearendofline,
|
||||
tty_cmd_clearendofscreen,
|
||||
tty_cmd_clearline,
|
||||
tty_cmd_clearscreen,
|
||||
tty_cmd_clearstartofline,
|
||||
tty_cmd_clearstartofscreen,
|
||||
tty_cmd_deletecharacter,
|
||||
tty_cmd_deleteline,
|
||||
tty_cmd_insertcharacter,
|
||||
tty_cmd_insertline,
|
||||
tty_cmd_linefeed,
|
||||
tty_cmd_utf8character,
|
||||
tty_cmd_reverseindex,
|
||||
};
|
||||
void tty_emulate_repeat(
|
||||
struct tty *, enum tty_code_code, enum tty_code_code, u_int);
|
||||
void tty_cell(struct tty *,
|
||||
const struct grid_cell *, const struct grid_utf8 *);
|
||||
|
||||
void
|
||||
tty_init(struct tty *tty, char *path, char *term)
|
||||
@ -544,15 +515,6 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tty_write(struct tty *tty, enum tty_cmd cmd, struct tty_ctx *ctx)
|
||||
{
|
||||
if (tty->flags & TTY_FREEZE || tty->term == NULL)
|
||||
return;
|
||||
if (tty_cmds[cmd] != NULL)
|
||||
tty_cmds[cmd](tty, ctx);
|
||||
}
|
||||
|
||||
void
|
||||
tty_cmd_insertcharacter(struct tty *tty, struct tty_ctx *ctx)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user