From 5ca710d9e3284393dfbd294915e9e4251b0fe728 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 16 Nov 2008 13:28:59 +0000 Subject: [PATCH] Disable UTF-8 by default and add options to enable it. --- CHANGES | 12 +++++++++++- cmd-set-option.c | 3 ++- cmd-set-window-option.c | 26 +++++++++++++++++++++++++- cmd-show-window-options.c | 4 +++- input.c | 4 ++-- session.c | 4 +++- tmux.1 | 16 ++++++++++++++-- tmux.c | 3 ++- tmux.h | 3 ++- tty.c | 4 ++-- 10 files changed, 66 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 999397cb..b26c1d25 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,15 @@ 16 November 2008 +* New window option: "utf8"; this must be on (it is off by default) for UTF-8 + to be parsed. The global/session option "utf8-default" controls the setting + for new windows. + + This means that by default tmux does not handle UTF-8. To use UTF-8 by + default it is necessary to a) "set utf8-default on" in .tmux.conf b) start + tmux with -u on any terminal which support UTF-8. + + It seems a bit unnecessary for this to be a per-window option but that is + the easiest way to do it, and it can't do any harm... * Enable default colours if op contains \033[39;49m, based on a report from fulvio ciriaco. @@ -697,4 +707,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.166 2008-11-16 10:10:26 nicm Exp $ +$Id: CHANGES,v 1.167 2008-11-16 13:28:59 nicm Exp $ diff --git a/cmd-set-option.c b/cmd-set-option.c index e3711b3f..a19be156 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.43 2008-09-26 06:45:25 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.44 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -77,6 +77,7 @@ const struct set_option_entry set_option_table[NSETOPTION] = { { "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "status-left", SET_OPTION_STRING, 0, 0, NULL }, { "status-right", SET_OPTION_STRING, 0, 0, NULL }, + { "utf8", SET_OPTION_FLAG, 0, 0, NULL }, }; void set_option_string(struct cmd_ctx *, diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c index 018d0809..cafce6bb 100644 --- a/cmd-set-window-option.c +++ b/cmd-set-window-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-window-option.c,v 1.12 2008-09-25 23:28:15 nicm Exp $ */ +/* $Id: cmd-set-window-option.c,v 1.13 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -181,6 +181,30 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) s->name, wl->idx, data->option); } + recalculate_sizes(); + } else if (strcmp(data->option, "utf8") == 0) { + if (flag == -1) { + ctx->error(ctx, "bad value: %s", data->value); + return; + } + + if (flag == -2) + wl->window->flags ^= WINDOW_UTF8; + else { + if (flag) + wl->window->flags |= WINDOW_UTF8; + else + wl->window->flags &= ~WINDOW_UTF8; + } + + if (wl->window->flags & WINDOW_UTF8) { + ctx->info(ctx, "window %s:%d: set %s", + s->name, wl->idx, data->option); + } else { + ctx->info(ctx, "window %s:%d: cleared %s", + s->name, wl->idx, data->option); + } + recalculate_sizes(); } else if (strcmp(data->option, "force-width") == 0) { if (data->value == NULL || number == -1) { diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c index abd4078b..bc8054dd 100644 --- a/cmd-show-window-options.c +++ b/cmd-show-window-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-window-options.c,v 1.2 2008-06-29 07:04:30 nicm Exp $ */ +/* $Id: cmd-show-window-options.c,v 1.3 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -62,6 +62,8 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->print(ctx, "monitor-activity"); if (wl->window->flags & WINDOW_ZOMBIFY) ctx->print(ctx, "remain-on-exit"); + if (wl->window->flags & WINDOW_UTF8) + ctx->print(ctx, "utf8"); if (ctx->cmdclient != NULL) server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); diff --git a/input.c b/input.c index c6022250..25995132 100644 --- a/input.c +++ b/input.c @@ -1,4 +1,4 @@ -/* $Id: input.c,v 1.66 2008-11-04 20:41:10 nicm Exp $ */ +/* $Id: input.c,v 1.67 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -510,7 +510,7 @@ input_state_utf8(u_char ch, struct input_ctx *ictx) void input_handle_character(u_char ch, struct input_ctx *ictx) { - if (ch > 0x7f) { + if (ictx->w->flags & WINDOW_UTF8 && ch > 0x7f) { /* * UTF-8 sequence. * diff --git a/session.c b/session.c index 32e595d6..d3af7388 100644 --- a/session.c +++ b/session.c @@ -1,4 +1,4 @@ -/* $Id: session.c,v 1.45 2008-11-16 10:10:26 nicm Exp $ */ +/* $Id: session.c,v 1.46 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -209,6 +209,8 @@ session_new(struct session *s, const char *name, const char *cmd, int idx) if (options_get_number(&s->options, "remain-by-default")) w->flags |= WINDOW_ZOMBIFY; + if (options_get_number(&s->options, "utf8-default")) + w->flags |= WINDOW_UTF8; return (session_attach(s, w, idx)); } diff --git a/tmux.1 b/tmux.1 index 799ace09..8bb28de2 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.49 2008-09-25 20:08:56 nicm Exp $ +.\" $Id: tmux.1,v 1.50 2008-11-16 13:28:59 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -23,7 +23,7 @@ .Sh SYNOPSIS .Nm tmux .Bk -words -.Op Fl qVv +.Op Fl 2dquVv .Op Fl f Ar file .Op Fl S Ar socket-path .Op Ar command Op Ar flags @@ -50,6 +50,14 @@ Communication takes place through a socket, by default placed in .Pp The options are as follows: .Bl -tag -width "XXXXXXXXXXXX" +.It Fl 2 +Force +.Nm +to assume the terminal supports 256 colours. +.It Fl d +Force +.Nm +to assume the terminal support default colours. .It Fl f Ar file Specify an alternative configuration file. By default, @@ -70,6 +78,10 @@ where .Em UID is the uid of the user who invoked .Nm . +.If Fl u +Intruct +.Nm +that the terminal support UTF-8. .It Fl V Print program version. .It Fl v diff --git a/tmux.c b/tmux.c index 15c1d3b8..a481826d 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.79 2008-09-29 16:03:27 nicm Exp $ */ +/* $Id: tmux.c,v 1.80 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -231,6 +231,7 @@ main(int argc, char **argv) options_set_number(&global_options, "buffer-limit", 9); options_set_number(&global_options, "remain-by-default", 0); options_set_number(&global_options, "mode-keys", MODEKEY_EMACS); + options_set_number(&global_options, "utf8-default", 0); if (cfg_file == NULL) { home = getenv("HOME"); diff --git a/tmux.h b/tmux.h index bab5e998..c4131270 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.196 2008-11-16 10:10:26 nicm Exp $ */ +/* $Id: tmux.h,v 1.197 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -569,6 +569,7 @@ struct window { #define WINDOW_MONITOR 0x8 #define WINDOW_AGGRESSIVE 0x10 #define WINDOW_ZOMBIFY 0x20 +#define WINDOW_UTF8 0x40 u_int limitx; u_int limity; diff --git a/tty.c b/tty.c index 90c4b9d0..22f0daf7 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.50 2008-11-16 10:10:26 nicm Exp $ */ +/* $Id: tty.c,v 1.51 2008-11-16 13:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -888,7 +888,7 @@ tty_cmd_cell(struct tty *tty, unused struct screen *s, va_list ap) tty_attributes(tty, gc); /* If not UTF8 multibyte, write directly. */ - if (gc->data < 0xff) { + if (gc->data <= 0xff) { tty_putc(tty, gc->data); return; }