Use local var and pull screen out of ictx.

This commit is contained in:
Nicholas Marriott 2007-10-24 15:40:59 +00:00
parent ebeb14211d
commit 4df168c986
2 changed files with 165 additions and 143 deletions

259
input.c
View File

@ -1,4 +1,4 @@
/* $Id: input.c,v 1.27 2007-10-24 15:29:28 nicm Exp $ */ /* $Id: input.c,v 1.28 2007-10-24 15:40:59 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -152,7 +152,6 @@ input_parse(struct window *w, struct buffer *b)
ictx->off = 0; ictx->off = 0;
ictx->w = w; ictx->w = w;
ictx->s = &w->screen;
ictx->b = b; ictx->b = b;
log_debug2("entry; buffer=%zu", ictx->len); log_debug2("entry; buffer=%zu", ictx->len);
@ -251,12 +250,13 @@ input_state_title_second(u_char ch, struct input_ctx *ictx)
void * void *
input_state_title_next(u_char ch, struct input_ctx *ictx) input_state_title_next(u_char ch, struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
if (ch == '\007') { if (ch == '\007') {
ictx->title_buf[ictx->title_len++] = '\0'; ictx->title_buf[ictx->title_len++] = '\0';
switch (ictx->title_type) { switch (ictx->title_type) {
case 0: case 0:
strlcpy(ictx->s->title, strlcpy(s->title, ictx->title_buf, sizeof s->title);
ictx->title_buf, sizeof ictx->s->title);
input_store_one(ictx->b, CODE_TITLE, ictx->title_len); input_store_one(ictx->b, CODE_TITLE, ictx->title_len);
buffer_write(ictx->b, ictx->title_buf, ictx->title_len); buffer_write(ictx->b, ictx->title_buf, ictx->title_len);
break; break;
@ -361,45 +361,49 @@ input_state_sequence_intermediate(u_char ch, struct input_ctx *ictx)
void void
input_handle_character(u_char ch, struct input_ctx *ictx) input_handle_character(u_char ch, struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch); log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch);
if (ictx->s->cx > ictx->s->sx || ictx->s->cy > ictx->s->sy - 1) if (s->cx > s->sx || s->cy > s->sy - 1)
return; return;
if (ictx->s->cx == ictx->s->sx) { if (s->cx == s->sx) {
input_store8(ictx->b, '\r'); input_store8(ictx->b, '\r');
input_store8(ictx->b, '\n'); input_store8(ictx->b, '\n');
ictx->s->cx = 0; s->cx = 0;
screen_cursor_down_scroll(ictx->s); screen_cursor_down_scroll(s);
} }
screen_write_character(ictx->s, ch); screen_write_character(s, ch);
input_store8(ictx->b, ch); input_store8(ictx->b, ch);
ictx->s->cx++; s->cx++;
} }
void void
input_handle_c0_control(u_char ch, struct input_ctx *ictx) input_handle_c0_control(u_char ch, struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
log_debug2("-- c0 %zu: %hhu", ictx->off, ch); log_debug2("-- c0 %zu: %hhu", ictx->off, ch);
switch (ch) { switch (ch) {
case '\0': /* NUL */ case '\0': /* NUL */
break; break;
case '\n': /* LF */ case '\n': /* LF */
screen_cursor_down_scroll(ictx->s); screen_cursor_down_scroll(s);
break; break;
case '\r': /* CR */ case '\r': /* CR */
ictx->s->cx = 0; s->cx = 0;
break; break;
case '\007': /* BELL */ case '\007': /* BELL */
ictx->w->flags |= WINDOW_BELL; ictx->w->flags |= WINDOW_BELL;
return; return;
case '\010': /* BS */ case '\010': /* BS */
if (ictx->s->cx > 0) if (s->cx > 0)
ictx->s->cx--; s->cx--;
break; break;
default: default:
log_debug("unknown c0: %hhu", ch); log_debug("unknown c0: %hhu", ch);
@ -411,11 +415,13 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx)
void void
input_handle_c1_control(u_char ch, struct input_ctx *ictx) input_handle_c1_control(u_char ch, struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
log_debug2("-- c1 %zu: %hhu (%c)", ictx->off, ch, ch); log_debug2("-- c1 %zu: %hhu (%c)", ictx->off, ch, ch);
switch (ch) { switch (ch) {
case 'M': /* RI */ case 'M': /* RI */
screen_cursor_up_scroll(ictx->s); screen_cursor_up_scroll(s);
input_store_zero(ictx->b, CODE_REVERSEINDEX); input_store_zero(ictx->b, CODE_REVERSEINDEX);
break; break;
default: default:
@ -427,6 +433,8 @@ input_handle_c1_control(u_char ch, struct input_ctx *ictx)
void void
input_handle_private_two(u_char ch, struct input_ctx *ictx) input_handle_private_two(u_char ch, struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
log_debug2("-- p2 %zu: %hhu (%c)", ictx->off, ch, ch); log_debug2("-- p2 %zu: %hhu (%c)", ictx->off, ch, ch);
switch (ch) { switch (ch) {
@ -437,29 +445,29 @@ input_handle_private_two(u_char ch, struct input_ctx *ictx)
input_store_zero(ictx->b, CODE_KKEYPADOFF); input_store_zero(ictx->b, CODE_KKEYPADOFF);
break; break;
case '7': /* DECSC */ case '7': /* DECSC */
ictx->s->saved_cx = ictx->s->cx; s->saved_cx = s->cx;
ictx->s->saved_cy = ictx->s->cy; s->saved_cy = s->cy;
ictx->s->saved_ry_upper = ictx->s->ry_upper; s->saved_ry_upper = s->ry_upper;
ictx->s->saved_ry_lower = ictx->s->ry_lower; s->saved_ry_lower = s->ry_lower;
ictx->s->saved_attr = ictx->s->attr; s->saved_attr = s->attr;
ictx->s->saved_colr = ictx->s->colr; s->saved_colr = s->colr;
ictx->s->mode |= MODE_SAVED; s->mode |= MODE_SAVED;
break; break;
case '8': /* DECRC */ case '8': /* DECRC */
if (!(ictx->s->mode & MODE_SAVED)) if (!(s->mode & MODE_SAVED))
break; break;
ictx->s->cx = ictx->s->saved_cx; s->cx = s->saved_cx;
ictx->s->cy = ictx->s->saved_cy; s->cy = s->saved_cy;
ictx->s->ry_upper = ictx->s->saved_ry_upper; s->ry_upper = s->saved_ry_upper;
ictx->s->ry_lower = ictx->s->saved_ry_lower; s->ry_lower = s->saved_ry_lower;
ictx->s->attr = ictx->s->saved_attr; s->attr = s->saved_attr;
ictx->s->colr = ictx->s->saved_colr; s->colr = s->saved_colr;
input_store_two( input_store_two(
ictx->b, CODE_ATTRIBUTES, ictx->s->attr, ictx->s->colr); ictx->b, CODE_ATTRIBUTES, s->attr, s->colr);
input_store_two(ictx->b, CODE_SCROLLREGION, input_store_two(ictx->b, CODE_SCROLLREGION,
ictx->s->ry_upper + 1, ictx->s->ry_lower + 1); s->ry_upper + 1, s->ry_lower + 1);
input_store_two( input_store_two(
ictx->b, CODE_CURSORMOVE, ictx->s->cy + 1, ictx->s->cx + 1); ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
break; break;
default: default:
log_debug("unknown p2: %hhu", ch); log_debug("unknown p2: %hhu", ch);
@ -502,12 +510,13 @@ input_handle_sequence(u_char ch, struct input_ctx *ictx)
{ 'n', input_handle_sequence_dsr }, { 'n', input_handle_sequence_dsr },
{ 'r', input_handle_sequence_decstbm }, { 'r', input_handle_sequence_decstbm },
}; };
struct screen *s = &ictx->w->screen;
u_int i; u_int i;
struct input_arg *iarg; struct input_arg *iarg;
log_debug2("-- sq %zu: %hhu (%c): %u [sx=%u, sy=%u, cx=%u, cy=%u]", log_debug2("-- sq %zu: %hhu (%c): %u [sx=%u, sy=%u, cx=%u, cy=%u]",
ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args), ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args),
ictx->s->sx, ictx->s->sy, ictx->s->cx, ictx->s->cy); s->sx, s->sy, s->cx, s->cy);
for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) { for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) {
iarg = &ARRAY_ITEM(&ictx->args, i); iarg = &ARRAY_ITEM(&ictx->args, i);
if (*iarg->data != '\0') if (*iarg->data != '\0')
@ -528,6 +537,7 @@ input_handle_sequence(u_char ch, struct input_ctx *ictx)
void void
input_handle_sequence_cuu(struct input_ctx *ictx) input_handle_sequence_cuu(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -538,18 +548,19 @@ input_handle_sequence_cuu(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->cy) { if (n == 0 || n > s->cy) {
log_debug3("cuu: out of range: %hu", n); log_debug3("cuu: out of range: %hu", n);
return; return;
} }
ictx->s->cy -= n; s->cy -= n;
input_store_one(ictx->b, CODE_CURSORUP, n); input_store_one(ictx->b, CODE_CURSORUP, n);
} }
void void
input_handle_sequence_cud(struct input_ctx *ictx) input_handle_sequence_cud(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -560,18 +571,19 @@ input_handle_sequence_cud(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sy - ictx->s->cy - 1) { if (n == 0 || n > s->sy - s->cy - 1) {
log_debug3("cud: out of range: %hu", n); log_debug3("cud: out of range: %hu", n);
return; return;
} }
ictx->s->cy += n; s->cy += n;
input_store_one(ictx->b, CODE_CURSORDOWN, n); input_store_one(ictx->b, CODE_CURSORDOWN, n);
} }
void void
input_handle_sequence_cuf(struct input_ctx *ictx) input_handle_sequence_cuf(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -582,18 +594,19 @@ input_handle_sequence_cuf(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sx - ictx->s->cx - 1) { if (n == 0 || n > s->sx - s->cx - 1) {
log_debug3("cuf: out of range: %hu", n); log_debug3("cuf: out of range: %hu", n);
return; return;
} }
ictx->s->cx += n; s->cx += n;
input_store_one(ictx->b, CODE_CURSORRIGHT, n); input_store_one(ictx->b, CODE_CURSORRIGHT, n);
} }
void void
input_handle_sequence_cub(struct input_ctx *ictx) input_handle_sequence_cub(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -604,18 +617,19 @@ input_handle_sequence_cub(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->cx) { if (n == 0 || n > s->cx) {
log_debug3("cub: out of range: %hu", n); log_debug3("cub: out of range: %hu", n);
return; return;
} }
ictx->s->cx -= n; s->cx -= n;
input_store_one(ictx->b, CODE_CURSORLEFT, n); input_store_one(ictx->b, CODE_CURSORLEFT, n);
} }
void void
input_handle_sequence_dch(struct input_ctx *ictx) input_handle_sequence_dch(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -626,18 +640,19 @@ input_handle_sequence_dch(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sx - ictx->s->cx - 1) { if (n == 0 || n > s->sx - s->cx - 1) {
log_debug3("dch: out of range: %hu", n); log_debug3("dch: out of range: %hu", n);
return; return;
} }
screen_delete_characters(ictx->s, ictx->s->cx, ictx->s->cy, n); screen_delete_characters(s, s->cx, s->cy, n);
input_store_one(ictx->b, CODE_DELETECHARACTER, n); input_store_one(ictx->b, CODE_DELETECHARACTER, n);
} }
void void
input_handle_sequence_dl(struct input_ctx *ictx) input_handle_sequence_dl(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -648,21 +663,22 @@ input_handle_sequence_dl(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sy - ictx->s->cy - 1) { if (n == 0 || n > s->sy - s->cy - 1) {
log_debug3("dl: out of range: %hu", n); log_debug3("dl: out of range: %hu", n);
return; return;
} }
if (n < ictx->s->ry_upper || n > ictx->s->ry_lower) if (n < s->ry_upper || n > s->ry_lower)
screen_delete_lines(ictx->s, ictx->s->cy, n); screen_delete_lines(s, s->cy, n);
else else
screen_delete_lines_region(ictx->s, ictx->s->cy, n); screen_delete_lines_region(s, s->cy, n);
input_store_one(ictx->b, CODE_DELETELINE, n); input_store_one(ictx->b, CODE_DELETELINE, n);
} }
void void
input_handle_sequence_ich(struct input_ctx *ictx) input_handle_sequence_ich(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -673,18 +689,19 @@ input_handle_sequence_ich(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sx - ictx->s->cx - 1) { if (n == 0 || n > s->sx - s->cx - 1) {
log_debug3("ich: out of range: %hu", n); log_debug3("ich: out of range: %hu", n);
return; return;
} }
screen_insert_characters(ictx->s, ictx->s->cx, ictx->s->cy, n); screen_insert_characters(s, s->cx, s->cy, n);
input_store_one(ictx->b, CODE_INSERTCHARACTER, n); input_store_one(ictx->b, CODE_INSERTCHARACTER, n);
} }
void void
input_handle_sequence_il(struct input_ctx *ictx) input_handle_sequence_il(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -695,20 +712,21 @@ input_handle_sequence_il(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sy - ictx->s->cy - 1) { if (n == 0 || n > s->sy - s->cy - 1) {
log_debug3("il: out of range: %hu", n); log_debug3("il: out of range: %hu", n);
return; return;
} }
if (n < ictx->s->ry_upper || n > ictx->s->ry_lower) if (n < s->ry_upper || n > s->ry_lower)
screen_insert_lines(ictx->s, ictx->s->cy, n); screen_insert_lines(s, s->cy, n);
else else
screen_insert_lines_region(ictx->s, ictx->s->cy, n); screen_insert_lines_region(s, s->cy, n);
input_store_one(ictx->b, CODE_INSERTLINE, n); input_store_one(ictx->b, CODE_INSERTLINE, n);
} }
void void
input_handle_sequence_vpa(struct input_ctx *ictx) input_handle_sequence_vpa(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -719,18 +737,19 @@ input_handle_sequence_vpa(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sy) { if (n == 0 || n > s->sy) {
log_debug3("vpa: out of range: %hu", n); log_debug3("vpa: out of range: %hu", n);
return; return;
} }
ictx->s->cy = n - 1; s->cy = n - 1;
input_store_two(ictx->b, CODE_CURSORMOVE, n, ictx->s->cx + 1); input_store_two(ictx->b, CODE_CURSORMOVE, n, s->cx + 1);
} }
void void
input_handle_sequence_hpa(struct input_ctx *ictx) input_handle_sequence_hpa(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -741,18 +760,19 @@ input_handle_sequence_hpa(struct input_ctx *ictx)
if (input_get_argument(ictx, 0, &n, 1) != 0) if (input_get_argument(ictx, 0, &n, 1) != 0)
return; return;
if (n == 0 || n > ictx->s->sx) { if (n == 0 || n > s->sx) {
log_debug3("hpa: out of range: %hu", n); log_debug3("hpa: out of range: %hu", n);
return; return;
} }
ictx->s->cx = n - 1; s->cx = n - 1;
input_store_two(ictx->b, CODE_CURSORMOVE, ictx->s->cy + 1, n); input_store_two(ictx->b, CODE_CURSORMOVE, s->cy + 1, n);
} }
void void
input_handle_sequence_cup(struct input_ctx *ictx) input_handle_sequence_cup(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n, m; uint16_t n, m;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -767,21 +787,22 @@ input_handle_sequence_cup(struct input_ctx *ictx)
if (n == 0) if (n == 0)
n = 1; n = 1;
if (n > ictx->s->sy) if (n > s->sy)
n = ictx->s->sy; n = s->sy;
if (m == 0) if (m == 0)
m = 1; m = 1;
if (m > ictx->s->sx) if (m > s->sx)
m = ictx->s->sx; m = s->sx;
ictx->s->cx = m - 1; s->cx = m - 1;
ictx->s->cy = n - 1; s->cy = n - 1;
input_store_two(ictx->b, CODE_CURSORMOVE, n, m); input_store_two(ictx->b, CODE_CURSORMOVE, n, m);
} }
void void
input_handle_sequence_ed(struct input_ctx *ictx) input_handle_sequence_ed(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
u_int i; u_int i;
@ -798,25 +819,24 @@ input_handle_sequence_ed(struct input_ctx *ictx)
switch (n) { switch (n) {
case 0: case 0:
screen_fill_end_of_screen(ictx->s, 0, ictx->s->cy, screen_fill_end_of_screen(
SCREEN_DEFDATA, ictx->s->attr, ictx->s->colr); s, 0, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
input_store_zero(ictx->b, CODE_CLEARLINE); input_store_zero(ictx->b, CODE_CLEARLINE);
for (i = ictx->s->cy + 1; i < ictx->s->sy; i++) { for (i = s->cy + 1; i < s->sy; i++) {
input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1); input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1);
input_store_zero(ictx->b, CODE_CLEARLINE); input_store_zero(ictx->b, CODE_CLEARLINE);
} }
input_store_two( input_store_two(
ictx->b, CODE_CURSORMOVE, ictx->s->cy + 1, ictx->s->cx + 1); ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
break; break;
case 2: case 2:
screen_fill_screen( screen_fill_screen(s, SCREEN_DEFDATA, s->attr, s->colr);
ictx->s, SCREEN_DEFDATA, ictx->s->attr, ictx->s->colr); for (i = 0; i < s->sy; i++) {
for (i = 0; i < ictx->s->sy; i++) {
input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1); input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1);
input_store_zero(ictx->b, CODE_CLEARLINE); input_store_zero(ictx->b, CODE_CLEARLINE);
} }
input_store_two( input_store_two(
ictx->b, CODE_CURSORMOVE, ictx->s->cy + 1, ictx->s->cx + 1); ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
break; break;
} }
} }
@ -824,6 +844,7 @@ input_handle_sequence_ed(struct input_ctx *ictx)
void void
input_handle_sequence_el(struct input_ctx *ictx) input_handle_sequence_el(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -839,18 +860,17 @@ input_handle_sequence_el(struct input_ctx *ictx)
switch (n) { switch (n) {
case 0: case 0:
screen_fill_end_of_line(ictx->s, ictx->s->cx, ictx->s->cy, screen_fill_end_of_line(
SCREEN_DEFDATA, ictx->s->attr, ictx->s->colr); s, s->cx, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
input_store_zero(ictx->b, CODE_CLEARENDOFLINE); input_store_zero(ictx->b, CODE_CLEARENDOFLINE);
break; break;
case 1: case 1:
screen_fill_start_of_line(ictx->s, ictx->s->cx, ictx->s->cy, screen_fill_start_of_line(
SCREEN_DEFDATA, ictx->s->attr, ictx->s->colr); s, s->cx, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
input_store_zero(ictx->b, CODE_CLEARSTARTOFLINE); input_store_zero(ictx->b, CODE_CLEARSTARTOFLINE);
break; break;
case 2: case 2:
screen_fill_line(ictx->s, ictx->s->cy, screen_fill_line(s, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
SCREEN_DEFDATA, ictx->s->attr, ictx->s->colr);
input_store_zero(ictx->b, CODE_CLEARLINE); input_store_zero(ictx->b, CODE_CLEARLINE);
break; break;
} }
@ -859,6 +879,7 @@ input_handle_sequence_el(struct input_ctx *ictx)
void void
input_handle_sequence_sm(struct input_ctx *ictx) input_handle_sequence_sm(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ARRAY_LENGTH(&ictx->args) > 1) if (ARRAY_LENGTH(&ictx->args) > 1)
@ -869,11 +890,11 @@ input_handle_sequence_sm(struct input_ctx *ictx)
if (ictx->private == '?') { if (ictx->private == '?') {
switch (n) { switch (n) {
case 1: /* GATM */ case 1: /* GATM */
ictx->s->mode |= MODE_KCURSOR; s->mode |= MODE_KCURSOR;
input_store_zero(ictx->b, CODE_KCURSORON); input_store_zero(ictx->b, CODE_KCURSORON);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
ictx->s->mode |= MODE_CURSOR; s->mode |= MODE_CURSOR;
input_store_zero(ictx->b, CODE_CURSORON); input_store_zero(ictx->b, CODE_CURSORON);
break; break;
default: default:
@ -883,7 +904,7 @@ input_handle_sequence_sm(struct input_ctx *ictx)
} else { } else {
switch (n) { switch (n) {
case 4: /* IRM */ case 4: /* IRM */
ictx->s->mode |= MODE_INSERT; s->mode |= MODE_INSERT;
input_store_zero(ictx->b, CODE_INSERTON); input_store_zero(ictx->b, CODE_INSERTON);
break; break;
case 34: case 34:
@ -899,6 +920,7 @@ input_handle_sequence_sm(struct input_ctx *ictx)
void void
input_handle_sequence_rm(struct input_ctx *ictx) input_handle_sequence_rm(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
if (ARRAY_LENGTH(&ictx->args) > 1) if (ARRAY_LENGTH(&ictx->args) > 1)
@ -909,11 +931,11 @@ input_handle_sequence_rm(struct input_ctx *ictx)
if (ictx->private == '?') { if (ictx->private == '?') {
switch (n) { switch (n) {
case 1: /* GATM */ case 1: /* GATM */
ictx->s->mode &= ~MODE_KCURSOR; s->mode &= ~MODE_KCURSOR;
input_store_zero(ictx->b, CODE_KCURSOROFF); input_store_zero(ictx->b, CODE_KCURSOROFF);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
ictx->s->mode &= ~MODE_CURSOR; s->mode &= ~MODE_CURSOR;
input_store_zero(ictx->b, CODE_CURSOROFF); input_store_zero(ictx->b, CODE_CURSOROFF);
break; break;
default: default:
@ -923,7 +945,7 @@ input_handle_sequence_rm(struct input_ctx *ictx)
} else if (ictx->private == '\0') { } else if (ictx->private == '\0') {
switch (n) { switch (n) {
case 4: /* IRM */ case 4: /* IRM */
ictx->s->mode &= ~MODE_INSERT; s->mode &= ~MODE_INSERT;
input_store_zero(ictx->b, CODE_INSERTOFF); input_store_zero(ictx->b, CODE_INSERTOFF);
break; break;
case 34: case 34:
@ -939,6 +961,7 @@ input_handle_sequence_rm(struct input_ctx *ictx)
void void
input_handle_sequence_dsr(struct input_ctx *ictx) input_handle_sequence_dsr(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n; uint16_t n;
char reply[32]; char reply[32];
@ -951,7 +974,7 @@ input_handle_sequence_dsr(struct input_ctx *ictx)
switch (n) { switch (n) {
case 6: /* cursor position */ case 6: /* cursor position */
xsnprintf(reply, sizeof reply, xsnprintf(reply, sizeof reply,
"\033[%u;%uR", ictx->s->cy + 1, ictx->s->cx + 1); "\033[%u;%uR", s->cy + 1, s->cx + 1);
log_debug("cursor request, reply: %s", reply); log_debug("cursor request, reply: %s", reply);
buffer_write(ictx->w->out, reply, strlen(reply)); buffer_write(ictx->w->out, reply, strlen(reply));
break; break;
@ -963,6 +986,7 @@ input_handle_sequence_dsr(struct input_ctx *ictx)
void void
input_handle_sequence_decstbm(struct input_ctx *ictx) input_handle_sequence_decstbm(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
uint16_t n, m; uint16_t n, m;
if (ictx->private != '\0') if (ictx->private != '\0')
@ -979,17 +1003,17 @@ input_handle_sequence_decstbm(struct input_ctx *ictx)
/* XXX this will catch [0;0r and [;r etc too, is this right? */ /* XXX this will catch [0;0r and [;r etc too, is this right? */
if (n == 0 && m == 0) { if (n == 0 && m == 0) {
n = 1; n = 1;
m = ictx->s->sy; m = s->sy;
} }
if (n == 0) if (n == 0)
n = 1; n = 1;
if (n > ictx->s->sy) if (n > s->sy)
n = ictx->s->sy; n = s->sy;
if (m == 0) if (m == 0)
m = 1; m = 1;
if (m > ictx->s->sx) if (m > s->sx)
m = ictx->s->sx; m = s->sx;
if (n > m) { if (n > m) {
log_debug3("decstbm: out of range: %hu,%hu", n, m); log_debug3("decstbm: out of range: %hu,%hu", n, m);
@ -997,24 +1021,25 @@ input_handle_sequence_decstbm(struct input_ctx *ictx)
} }
/* Cursor moves to top-left. */ /* Cursor moves to top-left. */
ictx->s->cx = 0; s->cx = 0;
ictx->s->cy = n - 1; s->cy = n - 1;
ictx->s->ry_upper = n - 1; s->ry_upper = n - 1;
ictx->s->ry_lower = m - 1; s->ry_lower = m - 1;
input_store_two(ictx->b, CODE_SCROLLREGION, n, m); input_store_two(ictx->b, CODE_SCROLLREGION, n, m);
} }
void void
input_handle_sequence_sgr(struct input_ctx *ictx) input_handle_sequence_sgr(struct input_ctx *ictx)
{ {
struct screen *s = &ictx->w->screen;
u_int i, n; u_int i, n;
uint16_t m; uint16_t m;
n = ARRAY_LENGTH(&ictx->args); n = ARRAY_LENGTH(&ictx->args);
if (n == 0) { if (n == 0) {
ictx->s->attr = 0; s->attr = 0;
ictx->s->colr = SCREEN_DEFCOLR; s->colr = SCREEN_DEFCOLR;
} else { } else {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (input_get_argument(ictx, i, &m, 0) != 0) if (input_get_argument(ictx, i, &m, 0) != 0)
@ -1022,35 +1047,35 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
switch (m) { switch (m) {
case 0: case 0:
case 10: case 10:
ictx->s->attr = 0; s->attr = 0;
ictx->s->colr = SCREEN_DEFCOLR; s->colr = SCREEN_DEFCOLR;
break; break;
case 1: case 1:
ictx->s->attr |= ATTR_BRIGHT; s->attr |= ATTR_BRIGHT;
break; break;
case 2: case 2:
ictx->s->attr |= ATTR_DIM; s->attr |= ATTR_DIM;
break; break;
case 3: case 3:
ictx->s->attr |= ATTR_ITALICS; s->attr |= ATTR_ITALICS;
break; break;
case 4: case 4:
ictx->s->attr |= ATTR_UNDERSCORE; s->attr |= ATTR_UNDERSCORE;
break; break;
case 5: case 5:
ictx->s->attr |= ATTR_BLINK; s->attr |= ATTR_BLINK;
break; break;
case 7: case 7:
ictx->s->attr |= ATTR_REVERSE; s->attr |= ATTR_REVERSE;
break; break;
case 8: case 8:
ictx->s->attr |= ATTR_HIDDEN; s->attr |= ATTR_HIDDEN;
break; break;
case 23: case 23:
ictx->s->attr &= ~ATTR_ITALICS; s->attr &= ~ATTR_ITALICS;
break; break;
case 24: case 24:
ictx->s->attr &= ~ATTR_UNDERSCORE; s->attr &= ~ATTR_UNDERSCORE;
break; break;
case 30: case 30:
case 31: case 31:
@ -1060,12 +1085,12 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
case 35: case 35:
case 36: case 36:
case 37: case 37:
ictx->s->colr &= 0x0f; s->colr &= 0x0f;
ictx->s->colr |= (m - 30) << 4; s->colr |= (m - 30) << 4;
break; break;
case 39: case 39:
ictx->s->colr &= 0x0f; s->colr &= 0x0f;
ictx->s->colr |= 0x80; s->colr |= 0x80;
break; break;
case 40: case 40:
case 41: case 41:
@ -1075,17 +1100,17 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
case 45: case 45:
case 46: case 46:
case 47: case 47:
ictx->s->colr &= 0xf0; s->colr &= 0xf0;
ictx->s->colr |= m - 40; s->colr |= m - 40;
break; break;
case 49: case 49:
ictx->s->colr &= 0xf0; s->colr &= 0xf0;
ictx->s->colr |= 0x08; s->colr |= 0x08;
break; break;
} }
} }
} }
input_store_two(ictx->b, CODE_ATTRIBUTES, ictx->s->attr, ictx->s->colr); input_store_two(ictx->b, CODE_ATTRIBUTES, s->attr, s->colr);
} }
void void

5
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.68 2007-10-24 15:29:28 nicm Exp $ */ /* $Id: tmux.h,v 1.69 2007-10-24 15:40:59 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -370,14 +370,11 @@ struct input_arg {
struct input_ctx { struct input_ctx {
struct window *w; struct window *w;
struct buffer *b; struct buffer *b;
struct screen *s;
u_char *buf; u_char *buf;
size_t len; size_t len;
size_t off; size_t off;
struct buffer *replyb; /* replies to information requests */
u_char title_buf[MAXTITLELEN]; u_char title_buf[MAXTITLELEN];
size_t title_len; size_t title_len;
u_int title_type; u_int title_type;