vile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vile] Unicode support for Win32 console driver


From: Rick Sladkey
Subject: [vile] Unicode support for Win32 console driver
Date: Sun, 17 Oct 2010 18:38:00 -0400

Here is a patch that adds Unicode support to the vile Win32 console
driver.  The winvile flavor already has unicode support but I had
difficulty getting it to work because winvile refused to recognize
"Lucida Console" as a Unicode font.  This patch also relaxes the
method winvile uses so that at least "Lucida Console" is recognized.

diff -ru orig\vile-9.8/estruct.h vile-9.8/estruct.h
--- orig\vile-9.8/estruct.h     2010-04-11 14:52:01.000000000 -0400
+++ vile-9.8/estruct.h  2010-10-12 01:43:17.048100900 -0400
@@ -2601,7 +2601,7 @@
 #define WIDE_CURSES 0
 #endif
 
-#if OPT_MULTIBYTE && (DISP_TERMCAP || WIDE_CURSES || DISP_X11 || (DISP_NTWIN 
&& defined(UNICODE)))
+#if OPT_MULTIBYTE && (DISP_TERMCAP || WIDE_CURSES || DISP_X11 || ((DISP_NTCONS 
|| DISP_NTWIN) && defined(UNICODE)))
 typedef USHORT VIDEO_TEXT;
 typedef USHORT VIDEO_CHAR;
 #else
diff -ru orig\vile-9.8/ntconio.c vile-9.8/ntconio.c
--- orig\vile-9.8/ntconio.c     2009-12-08 20:43:48.000000000 -0500
+++ vile-9.8/ntconio.c  2010-10-12 01:37:54.946100900 -0400
@@ -43,6 +43,7 @@
 static int icursor_cmdmode;    /* cmd mode cursor height             */
 static int icursor_insmode;    /* insertion mode  cursor height      */
 static int chgd_cursor;                /* must restore cursor height on exit */
+static ENC_CHOICES my_encoding = enc_DEFAULT;
 
 static int cfcolor = -1;       /* current forground color */
 static int cbcolor = -1;       /* current background color */
@@ -62,7 +63,7 @@
 static const char *initpalettestr = "0 4 2 6 1 5 3 7 8 12 10 14 9 13 11 15";
 /* black, red, green, yellow, blue, magenta, cyan, white   */
 
-static char linebuf[NCOL];
+static W32_CHAR linebuf[NCOL];
 static int bufpos = 0;
 
 /* Add state variables for console vile's autoscroll feature.              */
@@ -145,32 +146,15 @@
     if (bufpos) {
        COORD coordCursor;
        DWORD written;
-#ifdef UNICODE
-       W32_CHAR *actual;
-       char save_buf;
-#endif
 
        coordCursor.X = (SHORT) ccol;
        coordCursor.Y = (SHORT) crow;
        TRACE2(("scflush %04x [%d,%d]%.*s\n",
                currentAttribute, crow, ccol, bufpos, linebuf));
-#ifdef UNICODE
-       save_buf = linebuf[bufpos];
-       linebuf[bufpos] = 0;
-       if ((actual = w32_charstring(linebuf)) != 0) {
-           WriteConsoleOutputCharacter(
-                                          hConsoleOutput, actual, bufpos,
-                                          coordCursor, &written
-               );
-           free(actual);
-       }
-       linebuf[bufpos] = save_buf;
-#else
        WriteConsoleOutputCharacter(
                                       hConsoleOutput, linebuf, bufpos,
                                       coordCursor, &written
            );
-#endif
        FillConsoleOutputAttribute(
                                      hConsoleOutput, currentAttribute,
                                      bufpos, coordCursor, &written
@@ -377,7 +361,7 @@
     if (ch >= ' ') {
 
        /* This is an optimization for the most common case. */
-       linebuf[bufpos++] = (char) ch;
+       linebuf[bufpos++] = (W32_CHAR) ch;
 
     } else {
 
@@ -416,7 +400,7 @@
            break;
 
        default:
-           linebuf[bufpos++] = (char) ch;
+           linebuf[bufpos++] = (W32_CHAR) ch;
            break;
        }
     }
@@ -499,6 +483,18 @@
 }
 
 static void
+ntconio_set_encoding(ENC_CHOICES code)
+{
+    my_encoding = code;
+}
+
+static ENC_CHOICES
+ntconio_get_encoding(void)
+{
+    return my_encoding;
+}
+
+static void
 ntconio_open(void)
 {
     CONSOLE_CURSOR_INFO newcci;
@@ -546,6 +542,7 @@
     newscreensize(csbi.dwMaximumWindowSize.Y, csbi.dwMaximumWindowSize.X);
     hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
     SetConsoleCtrlHandler(nthandler, TRUE);
+    ntconio_set_encoding(enc_UTF16);
 }
 
 static void
@@ -1496,8 +1493,8 @@
     NROW,
     NCOL,
     NCOL,
-    dumb_set_encoding,
-    dumb_get_encoding,
+    ntconio_set_encoding,
+    ntconio_get_encoding,
     ntconio_open,
     ntconio_close,
     ntconio_kopen,
diff -ru orig\vile-9.8/ntwinio.c vile-9.8/ntwinio.c
--- orig\vile-9.8/ntwinio.c     2010-02-14 13:43:03.000000000 -0500
+++ vile-9.8/ntwinio.c  2010-09-06 22:28:13.589895800 -0400
@@ -1083,7 +1083,7 @@
         * FIXME - find how to (simply) determine the total number of glyphs
         * in a font.
         */
-       if ((metrics.tmFirstChar == 0x20) && (metrics.tmLastChar > 10000)) {
+       if ((metrics.tmFirstChar == 0x20) && (metrics.tmLastChar > 8000)) {
            term.set_enc(enc_UTF16);
            TRACE(("Assume font useful for UNICODE\n"));
        } else {
diff -ru orig\vile-9.8/w32oo.cpp vile-9.8/w32oo.cpp
--- orig\vile-9.8/w32oo.cpp     2009-05-18 17:15:31.000000000 -0400
+++ vile-9.8/w32oo.cpp  2010-09-06 19:26:43.424895800 -0400
@@ -37,7 +37,7 @@
     W32_CHAR buffer[FILENAME_MAX];
     char *result;
 
-    rc = SHGetPathFromIDList(lp, buffer);
+    rc = SHGetPathFromIDList(lp, (LPWSTR) buffer);
     if (rc) {
        if ((result = asc_charstring(buffer)) != 0) {
            strcpy(bufferp, result);
@@ -166,7 +166,7 @@
             break;
         case BFFM_SELCHANGED:
            // Set the status window text to the currently selected path.
-           if (SHGetPathFromIDList((LPITEMIDLIST) lp, szDir))
+           if (SHGetPathFromIDList((LPITEMIDLIST) lp, (LPWSTR) szDir))
               SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) szDir);
            break;
         default:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]