1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-17 23:06:25 -05:00

Clean up handling of unicode character width (non printable are displayed as \u) and insure modeline displays filename including double and zero width characters.

This commit is contained in:
Renaud 2020-06-24 16:38:03 +08:00
parent c926a94ac2
commit cf823e2fad
5 changed files with 25 additions and 24 deletions

View File

@ -176,8 +176,7 @@ void vttidy(void)
* screen. There is no checking for nonsense values; this might be a good * screen. There is no checking for nonsense values; this might be a good
* idea during the early stages. * idea during the early stages.
*/ */
void vtmove(int row, int col) static void vtmove( int row, int col) {
{
vtrow = row; vtrow = row;
vtcol = col; vtcol = col;
} }
@ -220,6 +219,9 @@ static void vtputc( unicode_t c) {
sane_vtputc( '\\') ; sane_vtputc( '\\') ;
sane_vtputc( hex[ c >> 4]) ; sane_vtputc( hex[ c >> 4]) ;
sane_vtputc( hex[ c & 15]) ; sane_vtputc( hex[ c & 15]) ;
} else if( utf8_width( c) < 0) {
sane_vtputc( '\\') ; /* show as non printable */
sane_vtputc( 'u') ;
} else } else
sane_vtputc( c) ; sane_vtputc( c) ;
} }
@ -232,7 +234,7 @@ static int vtputs( const char *s) {
s += utf8_to_unicode( s, 0, 4, &c) ; s += utf8_to_unicode( s, 0, 4, &c) ;
vtputc( c) ; vtputc( c) ;
n += utf8_width( c) ; n += utf8_width( c) ; /* To Do: only works if all printable */
} }
return n ; return n ;
@ -569,8 +571,10 @@ void updpos(void)
curcol += 2 ; /* displayed as ^c */ curcol += 2 ; /* displayed as ^c */
else if( c >= 0x80 && c <= 0xA0) else if( c >= 0x80 && c <= 0xA0)
curcol += 3 ; /* displayed as \xx */ curcol += 3 ; /* displayed as \xx */
else else {
curcol += utf8_width( c) ; int width = utf8_width( c) ;
curcol += (width < 0) ? 2 : width ; /* non printable are displayed as \u */
}
} }
/* if extended, flag so and update the virtual line image */ /* if extended, flag so and update the virtual line image */
@ -977,9 +981,10 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
the virtual screen array */ the virtual screen array */
while( ttcol < term.t_ncol) { while( ttcol < term.t_ncol) {
/* TODO: handle double width unicode char at last screen col */ /* TODO: handle double width unicode char at last screen col */
TTputc(*cp1); unicode_t c = *cp1++ ;
ttcol += utf8_width( *cp1) ; TTputc( c) ;
*cp2++ = *cp1++; ttcol += utf8_width( c) ;
*cp2++ = c ;
} }
TTrev( FALSE) ; /* turn rev video off */ TTrev( FALSE) ; /* turn rev video off */
@ -1045,9 +1050,10 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
#endif #endif
while (cp1 != cp5) { /* Ordinary. */ while (cp1 != cp5) { /* Ordinary. */
TTputc(*cp1); unicode_t c = *cp1++ ;
ttcol += utf8_width( *cp1) ; TTputc( c) ;
*cp2++ = *cp1++; ttcol += utf8_width( c) ;
*cp2++ = c ;
} }
if (cp5 != cp3) { /* Erase. */ if (cp5 != cp3) { /* Erase. */
@ -1153,7 +1159,7 @@ static void modeline(struct window *wp)
char *msg = NULL; char *msg = NULL;
char tline[ 6] ; /* buffer for part of mode line */ char tline[ 6] ; /* buffer for part of mode line */
vtcol = n - 7; /* strlen(" top ") plus a couple */ vtcol -= 7 ; /* strlen(" top ") plus a couple */
while (rows--) { while (rows--) {
lp = lforw(lp); lp = lforw(lp);
if (lp == wp->w_bufp->b_linep) { if (lp == wp->w_bufp->b_linep) {

View File

@ -16,7 +16,6 @@ extern int gbcolor ; /* global backgrnd color (black) */
void vtinit( void) ; void vtinit( void) ;
void vtfree( void) ; void vtfree( void) ;
void vttidy( void) ; void vttidy( void) ;
void vtmove( int row, int col) ;
int upscreen( int f, int n) ; int upscreen( int f, int n) ;
int update( int force) ; int update( int force) ;
void updpos( void) ; void updpos( void) ;

4
main.c
View File

@ -141,7 +141,7 @@ int main(int argc, char **argv)
int errflag; /* C error processing? */ int errflag; /* C error processing? */
bname_t bname ; /* buffer name of file to read */ bname_t bname ; /* buffer name of file to read */
setlocale( LC_CTYPE, "en_GB.UTF-8") ; /* wide character support (UTF-32) */ setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */
#if PKCODE & BSD #if PKCODE & BSD
sleep(1); /* Time for window manager. */ sleep(1); /* Time for window manager. */
@ -226,7 +226,7 @@ int main(int argc, char **argv)
} else if( argv[ carg + 1]) { /* -X filename */ } else if( argv[ carg + 1]) { /* -X filename */
if( startup( &argv[ carg + 1][ 0]) == TRUE) if( startup( &argv[ carg + 1][ 0]) == TRUE)
startflag = TRUE ; /* don't execute emacs.rc */ startflag = TRUE ; /* don't execute emacs.rc */
carg += 1 ; carg += 1 ;
} }

12
utf8.c
View File

@ -10,16 +10,12 @@
/* /*
* Display width of UTF-8 character * Display width of UTF-8 character
*/ */
unsigned utf8_width( unicode_t c) { int utf8_width( unicode_t c) {
#if CYGWIN #if CYGWIN
assert( sizeof( wchar_t) == 2) ; /* wcwidth only handles UTF-16 */ assert( sizeof( wchar_t) == 2) ; /* wcwidth only supports UTF-16 */
return (c < 0x10000) ? (unsigned) wcwidth( (wchar_t) c) : 2 ; return (c < 0x10000) ? wcwidth( (wchar_t) c) : -1 ;
#elif BSD
// assert( sizeof( wchar_t) == 4) ; /* wcwidth should handle UTF-32 */
int ret = wcwidth( (wchar_t) c) ;
return (ret < 0) ? 1 : (unsigned) ret ;
#else #else
return (unsigned) wcwidth( (wchar_t) c) ; return wcwidth( (wchar_t) c) ;
#endif #endif
} }

2
utf8.h
View File

@ -3,7 +3,7 @@
typedef unsigned int unicode_t ; typedef unsigned int unicode_t ;
unsigned utf8_width( unicode_t c) ; int utf8_width( unicode_t c) ;
unsigned utf8_to_unicode( const char *line, unsigned index, unsigned len, unsigned utf8_to_unicode( const char *line, unsigned index, unsigned len,
unicode_t *res) ; unicode_t *res) ;
unsigned utf8_revdelta( unsigned char *buf, unsigned pos) ; unsigned utf8_revdelta( unsigned char *buf, unsigned pos) ;