From eb319f9b6e960b6c00a10c31c747ee484aad6ee1 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 1 Sep 2015 18:35:38 +0100 Subject: [PATCH] pterm: set IUTF8 on pty devices depending on charset. In a UTF-8 pterm, it makes sense to set the IUTF8 flag (on systems that have one) on the pty device, so that line editing will take account of UTF-8 multibyte characters. (cherry picked from commit 1840103c05d10ba1c45353282b4ad7f742a75b92) --- unix/gtkwin.c | 6 ++++++ unix/unix.h | 1 + unix/uxpty.c | 19 +++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 4cce11e6..1c29b41e 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -2914,6 +2914,12 @@ void uxsel_input_remove(int id) { gdk_input_remove(id); } +int frontend_is_utf8(void *frontend) +{ + struct gui_data *inst = (struct gui_data *)frontend; + return inst->ucsdata.line_codepage == CS_UTF8; +} + char *setup_fonts_ucs(struct gui_data *inst) { int shadowbold = conf_get_int(inst->conf, CONF_shadowbold); diff --git a/unix/unix.h b/unix/unix.h index 917976d6..e78800b5 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -77,6 +77,7 @@ unsigned long getticks(void); /* based on gettimeofday(2) */ char *get_x_display(void *frontend); int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */ long get_windowid(void *frontend); +int frontend_is_utf8(void *frontend); /* Things gtkdlg.c needs from pterm.c */ void *get_window(void *frontend); /* void * to avoid depending on gtk.h */ diff --git a/unix/uxpty.c b/unix/uxpty.c index 307690d6..e504b705 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -738,14 +738,29 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, pty_open_master(pty); /* - * Set the backspace character to be whichever of ^H and ^? is - * specified by bksp_is_delete. + * Set up configuration-dependent termios settings on the new pty. */ { struct termios attrs; tcgetattr(pty->master_fd, &attrs); + + /* + * Set the backspace character to be whichever of ^H and ^? is + * specified by bksp_is_delete. + */ attrs.c_cc[VERASE] = conf_get_int(conf, CONF_bksp_is_delete) ? '\177' : '\010'; + + /* + * Set the IUTF8 bit iff the character set is UTF-8. + */ +#ifdef IUTF8 + if (frontend_is_utf8(frontend)) + attrs.c_iflag |= IUTF8; + else + attrs.c_iflag &= ~IUTF8; +#endif + tcsetattr(pty->master_fd, TCSANOW, &attrs); }