Support keypad mode, and get rid of SCREEN_DEF*. Meant to commit these separately but forgot :-/.

This commit is contained in:
Nicholas Marriott 2008-07-24 21:42:40 +00:00
parent 815b217482
commit 3337dfcae5
11 changed files with 74 additions and 64 deletions

12
CHANGES
View File

@ -1,11 +1,9 @@
24 July 2008 24 July 2008
* If keypad mode and cursor mode are on, switch the arrow keys from \033[A to * Finally lose inconsistently-used SCREEN_DEF* defines.
\033OA. Not sure what else keypad mode is meant to do. Something with the * If cursor mode is on, switch the arrow keys from \033[A to \033OA.
keypad keys I think, but screen doesn't seem to do anything... * Support the numeric keypad in both application and numbers mode. This is
* Support the numeric keypad. This is really confusing: parts of it have termcap different from screen which always keeps it in application mode.
entries and parts do not. I'm not sure I've got it right but this seems to
work.
19 July 2008 19 July 2008
@ -623,4 +621,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.153 2008-07-24 00:03:15 nicm Exp $ $Id: CHANGES,v 1.154 2008-07-24 21:42:40 nicm Exp $

2
TODO
View File

@ -42,9 +42,7 @@
- cfg file improvements (env vars particularly) - cfg file improvements (env vars particularly)
- better mode features: search, back word, forward word, etc - better mode features: search, back word, forward word, etc
- flags to centre screen in window - flags to centre screen in window
- get rid of DEFDATA etc
- better terminal emulation (identify, insert mode, some other bits) - better terminal emulation (identify, insert mode, some other bits)
- should we support kkeypad? looks like screen doesn't. what is kcursor?
-- For 0.5 -------------------------------------------------------------------- -- For 0.5 --------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
/* $Id: input-keys.c,v 1.13 2008-07-24 00:03:15 nicm Exp $ */ /* $Id: input-keys.c,v 1.14 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -50,17 +50,33 @@ struct {
{ KEYC_PPAGE, "\033[5~", 0 }, { KEYC_PPAGE, "\033[5~", 0 },
{ KEYC_SELECT, "\033[4~", 0 }, { KEYC_SELECT, "\033[4~", 0 },
/* Keypad + cursor versions must come first. */ /* Arrow keys. Cursor versions must come first. */
{ KEYC_UP, "\033OA", INPUTKEY_KEYPAD|INPUTKEY_CURSOR }, { KEYC_UP, "\033OA", INPUTKEY_CURSOR },
{ KEYC_DOWN, "\033OB", INPUTKEY_KEYPAD|INPUTKEY_CURSOR }, { KEYC_DOWN, "\033OB", INPUTKEY_CURSOR },
{ KEYC_LEFT, "\033OD", INPUTKEY_KEYPAD|INPUTKEY_CURSOR }, { KEYC_LEFT, "\033OD", INPUTKEY_CURSOR },
{ KEYC_RIGHT, "\033OC", INPUTKEY_KEYPAD|INPUTKEY_CURSOR }, { KEYC_RIGHT, "\033OC", INPUTKEY_CURSOR },
{ KEYC_UP, "\033[A", 0 }, { KEYC_UP, "\033[A", 0 },
{ KEYC_DOWN, "\033[B", 0 }, { KEYC_DOWN, "\033[B", 0 },
{ KEYC_LEFT, "\033[D", 0 }, { KEYC_LEFT, "\033[D", 0 },
{ KEYC_RIGHT, "\033[C", 0 }, { KEYC_RIGHT, "\033[C", 0 },
/* Keypad keys. Keypad versions must come first. */
{ KEYC_KP0_1, "/", INPUTKEY_KEYPAD },
{ KEYC_KP0_2, "*", INPUTKEY_KEYPAD },
{ KEYC_KP0_3, "-", INPUTKEY_KEYPAD },
{ KEYC_KP1_0, "7", INPUTKEY_KEYPAD },
{ KEYC_KP1_1, "8", INPUTKEY_KEYPAD },
{ KEYC_KP1_2, "9", INPUTKEY_KEYPAD },
{ KEYC_KP1_3, "+", INPUTKEY_KEYPAD },
{ KEYC_KP2_0, "4", INPUTKEY_KEYPAD },
{ KEYC_KP2_1, "5", INPUTKEY_KEYPAD },
{ KEYC_KP2_2, "6", INPUTKEY_KEYPAD },
{ KEYC_KP3_0, "1", INPUTKEY_KEYPAD },
{ KEYC_KP3_1, "2", INPUTKEY_KEYPAD },
{ KEYC_KP3_2, "3", INPUTKEY_KEYPAD },
{ KEYC_KP3_3, "\n", INPUTKEY_KEYPAD }, /* this can be CRLF too? */
{ KEYC_KP4_0, "0", INPUTKEY_KEYPAD },
{ KEYC_KP4_2, ".", INPUTKEY_KEYPAD },
{ KEYC_KP0_1, "\033Oo", 0 }, { KEYC_KP0_1, "\033Oo", 0 },
{ KEYC_KP0_2, "\033Oj", 0 }, { KEYC_KP0_2, "\033Oj", 0 },
{ KEYC_KP0_3, "\033Om", 0 }, { KEYC_KP0_3, "\033Om", 0 },
@ -86,7 +102,7 @@ input_key(struct window *w, int key)
{ {
u_int i; u_int i;
log_debug2("writing key %x", key); log_debug2("writing key 0x%x", key);
if (KEYC_ISESCAPE(key)) { if (KEYC_ISESCAPE(key)) {
buffer_write8(w->out, '\033'); buffer_write8(w->out, '\033');
@ -109,10 +125,10 @@ input_key(struct window *w, int key)
break; break;
} }
if (i == NINPUTKEYS) { if (i == NINPUTKEYS) {
log_debug2("key %d missing", key); log_debug2("key 0x%x missing", key);
return; return;
} }
log_debug2("found key %d: \"%s\"", key, input_keys[i].data); log_debug2("found key 0x%x: \"%s\"", key, input_keys[i].data);
buffer_write(w->out, input_keys[i].data, strlen(input_keys[i].data)); buffer_write(w->out, input_keys[i].data, strlen(input_keys[i].data));
} }

View File

@ -1,4 +1,4 @@
/* $Id: input.c,v 1.51 2008-07-23 23:44:50 nicm Exp $ */ /* $Id: input.c,v 1.52 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -1055,7 +1055,7 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
n = ARRAY_LENGTH(&ictx->args); n = ARRAY_LENGTH(&ictx->args);
if (n == 0) { if (n == 0) {
attr = 0; attr = 0;
colr = SCREEN_DEFCOLR; colr = 0x88;
} else { } else {
attr = s->attr; attr = s->attr;
colr = s->colr; colr = s->colr;
@ -1066,7 +1066,7 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
case 0: case 0:
case 10: case 10:
attr &= ATTR_CHARSET; attr &= ATTR_CHARSET;
colr = SCREEN_DEFCOLR; colr = 0x88;
break; break;
case 1: case 1:
attr |= ATTR_BRIGHT; attr |= ATTR_BRIGHT;

View File

@ -1,4 +1,4 @@
/* $Id: screen-display.c,v 1.17 2008-06-18 22:21:51 nicm Exp $ */ /* $Id: screen-display.c,v 1.18 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -39,9 +39,9 @@ screen_display_make_lines(struct screen *s, u_int py, u_int ny)
return; return;
} }
screen_make_lines(s, screen_y(s, py), ny); screen_make_lines(s, screen_y(s, py), ny);
if (s->attr != SCREEN_DEFATTR || s->colr != SCREEN_DEFCOLR) { if (s->attr != 0 || s->colr != 0x88) {
screen_display_fill_area(s, 0, py, screen_display_fill_area(s, 0, py,
screen_size_x(s), ny, SCREEN_DEFDATA, s->attr, s->colr); screen_size_x(s), ny, ' ', s->attr, s->colr);
} }
} }
@ -381,7 +381,7 @@ screen_display_insert_characters(struct screen *s, u_int px, u_int py, u_int nx)
memmove(&s->grid_colr[py][px + nx], &s->grid_colr[py][px], mx); memmove(&s->grid_colr[py][px + nx], &s->grid_colr[py][px], mx);
} }
memset(&s->grid_data[py][px], SCREEN_DEFDATA, nx); memset(&s->grid_data[py][px], ' ', nx);
memset(&s->grid_attr[py][px], s->attr, nx); memset(&s->grid_attr[py][px], s->attr, nx);
memset(&s->grid_colr[py][px], s->colr, nx); memset(&s->grid_colr[py][px], s->colr, nx);
} }
@ -420,7 +420,7 @@ screen_display_delete_characters(struct screen *s, u_int px, u_int py, u_int nx)
memmove(&s->grid_colr[py][px], &s->grid_colr[py][px + nx], mx); memmove(&s->grid_colr[py][px], &s->grid_colr[py][px + nx], mx);
} }
memset(&s->grid_data[py][screen_size_x(s) - nx], SCREEN_DEFDATA, nx); memset(&s->grid_data[py][screen_size_x(s) - nx], ' ', nx);
memset(&s->grid_attr[py][screen_size_x(s) - nx], s->attr, nx); memset(&s->grid_attr[py][screen_size_x(s) - nx], s->attr, nx);
memset(&s->grid_colr[py][screen_size_x(s) - nx], s->colr, nx); memset(&s->grid_colr[py][screen_size_x(s) - nx], s->colr, nx);
} }

View File

@ -1,4 +1,4 @@
/* $Id: screen-write.c,v 1.9 2008-07-23 23:44:50 nicm Exp $ */ /* $Id: screen-write.c,v 1.10 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -381,9 +381,9 @@ screen_write_fill_end_of_screen(struct screen_write_ctx *ctx)
u_int i; u_int i;
screen_display_fill_area(s, s->cx, s->cy, screen_display_fill_area(s, s->cx, s->cy,
screen_right_x(s, s->cx), 1, SCREEN_DEFDATA, s->attr, s->colr); screen_right_x(s, s->cx), 1, ' ', s->attr, s->colr);
screen_display_fill_area(s, 0, s->cy + 1, screen_size_x(s), screen_display_fill_area(s, 0, s->cy + 1, screen_size_x(s),
screen_below_y(s, s->cy + 1), SCREEN_DEFDATA, s->attr, s->colr); screen_below_y(s, s->cy + 1), ' ', s->attr, s->colr);
if (ctx->write != NULL) { if (ctx->write != NULL) {
ctx->write(ctx->data, TTY_CLEARENDOFLINE); ctx->write(ctx->data, TTY_CLEARENDOFLINE);
@ -402,8 +402,8 @@ screen_write_fill_screen(struct screen_write_ctx *ctx)
struct screen *s = ctx->s; struct screen *s = ctx->s;
u_int i; u_int i;
screen_display_fill_area(s, 0, 0, screen_size_x(s), screen_size_y(s), screen_display_fill_area(s, 0, 0,
SCREEN_DEFDATA, s->attr, s->colr); screen_size_x(s), screen_size_y(s), ' ', s->attr, s->colr);
if (ctx->write != NULL) { if (ctx->write != NULL) {
for (i = 0; i < screen_size_y(s); i++) { for (i = 0; i < screen_size_y(s); i++) {
@ -421,7 +421,7 @@ screen_write_fill_end_of_line(struct screen_write_ctx *ctx)
struct screen *s = ctx->s; struct screen *s = ctx->s;
screen_display_fill_area(s, s->cx, s->cy, screen_display_fill_area(s, s->cx, s->cy,
screen_right_x(s, s->cx), 1, SCREEN_DEFDATA, s->attr, s->colr); screen_right_x(s, s->cx), 1, ' ', s->attr, s->colr);
if (ctx->write != NULL) if (ctx->write != NULL)
ctx->write(ctx->data, TTY_CLEARENDOFLINE); ctx->write(ctx->data, TTY_CLEARENDOFLINE);
@ -434,7 +434,7 @@ screen_write_fill_start_of_line(struct screen_write_ctx *ctx)
struct screen *s = ctx->s; struct screen *s = ctx->s;
screen_display_fill_area(s, 0, s->cy, screen_display_fill_area(s, 0, s->cy,
screen_left_x(s, s->cx), 1, SCREEN_DEFDATA, s->attr, s->colr); screen_left_x(s, s->cx), 1, ' ', s->attr, s->colr);
if (ctx->write != NULL) if (ctx->write != NULL)
ctx->write(ctx->data, TTY_CLEARSTARTOFLINE); ctx->write(ctx->data, TTY_CLEARSTARTOFLINE);
@ -447,7 +447,7 @@ screen_write_fill_line(struct screen_write_ctx *ctx)
struct screen *s = ctx->s; struct screen *s = ctx->s;
screen_display_fill_area(s, 0, s->cy, screen_display_fill_area(s, 0, s->cy,
screen_size_x(s), s->cy, SCREEN_DEFDATA, s->attr, s->colr); screen_size_x(s), s->cy, ' ', s->attr, s->colr);
if (ctx->write != NULL) if (ctx->write != NULL)
ctx->write(ctx->data, TTY_CLEARLINE); ctx->write(ctx->data, TTY_CLEARLINE);

View File

@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.65 2008-07-24 07:01:57 nicm Exp $ */ /* $Id: screen.c,v 1.66 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -141,8 +141,8 @@ screen_create(struct screen *s, u_int dx, u_int dy, u_int hlimit)
s->hsize = 0; s->hsize = 0;
s->hlimit = hlimit; s->hlimit = hlimit;
s->attr = SCREEN_DEFATTR; s->attr = 0;
s->colr = SCREEN_DEFCOLR; s->colr = 0x88;
s->mode = MODE_CURSOR; s->mode = MODE_CURSOR;
s->title = xstrdup(""); s->title = xstrdup("");
@ -166,8 +166,8 @@ screen_reset(struct screen *s)
s->rupper = 0; s->rupper = 0;
s->rlower = s->dy - 1; s->rlower = s->dy - 1;
s->attr = SCREEN_DEFATTR; s->attr = 0;
s->colr = SCREEN_DEFCOLR; s->colr = 0x88;
s->mode = MODE_CURSOR; s->mode = MODE_CURSOR;
@ -276,11 +276,11 @@ screen_expand_line(struct screen *s, u_int py, u_int nx)
s->grid_size[py] = nx; s->grid_size[py] = nx;
s->grid_data[py] = xrealloc(s->grid_data[py], 1, nx); s->grid_data[py] = xrealloc(s->grid_data[py], 1, nx);
memset(&s->grid_data[py][ox], SCREEN_DEFDATA, nx - ox); memset(&s->grid_data[py][ox], ' ', nx - ox);
s->grid_attr[py] = xrealloc(s->grid_attr[py], 1, nx); s->grid_attr[py] = xrealloc(s->grid_attr[py], 1, nx);
memset(&s->grid_attr[py][ox], SCREEN_DEFATTR, nx - ox); memset(&s->grid_attr[py][ox], 0, nx - ox);
s->grid_colr[py] = xrealloc(s->grid_colr[py], 1, nx); s->grid_colr[py] = xrealloc(s->grid_colr[py], 1, nx);
memset(&s->grid_colr[py][ox], SCREEN_DEFCOLR, nx - ox); memset(&s->grid_colr[py][ox], 0x88, nx - ox);
} }
/* Reduce line. */ /* Reduce line. */
@ -300,9 +300,9 @@ screen_get_cell(struct screen *s,
u_int cx, u_int cy, u_char *data, u_char *attr, u_char *colr) u_int cx, u_int cy, u_char *data, u_char *attr, u_char *colr)
{ {
if (cx >= s->grid_size[cy]) { if (cx >= s->grid_size[cy]) {
*data = SCREEN_DEFDATA; *data = ' ';
*attr = SCREEN_DEFATTR; *attr = 0;
*colr = SCREEN_DEFCOLR; *colr = 0x88;
} else { } else {
*data = s->grid_data[cy][cx]; *data = s->grid_data[cy][cx];
*attr = s->grid_attr[cy][cx]; *attr = s->grid_attr[cy][cx];

7
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.176 2008-07-23 23:44:50 nicm Exp $ */ /* $Id: tmux.h,v 1.177 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -517,11 +517,6 @@ struct screen_write_ctx {
n, m, o, p); \ n, m, o, p); \
} while (0) } while (0)
/* Screen default contents. */
#define SCREEN_DEFDATA ' '
#define SCREEN_DEFATTR 0
#define SCREEN_DEFCOLR 0x88 /* default on default ;-) */
/* Input parser sequence argument. */ /* Input parser sequence argument. */
struct input_arg { struct input_arg {
u_char data[64]; u_char data[64];

View File

@ -1,4 +1,4 @@
/* $Id: tty-keys.c,v 1.8 2008-07-24 00:03:15 nicm Exp $ */ /* $Id: tty-keys.c,v 1.9 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -179,10 +179,14 @@ struct {
{ "pmous", KEYC_MOUSE }, { "pmous", KEYC_MOUSE },
/* /*
* Numeric keypad. * Numeric keypad. termcap and terminfo are totally confusing for this.
* * There are definitions for some keypad keys and for function keys,
* This is totally confusing and I still don't quite understand how it * but these seem to now be used for the real function keys rather than
* all fits together in relation to termcap... * for the keypad keys in application mode (which is different from
* what it says in the termcap file). So, we just hardcode the vt100
* escape sequences here and always put the terminal into keypad_xmit
* mode. Translation of numbers mode/applications mode is done in
* input-keys.c.
*/ */
{ "-\033Oo", KEYC_KP0_1 }, { "-\033Oo", KEYC_KP0_1 },
{ "-\033Oj", KEYC_KP0_2 }, { "-\033Oj", KEYC_KP0_2 },

View File

@ -1,4 +1,4 @@
/* $Id: window-copy.c,v 1.26 2008-07-02 21:22:57 nicm Exp $ */ /* $Id: window-copy.c,v 1.27 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -215,8 +215,7 @@ window_copy_write_line(
screen_write_move_cursor(ctx, 0, 0); screen_write_move_cursor(ctx, 0, 0);
size = screen_write_put_string_rjust( size = screen_write_put_string_rjust(
ctx, "[%u,%u/%u]", data->ox, data->oy, w->base.hsize); ctx, "[%u,%u/%u]", data->ox, data->oy, w->base.hsize);
screen_write_set_attributes( screen_write_set_attributes(ctx, 0, 0x88);
ctx, SCREEN_DEFATTR, SCREEN_DEFCOLR);
} else } else
size = 0; size = 0;
screen_write_move_cursor(ctx, 0, py); screen_write_move_cursor(ctx, 0, py);
@ -458,7 +457,7 @@ window_copy_find_length(struct window *w, u_int py)
u_int px; u_int px;
px = w->base.grid_size[py]; px = w->base.grid_size[py];
while (px > 0 && w->base.grid_data[py][px - 1] == SCREEN_DEFDATA) while (px > 0 && w->base.grid_data[py][px - 1] == ' ')
px--; px--;
return (px); return (px);
} }

View File

@ -1,4 +1,4 @@
/* $Id: window-more.c,v 1.15 2008-07-02 21:22:57 nicm Exp $ */ /* $Id: window-more.c,v 1.16 2008-07-24 21:42:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -176,7 +176,7 @@ window_more_write_line(struct window *w, struct screen_write_ctx *ctx, u_int py)
} else } else
size = 0; size = 0;
screen_write_set_attributes(ctx, SCREEN_DEFATTR, SCREEN_DEFCOLR); screen_write_set_attributes(ctx, 0, 0x88);
screen_write_move_cursor(ctx, 0, py); screen_write_move_cursor(ctx, 0, py);
if (data->top + py < ARRAY_LENGTH(&data->list)) { if (data->top + py < ARRAY_LENGTH(&data->list)) {
msg = ARRAY_ITEM(&data->list, data->top + py); msg = ARRAY_ITEM(&data->list, data->top + py);
@ -184,7 +184,7 @@ window_more_write_line(struct window *w, struct screen_write_ctx *ctx, u_int py)
ctx, "%.*s", (int) (screen_size_x(s) - size), msg); ctx, "%.*s", (int) (screen_size_x(s) - size), msg);
} }
while (s->cx < screen_size_x(s) - size) while (s->cx < screen_size_x(s) - size)
screen_write_put_character(ctx, SCREEN_DEFDATA); screen_write_put_character(ctx, ' ');
} }
void void