From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3602 invoked from network); 24 Oct 2005 16:53:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Oct 2005 16:53:29 -0000 Received: (qmail 56646 invoked from network); 24 Oct 2005 16:53:24 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Oct 2005 16:53:24 -0000 Received: (qmail 24510 invoked by alias); 24 Oct 2005 16:53:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21930 Received: (qmail 24499 invoked from network); 24 Oct 2005 16:53:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Oct 2005 16:53:20 -0000 Received: (qmail 56335 invoked from network); 24 Oct 2005 16:53:20 -0000 Received: from cluster-c.mailcontrol.com (HELO rly01c.srv.mailcontrol.com) (168.143.177.190) by a.mx.sunsite.dk with SMTP; 24 Oct 2005 16:53:19 -0000 Received: from exchange03.csr.com (mailhost1.csr.com [81.105.217.43]) by rly01c.srv.mailcontrol.com (MailControl) with ESMTP id j9OGrHuS015766 for ; Mon, 24 Oct 2005 17:53:17 +0100 Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 24 Oct 2005 17:55:33 +0100 Date: Mon, 24 Oct 2005 17:53:15 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: PATCH: displaying wide characters Message-Id: <20051024175315.2c892cd0.pws@csr.com> In-Reply-To: References: <200510192031.j9JKVYk7010115@pwslaptop.csr.com> <200510192041.j9JKfTJZ010450@pwslaptop.csr.com> <237967ef0510191739t103352a9vad735334a790d8b5@mail.gmail.com> <237967ef0510240140g548e0c0r3deb3f4704dc313@mail.gmail.com> <20051024100716.2efa76f1.pws@csr.com> <237967ef0510240541w2cd39b10l3b381a345bfb7ec4@mail.gmail.com> Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 24 Oct 2005 16:55:33.0629 (UTC) FILETIME=[BFAE6AD0:01C5D8BB] X-Scanned-By: MailControl A-05-40-01 (www.mailcontrol.com) on 10.67.0.111 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Peter Stephenson wrote: > Mikael Magnusson wrote: > > My terminal (rxvt-unicode) automatically breaks a wide character to > > the next line if you try to print it in the last (singlewidth) column > > of a line. Zsh does seem to get confused when you get to the second > > line then. > > Yes, I think this is fairly standard, hence adding spaces in front ought > to be the right thing to do. I think this fixes the end-of-line problem, which is the easier one. If the screen's just too narrow for the character it simply prints a '?'; that's a very unusual case where safety is probably best. However, maybe some other character might make the user more aware of what's going on, '>' for example? Index: Src/Zle/zle_refresh.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v retrieving revision 1.31 diff -u -r1.31 zle_refresh.c --- Src/Zle/zle_refresh.c 19 Oct 2005 23:45:06 -0000 1.31 +++ Src/Zle/zle_refresh.c 24 Oct 2005 16:50:20 -0000 @@ -612,7 +612,7 @@ rpms.sen = *nbuf + winw; for (; t < tmpline+tmpll; t++) { if (t == scs) /* if cursor is here, remember it */ - rpms.nvcs = rpms.s - (nbuf[rpms.nvln = rpms.ln]); + rpms.nvcs = rpms.s - nbuf[rpms.nvln = rpms.ln]; if (*t == ZWC('\n')){ /* newline */ /* text not wrapped */ @@ -631,33 +631,33 @@ } #ifdef ZLE_UNICODE_SUPPORT else if (iswprint(*t)) { - int width = wcwidth(*t), break2 = 0; - *rpms.s++ = *t; - while (--width > 0) { + int width = wcwidth(*t); + if (width > rpms.sen - rpms.s) { /* - * Character is wider than a single position. - * Put WEOF into the positions above 1 as placeholders. - * This keeps the indexing into the video buffer correct. + * Too wide to fit. Insert spaces to end of current line. */ - if (rpms.s == rpms.sen) { - /* - * Text wrapped. - * - * TODO: hmm, what is the terminal emulator going to - * do? Let's assume some kind of automatic margin - * behaviour, implying we continue the procedure on the - * next line. Wrapping behaviour has always been - * problematic. I foresee interesting times... - */ - if (nextline(&rpms, 1)) { - break2 = 1; - break; - } + do { + *rpms.s++ = ZWC(' '); + } while (rpms.s < rpms.sen); + if (nextline(&rpms, 1)) + break; + if (t == scs) { + /* Update cursor to this point */ + rpms.nvcs = rpms.s - nbuf[rpms.nvln = rpms.ln]; } - *rpms.s++ = WEOF; } - if (break2) - break; + if (width > rpms.sen - rpms.s) { + /* + * The screen width is too small to fit even one + * occurrence. + */ + *rpms.s++ = ZWC('?'); + } else { + /* We can fit it without reaching the end of the line. */ + *rpms.s++ = *t; + while (--width > 0) + *rpms.s++ = WEOF; + } } #endif else if (ZC_icntrl(*t)) { /* other control character */ @@ -705,14 +705,20 @@ #ifdef ZLE_UNICODE_SUPPORT if (iswprint(*u)) { int width = wcwidth(*u); - *rpms.s++ = *u; - while (--width > 0) { - /* Wide character, handled as above */ - if (rpms.s == rpms.sen) { - nbuf[rpms.ln][winw + 1] = ZWC('\n'); - snextline(&rpms); - } - *rpms.s++ = WEOF; + /* Handle wide characters as above */ + if (width > rpms.sen - rpms.s) { + do { + *rpms.s++ = ZWC(' '); + } while (rpms.s < rpms.sen); + nbuf[rpms.ln][winw + 1] = ZWC('\n'); + snextline(&rpms); + } + if (width > rpms.sen - rpms.s) { + *rpms.s++ = ZWC('?'); + } else { + *rpms.s++ = *u; + while (--width > 0) + *rpms.s++ = WEOF; } } else -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com