diff --git a/CHANGES b/CHANGES index 2a17df34..c55af603 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +10 September 2008 + +* Split off colour conversion code from screen code. + 09 September 2008 * Initial UTF-8 support. A bit ugly and with a limit of 4096 UTF-8 @@ -660,4 +664,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.159 2008-09-09 22:16:36 nicm Exp $ +$Id: CHANGES,v 1.160 2008-09-10 18:59:29 nicm Exp $ diff --git a/Makefile b/Makefile index 664bfb2e..51334ace 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.73 2008-09-09 22:16:36 nicm Exp $ +# $Id: Makefile,v 1.74 2008-09-10 18:59:29 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean update-index.html upload-index.html @@ -16,7 +16,8 @@ DEBUG= META?= \002 # C-b SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ - xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c screen-display.c \ + xmalloc.c xmalloc-debug.c input.c input-keys.c \ + screen.c screen-display.c screen-write.c screen-redraw.c \ window.c session.c log.c client.c client-msg.c client-fn.c cfg.c \ key-string.c key-bindings.c resize.c arg.c mode-key.c \ cmd.c cmd-generic.c cmd-string.c \ @@ -35,7 +36,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-list-commands.c cmd-move-window.c cmd-select-prompt.c \ cmd-respawn-window.c \ window-scroll.c window-more.c window-copy.c options.c paste.c \ - tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c utf8.c + tty.c tty-keys.c tty-write.c colour.c utf8.c CC?= cc INCDIRS+= -I. -I- -I/usr/local/include diff --git a/TODO b/TODO index 2794017c..54311a6f 100644 --- a/TODO +++ b/TODO @@ -41,6 +41,18 @@ -- For 0.5 -------------------------------------------------------------------- +XXX +screen contains grid + +screen_write <-- write to TTY and to screen using close-to-ANSI functions +screen_redraw <-- write areas of screen to TTY +grid_view <-- write to viewable area of grid +grid <-- manipulate grid and history + +XXX +grid_view has ox,oy +XXX + - FINISH UTF8: fix copy and paste - SPLIT u_short attr into attr,flags? - maybe rethink backend data structure? @@ -54,6 +66,16 @@ - write to ttys without updating screen --- +NEED to be able to: + resize screen + apply ops to both screen and tty simultaneously + both when parsing input and when eg scrolling history + draw on the top of the screen without modifying it + display arbitrary parts of the history + redraw arbitrary parts of the visible screen +--- +NEVER need to draw into the history + split off grid manip: 16-bit characters 8-bit flags @@ -62,9 +84,14 @@ split off grid manip: 8-bit bg colour struct grid_data { - struct grid_cell **cells; - u_int sx; - u_int sy; + struct grid_cell **data; + int *sizes; + + int sx; + int sy; + + int hsize; + int hlimit; }; struct grid_cell { u_short data; @@ -72,7 +99,63 @@ struct grid_cell { u_char flags; u_char fg; u_char bg; -} +}; +const struct grid_default_cell = { 0x20, 0, 0, 8, 8 }; + +; grid logically split from +; -hlimit to 0 and 0 to sy + +; ALWAYS fill with default + +const struct grid_cell *grid_get(int x, int y); +void grid_set(int x, int y, const struct grid_cell *cell); + +void grid_resize() +void grid_shift() /* shift lines into history */ + +struct grid_view { + int ox; + int oy; + + int sx; + int sy; + + struct grid_data *gdata; + struct grid_view *parent; +}; + +struct grid_cell *grid_view_get_cell(int x, int y) +void grid_view_set_cell(int x, int y, const struct grid_cell *cell); + +int grid_view_absolute_x(int x); +int grid_view_absolute_y(int y); + +int grid_view_relative_x(int x); +int grid_view_relative_y(int y); + +void grid_view_delete_lines(int y, int ny) +void grid_view_insert_lines(int y, int ny) +void grid_view_clear_lines(int y, int ny) +void grid_view_fill_lines(int y, int ny, const struct grid_cell *cell) + +void grid_view_delete_cells(int x, int y, int nx) +void grid_view_insert_cells(int x, int y, int nx) +void grid_view_clear_cells(int x, int y, int nx) +void grid_view_fill_cells(int x, int nx, const struct grid_cell *cell) + +void grid_view_clear_area(int x, int y, int nx, int ny) +void grid_view_fill_area(int x, int y, int nx, int ny, const struct grid_cell *cell) + +--- + +screen has two (both grid_view): + base and overlay + +--- +screen_write writes into overlay if it exists and then base, also optionally to tty +screen_draw draws overlay + base to display +--- + --- Would it be better to just expand char to 16-bits and use it as an index only diff --git a/cmd-set-option.c b/cmd-set-option.c index 156e1468..8f6a488d 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.40 2008-07-19 10:07:50 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.41 2008-09-10 18:59:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -271,7 +271,7 @@ set_option_colour(struct cmd_ctx *ctx, struct options *oo, return; } - if ((colour = screen_stringcolour(value)) > 8) { + if ((colour = colour_fromstring(value)) > 8) { ctx->error(ctx, "bad colour: %s", value); return; } diff --git a/cmd-show-options.c b/cmd-show-options.c index a6f80458..d1f5f559 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-options.c,v 1.5 2008-06-23 22:12:29 nicm Exp $ */ +/* $Id: cmd-show-options.c,v 1.6 2008-09-10 18:59:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -135,7 +135,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) case SET_OPTION_COLOUR: vn = options_get_number(oo, entry->name); ctx->print(ctx, "%s %s", - entry->name, screen_colourstring(vn)); + entry->name, colour_tostring(vn)); break; case SET_OPTION_FLAG: vn = options_get_number(oo, entry->name); diff --git a/colour.c b/colour.c new file mode 100644 index 00000000..36a2cf6f --- /dev/null +++ b/colour.c @@ -0,0 +1,74 @@ +/* $Id: colour.c,v 1.1 2008-09-10 18:59:29 nicm Exp $ */ + +/* + * Copyright (c) 2008 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include + +#include "tmux.h" + +const char * +colour_tostring(u_char c) +{ + switch (c) { + case 0: + return ("black"); + case 1: + return ("red"); + case 2: + return ("green"); + case 3: + return ("yellow"); + case 4: + return ("blue"); + case 5: + return ("magenta"); + case 6: + return ("cyan"); + case 7: + return ("white"); + case 8: + return ("default"); + } + return (NULL); +} + +/* String to colour. */ +u_char +colour_fromstring(const char *s) +{ + if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0')) + return (0); + if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0')) + return (1); + if (strcasecmp(s, "green") == 0 || (s[0] == '2' && s[1] == '\0')) + return (2); + if (strcasecmp(s, "yellow") == 0 || (s[0] == '3' && s[1] == '\0')) + return (3); + if (strcasecmp(s, "blue") == 0 || (s[0] == '4' && s[1] == '\0')) + return (4); + if (strcasecmp(s, "magenta") == 0 || (s[0] == '5' && s[1] == '\0')) + return (5); + if (strcasecmp(s, "cyan") == 0 || (s[0] == '6' && s[1] == '\0')) + return (6); + if (strcasecmp(s, "white") == 0 || (s[0] == '7' && s[1] == '\0')) + return (7); + if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0')) + return (8); + return (255); +} diff --git a/screen.c b/screen.c index ec3d244b..8b4fc924 100644 --- a/screen.c +++ b/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.69 2008-09-09 22:16:36 nicm Exp $ */ +/* $Id: screen.c,v 1.70 2008-09-10 18:59:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -74,58 +74,6 @@ * If you're thinking this all seems too complicated, that's because it is :-/. */ -/* Colour to string. */ -const char * -screen_colourstring(u_char c) -{ - switch (c) { - case 0: - return ("black"); - case 1: - return ("red"); - case 2: - return ("green"); - case 3: - return ("yellow"); - case 4: - return ("blue"); - case 5: - return ("magenta"); - case 6: - return ("cyan"); - case 7: - return ("white"); - case 8: - return ("default"); - } - return (NULL); -} - -/* String to colour. */ -u_char -screen_stringcolour(const char *s) -{ - if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0')) - return (0); - if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0')) - return (1); - if (strcasecmp(s, "green") == 0 || (s[0] == '2' && s[1] == '\0')) - return (2); - if (strcasecmp(s, "yellow") == 0 || (s[0] == '3' && s[1] == '\0')) - return (3); - if (strcasecmp(s, "blue") == 0 || (s[0] == '4' && s[1] == '\0')) - return (4); - if (strcasecmp(s, "magenta") == 0 || (s[0] == '5' && s[1] == '\0')) - return (5); - if (strcasecmp(s, "cyan") == 0 || (s[0] == '6' && s[1] == '\0')) - return (6); - if (strcasecmp(s, "white") == 0 || (s[0] == '7' && s[1] == '\0')) - return (7); - if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0')) - return (8); - return (255); -} - /* Create a new screen. */ void screen_create(struct screen *s, u_int dx, u_int dy, u_int hlimit) diff --git a/tmux.h b/tmux.h index 77fb6680..fc1943b9 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.186 2008-09-09 22:16:37 nicm Exp $ */ +/* $Id: tmux.h,v 1.187 2008-09-10 18:59:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1171,6 +1171,10 @@ void input_parse(struct window *); /* input-key.c */ void input_key(struct window *, int); +/* colour.c */ +const char *colour_tostring(u_char); +u_char colour_fromstring(const char *); + /* screen-display.c */ void screen_display_get_cell(struct screen *, u_int, u_int, u_char *, u_short *, u_char *, u_char *); @@ -1251,8 +1255,6 @@ void screen_redraw_lines(struct screen_redraw_ctx *, u_int, u_int); void screen_redraw_columns(struct screen_redraw_ctx *, u_int, u_int); /* screen.c */ -const char *screen_colourstring(u_char); -u_char screen_stringcolour(const char *); void screen_create(struct screen *, u_int, u_int, u_int); void screen_reset(struct screen *); void screen_destroy(struct screen *);