mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 10:08:47 +00:00
Simplify screen/tty write code to eliminate function pointer which is now
unnecessary (it always does the same thing).
This commit is contained in:
parent
89f30822ef
commit
c6be7d3ee6
@ -1,4 +1,4 @@
|
||||
/* $Id: screen-write.c,v 1.31 2009-01-28 19:52:21 nicm Exp $ */
|
||||
/* $Id: screen-write.c,v 1.32 2009-02-11 06:31:09 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -27,17 +27,14 @@ void
|
||||
screen_write_start(
|
||||
struct screen_write_ctx *ctx, struct window_pane *wp, struct screen *s)
|
||||
{
|
||||
ctx->s = s;
|
||||
if (wp != NULL) {
|
||||
ctx->write = tty_write_window;
|
||||
ctx->data = wp;
|
||||
if (ctx->s == NULL)
|
||||
ctx->s = wp->screen;
|
||||
tty_write_update_mode(ctx->data, ctx->s->mode & ~MODE_CURSOR);
|
||||
} else {
|
||||
ctx->write = NULL;
|
||||
ctx->data = NULL;
|
||||
}
|
||||
ctx->wp = wp;
|
||||
if (wp != NULL && ctx->s != NULL)
|
||||
ctx->s = wp->screen;
|
||||
else
|
||||
ctx->s = s;
|
||||
|
||||
if (ctx->s != NULL)
|
||||
tty_write_mode(ctx->wp, ctx->s->mode & ~MODE_CURSOR);
|
||||
}
|
||||
|
||||
/* Finish writing. */
|
||||
@ -180,8 +177,7 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
|
||||
if (nx == 0)
|
||||
return;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_INSERTCHARACTER, nx);
|
||||
tty_write_cmd(ctx->wp, TTY_INSERTCHARACTER, nx);
|
||||
|
||||
if (s->cx <= screen_size_x(s) - 1)
|
||||
grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
|
||||
@ -201,8 +197,7 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
|
||||
if (nx == 0)
|
||||
return;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_DELETECHARACTER, nx);
|
||||
tty_write_cmd(ctx->wp, TTY_DELETECHARACTER, nx);
|
||||
|
||||
if (s->cx <= screen_size_x(s) - 1)
|
||||
grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
|
||||
@ -222,8 +217,7 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
|
||||
if (ny == 0)
|
||||
return;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_INSERTLINE, ny);
|
||||
tty_write_cmd(ctx->wp, TTY_INSERTLINE, ny);
|
||||
|
||||
if (s->cy < s->rupper || s->cy > s->rlower)
|
||||
grid_view_insert_lines(s->grid, s->cy, ny);
|
||||
@ -247,8 +241,7 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
|
||||
if (ny == 0)
|
||||
return;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_DELETELINE, ny);
|
||||
tty_write_cmd(ctx->wp, TTY_DELETELINE, ny);
|
||||
|
||||
if (s->cy < s->rupper || s->cy > s->rlower)
|
||||
grid_view_delete_lines(s->grid, s->cy, ny);
|
||||
@ -264,8 +257,7 @@ screen_write_clearline(struct screen_write_ctx *ctx)
|
||||
{
|
||||
struct screen *s = ctx->s;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARLINE);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARLINE);
|
||||
|
||||
grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1);
|
||||
}
|
||||
@ -279,8 +271,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx)
|
||||
|
||||
sx = screen_size_x(s);
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARENDOFLINE);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARENDOFLINE);
|
||||
|
||||
if (s->cx <= sx - 1)
|
||||
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
||||
@ -295,8 +286,7 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx)
|
||||
|
||||
sx = screen_size_x(s);
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARSTARTOFLINE);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARSTARTOFLINE);
|
||||
|
||||
if (s->cx > sx - 1)
|
||||
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
||||
@ -337,8 +327,7 @@ screen_write_reverseindex(struct screen_write_ctx *ctx)
|
||||
{
|
||||
struct screen *s = ctx->s;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_REVERSEINDEX);
|
||||
tty_write_cmd(ctx->wp, TTY_REVERSEINDEX);
|
||||
|
||||
if (s->cy == s->rupper)
|
||||
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower);
|
||||
@ -398,8 +387,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx)
|
||||
{
|
||||
struct screen *s = ctx->s;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_LINEFEED);
|
||||
tty_write_cmd(ctx->wp, TTY_LINEFEED);
|
||||
|
||||
if (s->cy == s->rlower)
|
||||
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
|
||||
@ -450,8 +438,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx)
|
||||
sx = screen_size_x(s);
|
||||
sy = screen_size_y(s);
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARENDOFSCREEN);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARENDOFSCREEN);
|
||||
|
||||
if (s->cx <= sx - 1)
|
||||
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
||||
@ -467,8 +454,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
|
||||
|
||||
sx = screen_size_x(s);
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARSTARTOFSCREEN);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARSTARTOFSCREEN);
|
||||
|
||||
if (s->cy > 0)
|
||||
grid_view_clear(s->grid, 0, 0, sx, s->cy - 1);
|
||||
@ -484,8 +470,7 @@ screen_write_clearscreen(struct screen_write_ctx *ctx)
|
||||
{
|
||||
struct screen *s = ctx->s;
|
||||
|
||||
if (ctx->write != NULL)
|
||||
ctx->write(ctx->data, TTY_CLEARSCREEN);
|
||||
tty_write_cmd(ctx->wp, TTY_CLEARSCREEN);
|
||||
|
||||
grid_view_clear(s->grid, 0, 0, screen_size_x(s), screen_size_y(s));
|
||||
}
|
||||
@ -589,15 +574,12 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
|
||||
|
||||
/* Write the actual cell. */
|
||||
grid_view_set_cell(gd, s->cx, s->cy, gc);
|
||||
|
||||
if (ctx->write != NULL) {
|
||||
if (screen_check_selection(s, s->cx, s->cy)) {
|
||||
memcpy(&tc, &s->sel.cell, sizeof tc);
|
||||
tc.data = gc->data;
|
||||
ctx->write(ctx->data, TTY_CELL, &tc);
|
||||
} else
|
||||
ctx->write(ctx->data, TTY_CELL, gc);
|
||||
}
|
||||
if (screen_check_selection(s, s->cx, s->cy)) {
|
||||
memcpy(&tc, &s->sel.cell, sizeof tc);
|
||||
tc.data = gc->data;
|
||||
tty_write_cmd(ctx->wp, TTY_CELL, &tc);
|
||||
} else
|
||||
tty_write_cmd(ctx->wp, TTY_CELL, gc);
|
||||
|
||||
/* Move the cursor. */
|
||||
s->cx += width;
|
||||
|
11
tmux.h
11
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.263 2009-02-10 00:18:06 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.264 2009-02-11 06:31:09 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -506,9 +506,7 @@ struct screen {
|
||||
|
||||
/* Screen write context. */
|
||||
struct screen_write_ctx {
|
||||
void *data;
|
||||
void (*write)(void *, enum tty_cmd, ...);
|
||||
|
||||
struct window_pane *wp;
|
||||
struct screen *s;
|
||||
};
|
||||
|
||||
@ -1053,9 +1051,8 @@ void tty_keys_free(struct tty *);
|
||||
int tty_keys_next(struct tty *, int *, u_char *);
|
||||
|
||||
/* tty-write.c */
|
||||
void tty_write_window(void *, enum tty_cmd, ...);
|
||||
void tty_vwrite_window(void *, enum tty_cmd, va_list);
|
||||
void tty_write_update_mode(void *, int);
|
||||
void tty_write_cmd(struct window_pane *, enum tty_cmd, ...);
|
||||
void tty_write_mode(struct window_pane *, int);
|
||||
|
||||
/* options-cmd.c */
|
||||
void set_option_string(struct cmd_ctx *,
|
||||
|
30
tty-write.c
30
tty-write.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tty-write.c,v 1.9 2009-01-28 19:52:21 nicm Exp $ */
|
||||
/* $Id: tty-write.c,v 1.10 2009-02-11 06:31:09 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -20,23 +20,27 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void tty_vwrite_cmd(struct window_pane *, enum tty_cmd, va_list);
|
||||
|
||||
void
|
||||
tty_write_window(void *ptr, enum tty_cmd cmd, ...)
|
||||
tty_write_cmd(struct window_pane *wp, enum tty_cmd cmd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, cmd);
|
||||
tty_vwrite_window(ptr, cmd, ap);
|
||||
tty_vwrite_cmd(wp, cmd, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
tty_vwrite_window(void *ptr, enum tty_cmd cmd, va_list ap)
|
||||
tty_vwrite_cmd(struct window_pane *wp, enum tty_cmd cmd, va_list ap)
|
||||
{
|
||||
struct window_pane *wp = ptr;
|
||||
struct client *c;
|
||||
va_list aq;
|
||||
u_int i;
|
||||
struct client *c;
|
||||
va_list aq;
|
||||
u_int i;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (wp->window->flags & WINDOW_HIDDEN || wp->flags & PANE_HIDDEN)
|
||||
return;
|
||||
@ -57,11 +61,13 @@ tty_vwrite_window(void *ptr, enum tty_cmd cmd, va_list ap)
|
||||
}
|
||||
|
||||
void
|
||||
tty_write_update_mode(void *ptr, int mode)
|
||||
tty_write_mode(struct window_pane *wp, int mode)
|
||||
{
|
||||
struct window_pane *wp = ptr;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (wp->window->flags & WINDOW_HIDDEN || wp->flags & PANE_HIDDEN)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user