summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-10-01 14:18:42 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-10-01 14:18:42 +0000
commit872696f7819f20eb5fdaa53c16221cf614952eb7 (patch)
tree2afd0be07b4cbd0340a50185e7c690984685399b
parent9d563c340b16dfe0d4b3cd789ffbeda0d4d1e589 (diff)
Pass attributes around as flags rather than as a list of escape codes.
-rw-r--r--TODO2
-rw-r--r--input.c13
-rw-r--r--local.c182
-rw-r--r--screen.c99
-rw-r--r--server-fn.c6
-rw-r--r--tmux.h4
6 files changed, 90 insertions, 216 deletions
diff --git a/TODO b/TODO
index 2e261e15..f2e1c573 100644
--- a/TODO
+++ b/TODO
@@ -37,3 +37,5 @@
- store_attr/colr could be two-pass and avoid reverse_add/remove games
- window creation/idle time
- attributes could be 8 not 16 bits
+- put title setting back
+- profile/optimise, particularly (i suspect) input.c
diff --git a/input.c b/input.c
index a77a4cd4..31bfd7ce 100644
--- a/input.c
+++ b/input.c
@@ -1,4 +1,4 @@
-/* $Id: input.c,v 1.14 2007-09-30 13:29:28 nicm Exp $ */
+/* $Id: input.c,v 1.15 2007-10-01 14:18:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -953,20 +953,13 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
uint16_t m;
n = ARRAY_LENGTH(&ictx->args);
-
- input_store_zero(ictx->b, CODE_ATTRIBUTES);
if (n == 0) {
ictx->s->attr = 0;
ictx->s->colr = SCREEN_DEFCOLR;
- input_store16(ictx->b, 1);
- input_store16(ictx->b, 0);
} else {
- input_store16(ictx->b, n);
for (i = 0; i < n; i++) {
- if (input_get_argument(ictx, i, &m, 0) != 0) {
- /* XXX XXX partial write to client */
+ if (input_get_argument(ictx, i, &m, 0) != 0)
return;
- }
switch (m) {
case 0:
case 10:
@@ -1031,9 +1024,9 @@ input_handle_sequence_sgr(struct input_ctx *ictx)
ictx->s->colr |= 0x08;
break;
}
- input_store16(ictx->b, m);
}
}
+ input_store_two(ictx->b, CODE_ATTRIBUTES, ictx->s->attr, ictx->s->colr);
}
void
diff --git a/local.c b/local.c
index ce735545..87031e1e 100644
--- a/local.c
+++ b/local.c
@@ -1,4 +1,4 @@
-/* $Id: local.c,v 1.11 2007-09-29 14:25:49 nicm Exp $ */
+/* $Id: local.c,v 1.12 2007-10-01 14:18:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -37,6 +37,7 @@
int local_cmp(const void *, const void *);
int local_putc(int);
void local_putp(const char *);
+void local_attributes(u_char, u_char);
/* Local key types and key codes. */
struct local_key {
@@ -204,6 +205,8 @@ int local_fd;
struct buffer *local_in;
struct buffer *local_out;
struct termios local_tio;
+u_char local_attr;
+u_char local_colr;
/* Initialise local terminal. */
int
@@ -260,6 +263,9 @@ local_init(struct buffer **in, struct buffer **out)
qsort(local_keys, sizeof local_keys /
sizeof local_keys[0], sizeof local_keys[0], local_cmp);
+ local_attr = 0;
+ local_colr = 0x88;
+
return (local_fd);
}
@@ -304,7 +310,7 @@ local_done(void)
int
local_putc(int c)
{
- FILE *f;
+ /* XXX FILE *f;*/
u_char ch = c;
if (c < 0 || c > (int) UCHAR_MAX)
@@ -635,115 +641,77 @@ local_output(struct buffer *b, size_t size)
buffer_remove(b, ua);
break;
case CODE_ATTRIBUTES:
- if (size < 2)
+ if (size < 4)
fatalx("CODE_ATTRIBUTES underflow");
- size -= 2;
+ size -= 4;
ua = input_extract16(b);
+ ub = input_extract16(b);
- if (exit_attribute_mode == NULL) {
- log_warnx("exit_attribute_mode not supported");
- break;
- }
- if (ua == 0) {
- local_putp(exit_attribute_mode);
- break;
- }
-
- while (ua-- != 0) {
- if (size < 2)
- fatalx("CODE_ATTRIBUTES underflow");
- size -= 2;
- ub = input_extract16(b);
-
- switch (ub) {
- case 0:
- case 10:
- if (exit_attribute_mode)
- local_putp(exit_attribute_mode);
- break;
- case 1:
- if (enter_bold_mode)
- local_putp(enter_bold_mode);
- break;
- case 2:
- if (enter_dim_mode)
- local_putp(enter_dim_mode);
- break;
- case 3:
- if (enter_standout_mode)
- local_putp(enter_standout_mode);
- break;
- case 4:
- if (enter_underline_mode)
- local_putp(enter_underline_mode);
- break;
- case 5:
- if (enter_blink_mode)
- local_putp(enter_blink_mode);
- break;
- case 7:
- if (enter_reverse_mode)
- local_putp(enter_reverse_mode);
- break;
- case 8:
- if (enter_secure_mode)
- local_putp(enter_secure_mode);
- break;
- case 23:
- if (exit_standout_mode)
- local_putp(exit_standout_mode);
- break;
- case 24:
- if (exit_underline_mode)
- local_putp(exit_underline_mode);
- break;
- case 30:
- case 31:
- case 32:
- case 33:
- case 34:
- case 35:
- case 36:
- case 37:
- if (set_a_foreground == NULL)
- break;
- local_putp(
- tparm(set_a_foreground, ub - 30));
- break;
- case 39:
- if (set_a_foreground == NULL)
- break;
- if (tigetflag("AX") == TRUE) {
- local_putp("\e[39m");
- break;
- }
- local_putp(tparm(set_a_foreground, 7));
- break;
- case 40:
- case 41:
- case 42:
- case 43:
- case 44:
- case 45:
- case 46:
- case 47:
- if (set_a_background == NULL)
- break;
- local_putp(
- tparm(set_a_background, ub - 40));
- break;
- case 49:
- if (set_a_background == NULL)
- break;
- if (tigetflag("AX") == TRUE) {
- local_putp("\e[49m");
- break;
- }
- local_putp(tparm(set_a_background, 0));
- break;
- }
- }
+ local_attributes(ua, ub);
break;
}
}
}
+
+void
+local_attributes(u_char attr, u_char colr)
+{
+ u_char fg, bg;
+
+ if (attr == local_attr && colr == local_colr)
+ return;
+ if (exit_attribute_mode == NULL) {
+ log_warnx("exit_attribute_mode not supported");
+ return;
+ }
+
+ /* If any bits are being cleared, reset everything. */
+ if (local_attr & ~attr) {
+ local_putp(exit_attribute_mode);
+ local_colr = 0x88;
+ local_attr = 0;
+ }
+
+ /* Filter out bits already set. */
+ attr &= ~local_attr;
+ local_attr |= attr;
+
+ if ((attr & ATTR_BRIGHT) && enter_bold_mode != NULL)
+ local_putp(enter_bold_mode);
+ if ((attr & ATTR_DIM) && enter_dim_mode != NULL)
+ local_putp(enter_dim_mode);
+ if ((attr & ATTR_ITALICS) && enter_standout_mode != NULL)
+ local_putp(enter_standout_mode);
+ if ((attr & ATTR_UNDERSCORE) && enter_underline_mode != NULL)
+ local_putp(enter_underline_mode);
+ if ((attr & ATTR_BLINK) && enter_blink_mode != NULL)
+ local_putp(enter_blink_mode);
+ if ((attr & ATTR_REVERSE) && enter_reverse_mode != NULL)
+ local_putp(enter_reverse_mode);
+ if ((attr & ATTR_HIDDEN) && enter_secure_mode != NULL)
+ local_putp(enter_secure_mode);
+
+ fg = (colr >> 4) & 0xf;
+ if (fg != ((local_colr >> 4) & 0xf)) {
+ if (fg == 8) {
+ if (tigetflag("AX") == TRUE)
+ local_putp("\e[39m");
+ else if (set_a_foreground != NULL)
+ local_putp(tparm(set_a_foreground, 7));
+ } else if (set_a_foreground != NULL)
+ local_putp(tparm(set_a_foreground, fg));
+ }
+
+ bg = colr & 0xf;
+ if (bg != (local_colr & 0xf)) {
+ if (bg == 8) {
+ if (tigetflag("AX") == TRUE)
+ local_putp("\e[49m");
+ else if (set_a_background != NULL)
+ local_putp(tparm(set_a_background, 0));
+ } else if (set_a_background != NULL)
+ local_putp(tparm(set_a_background, bg));
+ }
+
+ local_colr = colr;
+}
diff --git a/screen.c b/screen.c
index 5f939352..5d81afd8 100644
--- a/screen.c
+++ b/screen.c
@@ -1,4 +1,4 @@
-/* $Id: screen.c,v 1.18 2007-10-01 14:15:48 nicm Exp $ */
+/* $Id: screen.c,v 1.19 2007-10-01 14:18:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -172,9 +172,7 @@ void
screen_draw(struct screen *s, struct buffer *b, u_int uy, u_int ly)
{
u_char attr, colr;
- size_t size;
u_int i, j;
- uint16_t n;
if (uy > screen_last_y(s) || ly > screen_last_y(s) || ly < uy)
fatalx("bad range");
@@ -186,112 +184,29 @@ screen_draw(struct screen *s, struct buffer *b, u_int uy, u_int ly)
input_store_two(b, CODE_SCROLLREGION, s->ry_upper + 1, s->ry_lower + 1);
input_store_zero(b, CODE_CURSOROFF);
-
- input_store_one(b, CODE_ATTRIBUTES, 0);
+ input_store_two(b, CODE_ATTRIBUTES, attr, colr);
for (j = uy; j <= ly; j++) {
input_store_two(b, CODE_CURSORMOVE, j + 1, 1);
for (i = 0; i <= screen_last_x(s); i++) {
- size = BUFFER_USED(b);
- input_store_one(b, CODE_ATTRIBUTES, 0);
-
- n = 0;
- if (s->grid_attr[j][i] != attr) {
+ if (s->grid_attr[j][i] != attr ||
+ s->grid_colr[j][i] != colr) {
+ input_store_two(b, CODE_ATTRIBUTES,
+ s->grid_attr[j][i], s->grid_colr[j][i]);
attr = s->grid_attr[j][i];
- n += screen_store_attributes(b, attr);
- if (attr == 0)
- colr = SCREEN_DEFCOLR;
- }
- if (s->grid_colr[j][i] != colr) {
colr = s->grid_colr[j][i];
- n += screen_store_colours(b, colr);
- }
- if (n == 0)
- buffer_reverse_add(b, 4);
- else {
- size = BUFFER_USED(b) - size;
- memcpy(BUFFER_IN(b) - size + 2, &n, 2);
}
-
input_store8(b, s->grid_data[j][i]);
}
}
-
- size = BUFFER_USED(b);
- input_store_one(b, CODE_ATTRIBUTES, 0);
- n = screen_store_attributes(b, s->attr);
- n += screen_store_colours(b, s->colr);
- size = BUFFER_USED(b) - size;
- memcpy(BUFFER_IN(b) - size + 2, &n, 2);
-
input_store_two(b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
+ input_store_two(b, CODE_ATTRIBUTES, s->attr, s->colr);
if (s->mode & MODE_CURSOR)
input_store_zero(b, CODE_CURSORON);
}
-/* Store screen atttributes in buffer. */
-size_t
-screen_store_attributes(struct buffer *b, u_char attr)
-{
- size_t n;
-
- if (attr == 0) {
- input_store16(b, 0);
- return (1);
- }
-
- n = 0;
- if (attr & ATTR_BRIGHT) {
- input_store16(b, 1);
- n++;
- }
- if (attr & ATTR_DIM) {
- input_store16(b, 2);
- n++;
- }
- if (attr & ATTR_ITALICS) {
- input_store16(b, 3);
- n++;
- }
- if (attr & ATTR_UNDERSCORE) {
- input_store16(b, 4);
- n++;
- }
- if (attr & ATTR_BLINK) {
- input_store16(b, 5);
- n++;
- }
- if (attr & ATTR_REVERSE) {
- input_store16(b, 7);
- n++;
- }
- if (attr & ATTR_HIDDEN) {
- input_store16(b, 8);
- n++;
- }
- return (n);
-}
-
-/* Store screen colours in buffer. */
-size_t
-screen_store_colours(struct buffer *b, u_char colr)
-{
- uint16_t v;
-
- v = colr >> 4;
- if (v == 8)
- v = 9;
- input_store16(b, 30 + v);
- v = colr & 0xf;
- if (v == 8)
- v = 9;
- input_store16(b, 40 + v);
-
- return (2);
-}
-
/* Make a range of lines. */
void
screen_make_lines(struct screen *s, u_int py, u_int ny)
diff --git a/server-fn.c b/server-fn.c
index 598632b2..6b14c0ad 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -1,4 +1,4 @@
-/* $Id: server-fn.c,v 1.8 2007-09-29 13:22:15 nicm Exp $ */
+/* $Id: server-fn.c,v 1.9 2007-10-01 14:18:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -203,9 +203,7 @@ server_write_message(struct client *c, const char *fmt, ...)
input_store_zero(c->out, CODE_CURSOROFF);
input_store_two(c->out, CODE_CURSORMOVE, c->sy, 1);
- input_store_one(c->out, CODE_ATTRIBUTES, 2);
- input_store16(c->out, 0);
- input_store16(c->out, 7);
+ input_store_two(c->out, CODE_ATTRIBUTES, ATTR_REVERSE, 0x88);
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end(ap);
diff --git a/tmux.h b/tmux.h
index dd23f91f..f4668db3 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.29 2007-10-01 14:15:48 nicm Exp $ */
+/* $Id: tmux.h,v 1.30 2007-10-01 14:18:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -568,8 +568,6 @@ void screen_create(struct screen *, u_int, u_int);
void screen_destroy(struct screen *);
void screen_resize(struct screen *, u_int, u_int);
void screen_draw(struct screen *, struct buffer *, u_int, u_int);
-size_t screen_store_attributes(struct buffer *, u_char);
-size_t screen_store_colours(struct buffer *, u_char);
void screen_write_character(struct screen *, u_char);
void screen_insert_lines(struct screen *, u_int, u_int);
void screen_insert_lines_region(struct screen *, u_int, u_int);