From ec3b0825098dd60b2a14ab09881719968ac574a9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 25 May 2006 22:32:03 +0000 Subject: [PATCH] * Fixed UTF-8 support in ncurses. * Set ncurses's priority higher than slang. --- caca/caca.c | 10 +++++----- caca/driver_ncurses.c | 37 ++++++++++++++++++++++--------------- configure.ac | 2 +- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/caca/caca.c b/caca/caca.c index 631314e..2af4f7a 100644 --- a/caca/caca.c +++ b/caca/caca.c @@ -161,14 +161,14 @@ static int caca_init_driver(caca_display_t *dp) #if defined(USE_GL) if(gl_install(dp) == 0) return 0; #endif - /* slang has a higher priority than ncurses because though ncurses handles - * color a bit better across terminals, its UTF-8 supports seems broken. */ -#if defined(USE_SLANG) - if(slang_install(dp) == 0) return 0; -#endif + /* ncurses has a higher priority than slang because it has better colour + * support across terminal types, despite being slightly slower. */ #if defined(USE_NCURSES) if(ncurses_install(dp) == 0) return 0; #endif +#if defined(USE_SLANG) + if(slang_install(dp) == 0) return 0; +#endif return -1; } diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index 096d451..cb81cf6 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -18,13 +18,13 @@ #include "config.h" #include "common.h" -#if defined(USE_NCURSES) +#if defined USE_NCURSES -#if defined(HAVE_NCURSESW_NCURSES_H) +#if defined HAVE_NCURSESW_NCURSES_H # include -#elif defined(HAVE_NCURSES_NCURSES_H) +#elif defined HAVE_NCURSES_NCURSES_H # include -#elif defined(HAVE_NCURSES_H) +#elif defined HAVE_NCURSES_H # include #else # include @@ -33,12 +33,15 @@ #include #include -#if defined(HAVE_SIGNAL_H) +#if defined HAVE_SIGNAL_H # include #endif -#if defined(HAVE_SYS_IOCTL_H) +#if defined HAVE_SYS_IOCTL_H # include #endif +#if defined HAVE_LOCALE_H +# include +#endif #include "caca.h" #include "caca_internals.h" @@ -49,11 +52,11 @@ * Local functions */ -#if defined(HAVE_SIGNAL) +#if defined HAVE_SIGNAL static RETSIGTYPE sigwinch_handler(int); static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */ #endif -#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) +#if defined HAVE_GETENV && defined HAVE_PUTENV static void ncurses_check_terminal(void); #endif static void ncurses_write_utf32(uint32_t); @@ -93,15 +96,19 @@ static int ncurses_init_graphics(caca_display_t *dp) dp->drv.p = malloc(sizeof(struct driver_private)); -#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) +#if defined HAVE_GETENV && defined HAVE_PUTENV ncurses_check_terminal(); #endif -#if defined(HAVE_SIGNAL) +#if defined HAVE_SIGNAL sigwinch_d = dp; signal(SIGWINCH, sigwinch_handler); #endif +#if defined HAVE_LOCALE_H + setlocale(LC_ALL, ""); +#endif + initscr(); keypad(stdscr, TRUE); nonl(); @@ -207,12 +214,12 @@ static void ncurses_handle_resize(caca_display_t *dp) { struct winsize size; -#if defined(HAVE_SYS_IOCTL_H) +#if defined HAVE_SYS_IOCTL_H if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { dp->resize.w = size.ws_col; dp->resize.h = size.ws_row; -#if defined(HAVE_RESIZE_TERM) +#if defined HAVE_RESIZE_TERM resize_term(dp->resize.h, dp->resize.w); #else resizeterm(*dp->resize.h, *dp->resize.w); @@ -352,7 +359,7 @@ static int ncurses_get_event(caca_display_t *dp, caca_event_t *ev) * XXX: following functions are local */ -#if defined(HAVE_SIGNAL) +#if defined HAVE_SIGNAL static RETSIGTYPE sigwinch_handler(int sig) { sigwinch_d->resize.resized = 1; @@ -361,7 +368,7 @@ static RETSIGTYPE sigwinch_handler(int sig) } #endif -#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) +#if defined HAVE_GETENV && defined HAVE_PUTENV static void ncurses_check_terminal(void) { char *term, *colorterm, *other; @@ -401,7 +408,7 @@ static void ncurses_check_terminal(void) static void ncurses_write_utf32(uint32_t ch) { -#if defined(HAVE_NCURSESW_NCURSES_H) +#if defined HAVE_NCURSESW_NCURSES_H char buf[10]; int bytes; diff --git a/configure.ac b/configure.ac index b4021b2..cd2a749 100644 --- a/configure.ac +++ b/configure.ac @@ -65,7 +65,7 @@ dnl conditional builds AC_ARG_ENABLE(doc, [ --enable-doc build documentation (needs doxygen and LaTeX)]) -AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h) +AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h) AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) AC_CHECK_FUNCS(usleep gettimeofday)