Skip to contentSkip to conversation

curses: wide character support

PATCH In review Samuel Thibault 4 participants 14 messages Oct 15, 2016 – Oct 26, 2016

lore
Share & tools
lore
#0 lore raw

cover curses: wide character support

Hello,

This patch series adds wide character support to the curses frontend of qemu, thus allowing to fix a lot of input and output issues with e.g. accented letters and semi-graphic glyphs. Since qemu can't know the encoding of the VGA font, the user has to specify it (just like he has to specify the keyboard layout with -k). I used option -f to make it simple for now, but I welcome any other idea :)

Samuel

Samuel Thibault (5):
curses: fix left/right arrow translation
curses: Use cursesw instead of curses
curses: use wide output functions
curses: add option to specify VGA font encoding
curses: support wide input

 configure               |  71 ++++++--
 hw/display/vga.c        |   4 +-
 include/sysemu/sysemu.h |   1 +
 include/ui/console.h    |  16 +-
 qemu-options.hx         |   5 +-
 ui/curses.c             | 436 +++++++++++++++++++++++++++++++++++++++++-------
 ui/curses_keys.h        | 113 +++++++------
 vl.c                    |  21 ++-
 8 files changed, 543 insertions(+), 124 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/5 curses: fix left/right arrow translation

In default VGA font, left/right arrow are glyphs 0x1a and 0x1b, not 0x0a and 0x0b.

---
 ui/curses.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ui/curses.c +2 -2
index c8be4b7..3599295 100644
@@ -370,10 +370,10 @@ static void curses_setup(void)
     /* ACS_* is not constant. So, we can't initialize statically. */
     vga_to_curses['\0'] = ' ';
     vga_to_curses[0x04] = ACS_DIAMOND;
-    vga_to_curses[0x0a] = ACS_RARROW;
-    vga_to_curses[0x0b] = ACS_LARROW;
     vga_to_curses[0x18] = ACS_UARROW;
     vga_to_curses[0x19] = ACS_DARROW;
+    vga_to_curses[0x1a] = ACS_RARROW;
+    vga_to_curses[0x1b] = ACS_LARROW;
     vga_to_curses[0x9c] = ACS_STERLING;
     vga_to_curses[0xb0] = ACS_BOARD;
     vga_to_curses[0xb1] = ACS_CKBOARD;
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/5 curses: Use cursesw instead of curses

In reply to Samuel Thibault

Use ncursesw package instead of curses on non-mingw, and check a few functions.
Also take cflags from pkg-config, since cursesw headers may be in a separate, non-default directory.

---
 configure | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
configure +20 -9
index 7d083bd..29649d9 100755
@@ -2890,27 +2890,38 @@ fi
 # curses probe
 if test "$curses" != "no" ; then
   if test "$mingw32" = "yes" ; then
-    curses_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
+    curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
+    curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
   else
-    curses_list="$($pkg_config --libs ncurses 2>/dev/null):-lncurses:-lcurses"
+    curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):"
+    curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
   fi
   curses_found=no
   cat > $TMPC << EOF
+#include <locale.h>
 #include <curses.h>
+#include <wchar.h>
 int main(void) {
   const char *s = curses_version();
+  wchar_t wch = L'w';
+  setlocale(LC_ALL, "");
   resize_term(0, 0);
+  addwstr(L"wide chars\n");
+  addnwstr(&wch, 1);
   return s != 0;
 }
 EOF
   IFS=:
-  for curses_lib in $curses_list; do
-    unset IFS
-    if compile_prog "" "$curses_lib" ; then
-      curses_found=yes
-      libs_softmmu="$curses_lib $libs_softmmu"
-      break
-    fi
+  for curses_inc in $curses_inc_list; do
+    for curses_lib in $curses_lib_list; do
+      unset IFS
+      if compile_prog "$curses_inc" "$curses_lib" ; then
+        curses_found=yes
+        QEMU_CFLAGS="$curses_inc $QEMU_CFLAGS"
+        libs_softmmu="$curses_lib $libs_softmmu"
+        break
+      fi
+    done
   done
   unset IFS
   if test "$curses_found" = "yes" ; then
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/5 curses: use wide output functions

In reply to Samuel Thibault

This makes use of cchar_t instead of chtype when using ncursesw, which allows to store a wide char as well as the WACS values.

This also allows to complete the printable glyphs list beyond ascii and the ACS values.

---
 configure            |   5 +-
 hw/display/vga.c     |   4 +-
 include/ui/console.h |  16 ++-
 ui/curses.c          | 321 ++++++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 294 insertions(+), 52 deletions(-)
configure +4 -1
index 29649d9..ebe0599 100755
@@ -2901,14 +2901,17 @@ if test "$curses" != "no" ; then
 #include <locale.h>
 #include <curses.h>
 #include <wchar.h>
+#include <langinfo.h>
 int main(void) {
   const char *s = curses_version();
+  const char *codeset;
   wchar_t wch = L'w';
   setlocale(LC_ALL, "");
   resize_term(0, 0);
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
-  return s != 0;
+  codeset = nl_langinfo(CODESET);
+  return s != 0 && codeset != 0;
 }
 EOF
   IFS=:
hw/display/vga.c +2 -2
index 2a88b3c..ce225c9 100644
@@ -1966,7 +1966,7 @@ static void vga_update_text(void *opaque, console_ch_t *chardata)
 
             for (i = 0; i < size; src ++, dst ++, i ++) {
                 console_write_ch(&val, VMEM2CHTYPE(le32_to_cpu(*src)));
-                if (*dst != val) {
+                if (memcmp(dst, &val, sizeof(val))) {
                     *dst = val;
                     c_max = i;
                     break;
@@ -1975,7 +1975,7 @@ static void vga_update_text(void *opaque, console_ch_t *chardata)
             c_min = i;
             for (; i < size; src ++, dst ++, i ++) {
                 console_write_ch(&val, VMEM2CHTYPE(le32_to_cpu(*src)));
-                if (*dst != val) {
+                if (memcmp(dst, &val, sizeof(val))) {
                     *dst = val;
                     c_max = i;
                 }
include/ui/console.h +10 -6
index d9c13d2..94e3133 100644
@@ -338,8 +338,8 @@ static inline pixman_format_code_t surface_format(DisplaySurface *s)
 
 #ifdef CONFIG_CURSES
 #include <curses.h>
-typedef chtype console_ch_t;
-extern chtype vga_to_curses[];
+typedef cchar_t console_ch_t;
+extern console_ch_t vga_to_curses[];
 #else
 typedef unsigned long console_ch_t;
 #endif
@@ -347,16 +347,20 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 {
     uint8_t c = ch;
 #ifdef CONFIG_CURSES
-    if (vga_to_curses[c]) {
-        ch &= ~(console_ch_t)0xff;
-        ch |= vga_to_curses[c];
+    if (vga_to_curses[c].chars[0]) {
+        *dest = vga_to_curses[c];
+    } else {
+        dest->chars[0] = c;
+        dest->chars[1] = 0;
+        dest->attr = 0;
     }
+    dest->attr |= ch & ~0xff;
 #else
     if (c == '\0') {
         ch |= ' ';
     }
-#endif
     *dest = ch;
+#endif
 }
 
 typedef struct GraphicHwOps {
ui/curses.c +278 -43

351 lines not on this page · raw message

Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/5 curses: add option to specify VGA font encoding

In reply to Samuel Thibault

This detects and uses iconv to convert glyphs from the specified VGA font encoding to unicode.

---
 configure               | 37 +++++++++++++++++++++++++++++++++++++
 include/sysemu/sysemu.h |  1 +
 qemu-options.hx         |  5 ++++-
 ui/curses.c             | 41 +++++++++++++++++++++++++++++++++++++++++
 vl.c                    | 21 ++++++++++++++++++++-
 5 files changed, 103 insertions(+), 2 deletions(-)
configure +37 -0
index ebe0599..2ecd03a 100755
@@ -203,6 +203,7 @@ bluez=""
 brlapi=""
 curl=""
 curses=""
+cursesw=""
 docs=""
 fdt=""
 netmap="no"
@@ -984,6 +985,10 @@ for opt do
   ;;
   --enable-curses) curses="yes"
   ;;
+  --disable-iconv) iconv="no"
+  ;;
+  --enable-iconv) iconv="yes"
+  ;;
   --disable-curl) curl="no"
   ;;
   --enable-curl) curl="yes"
@@ -1351,6 +1356,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   --with-gtkabi     select preferred GTK ABI 2.0 or 3.0
   vte             vte support for the gtk UI
   curses          curses UI
+  iconv           font glyph conversion support
   vnc             VNC UI support
   vnc-sasl        SASL encryption for VNC server
   vnc-jpeg        JPEG lossy compression for VNC server
@@ -2938,6 +2944,33 @@ EOF
 fi
 
 ##########################################
+# iconv probe
+if test "$iconv" != "no" ; then
+  cat > $TMPC << EOF
+#include <iconv.h>
+int main(void) {
+  iconv_t conv = iconv_open("ISO-8859-1", "ISO-8859-1");
+  return conv != (iconv_t) -1;
+}
+EOF
+  for iconv_lib in '' -liconv; do
+    if compile_prog "" "$iconv_lib" ; then
+      iconv_found=yes
+      libs_softmmu="$iconv_lib $libs_softmmu"
+      break
+    fi
+  done
+  if test "$iconv_found" = "yes" ; then
+    iconv=yes
+  else
+    if test "$iconv" = "yes" ; then
+      feature_not_found "iconv" "Install iconv devel"
+    fi
+    iconv=no
+  fi
+fi
+
+##########################################
 # curl probe
 if test "$curl" != "no" ; then
   if $pkg_config libcurl --exists; then
@@ -4860,6 +4893,7 @@ echo "nettle            $nettle $(echo_version $nettle $nettle_version)"
 echo "nettle kdf        $nettle_kdf"
 echo "libtasn1          $tasn1"
 echo "curses support    $curses"
+echo "iconv support     $iconv"
 echo "virgl support     $virglrenderer"
 echo "curl support      $curl"
 echo "mingw32 support   $mingw32"
@@ -5120,6 +5154,9 @@ fi
 if test "$curses" = "yes" ; then
   echo "CONFIG_CURSES=y" >> $config_host_mak
 fi
+if test "$iconv" = "yes" ; then
+  echo "CONFIG_ICONV=y" >> $config_host_mak
+fi
 if test "$utimens" = "yes" ; then
   echo "CONFIG_UTIMENSAT=y" >> $config_host_mak
 fi
include/sysemu/sysemu.h +1 -0
index ee7c760..b90b9b1 100644
@@ -148,6 +148,7 @@ extern int graphic_height;
 extern int graphic_depth;
 extern int display_opengl;
 extern const char *keyboard_layout;
+extern const char *font_charset;
 extern int win2k_install_hack;
 extern int alt_grab;
 extern int ctrl_grab;
qemu-options.hx +4 -1
index 0b621bb..c82a26e 100644
@@ -930,7 +930,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
     "            [,window_close=on|off][,gl=on|off]|curses|none|\n"
     "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n"
     "-display vnc=<display>[,<optargs>]\n"
-    "-display curses\n"
+    "-display curses[,charset=<encoding>]\n"
     "-display none"
     "                select display type\n"
     "The default display is equivalent to\n"
@@ -961,6 +961,9 @@ support a text mode, QEMU can display this output using a
 curses/ncurses interface. Nothing is displayed when the graphics
 device is in graphical mode or if the graphics device does not support
 a text mode. Generally only the VGA device models support text mode.
+The font charset used by the guest can be specified with the
+@code{charset} option, for example @code{charset=CP850} for IBM CP850
+encoding. The default is @code{CP437}.
 @item none
 Do not display video output. The guest will still see an emulated
 graphics card, but its output will not be displayed to the QEMU
ui/curses.c +41 -0

53 lines not on this page · raw message

vl.c +20 -1
index ad2664b..3043132 100644
@@ -132,7 +132,8 @@ const char *bios_name = NULL;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 int request_opengl = -1;
 int display_opengl;
-const char* keyboard_layout = NULL;
+const char *keyboard_layout;
+const char *font_charset;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
@@ -2140,6 +2141,24 @@ static DisplayType select_display(const char *p)
     } else if (strstart(p, "curses", &opts)) {
 #ifdef CONFIG_CURSES
         display = DT_CURSES;
+        while (*opts) {
+            const char *nextopt, *name;
+
+            if (strstart(opts, ",charset=", &name)) {
+                nextopt = strchr(name, ',');
+                if (nextopt) {
+                    font_charset = g_strndup(name, nextopt - name);
+                    nextopt++;
+                } else {
+                    font_charset = g_strdup(name);
+                    nextopt = name + strlen(name);
+                }
+            } else {
+                error_report("invalid curses option string");
+                exit(1);
+            }
+            opts = nextopt;
+        }
 #else
         error_report("curses support is disabled");
         exit(1);
Signature · 1 line
2.9.3
#5 lore raw

Re: [Qemu-devel] [PATCH 4/5] curses: add option to specify VGA font encoding

ui/curses.c static void curses_setup(void) · line 411

Quoted 10 lines
ui/curses.c +9 -0
+#ifdef CONFIG_ICONV
+    if (font_charset) {
+        unsigned char ch;
+        wchar_t wch;
+        char *pch, *pwch;
+        size_t sch, swch;
+        iconv_t conv;
+
+        conv = iconv_open("WCHAR_T", font_charset);

Is this portable? It seems safer to convert to UTF-8 and parse the resulting character (assuming that wchar_t is Unicode). There is already mod_utf8_codepoint for this task.

Paolo

#6 lore raw

Re: [Qemu-devel] [PATCH 4/5] curses: add option to specify VGA font encoding

In reply to Samuel Thibault

Hello,

It seems that in the flurry of qemu-devel mails, I missed this answer.

Quoted 11 lines · Paolo Bonzini

ui/curses.c static void curses_setup(void) · line 411

Quoted 9 lines
ui/curses.c +9 -0
+#ifdef CONFIG_ICONV
+    if (font_charset) {
+        unsigned char ch;
+        wchar_t wch;
+        char *pch, *pwch;
+        size_t sch, swch;
+        iconv_t conv;
+
+        conv = iconv_open("WCHAR_T", font_charset);

Is this portable?

I confirm it works on at least glibc (thus Linux and other GNUs), MacOS, OpenBSD, FreeBSD, Windows mingw.

Samuel

#7 lore raw

PATCH 5/5 curses: support wide input

In reply to Samuel Thibault

This makes use of wide curses functions instead of 8bit functions. This allows to type e.g. accented letters.

Unfortunately, key codes are then returned with values that could be confused with wide characters by ncurses, so we need to add a maybe_keycode variable to know whether the returned value is a key code or a character (wide support), or possibly both (non-wide support).

The translation tables thus also need to be separated into key code translation and character translation. The curses2foo helper makes it easier to use them.

---
 ui/curses.c      |  76 ++++++++++++++++++++++++++++++-------
 ui/curses_keys.h | 113 ++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 127 insertions(+), 62 deletions(-)
ui/curses.c +62 -14
index f839a9d..441cc93 100644
@@ -43,6 +43,12 @@
 #define FONT_HEIGHT 16
 #define FONT_WIDTH 8
 
+enum maybe_keycode {
+    CURSES_KEYCODE,
+    CURSES_CHAR,
+    CURSES_CHAR_OR_KEYCODE,
+};
+
 static DisplayChangeListener *dcl;
 static console_ch_t screen[160 * 100];
 static WINDOW *screenpad = NULL;
@@ -51,6 +57,23 @@ static int px, py, sminx, sminy, smaxx, smaxy;
 
 console_ch_t vga_to_curses[256];
 
+static wint_t console_getch(int *maybe_keycode)
+{
+    wint_t ret;
+    switch (get_wch(&ret)) {
+    case KEY_CODE_YES:
+        *maybe_keycode = CURSES_KEYCODE;
+        break;
+    case OK:
+        *maybe_keycode = CURSES_CHAR;
+        break;
+    case ERR:
+        ret = -1;
+        break;
+    }
+    return ret;
+}
+
 static void curses_update(DisplayChangeListener *dcl,
                           int x, int y, int w, int h)
 {
@@ -186,9 +209,37 @@ static void curses_cursor_position(DisplayChangeListener *dcl,
 
 static kbd_layout_t *kbd_layout = NULL;
 
+static int curses2foo(const int _curses2foo[], const int _curseskey2foo[],
+                      int chr, int maybe_keycode)
+{
+    int ret = -1;
+    if (maybe_keycode == CURSES_CHAR) {
+        if (chr < CURSES_CHARS) {
+            ret = _curses2foo[chr];
+        }
+    } else {
+        if (chr < CURSES_KEYS) {
+            ret = _curseskey2foo[chr];
+        }
+        if (ret == -1 && maybe_keycode == CURSES_CHAR_OR_KEYCODE &&
+            chr < CURSES_CHARS) {
+            ret = _curses2foo[chr];
+        }
+    }
+    return ret;
+}
+
+#define curses2keycode(chr, maybe_keycode) \
+    curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
+#define curses2keysym(chr, maybe_keycode) \
+    curses2foo(_curses2keysym, _curseskey2keysym, chr, maybe_keycode)
+#define curses2qemu(chr, maybe_keycode) \
+    curses2foo(_curses2qemu, _curseskey2qemu, chr, maybe_keycode)
+
 static void curses_refresh(DisplayChangeListener *dcl)
 {
     int chr, keysym, keycode, keycode_alt;
+    int maybe_keycode;
 
     curses_winch_check();
 
@@ -204,14 +255,14 @@ static void curses_refresh(DisplayChangeListener *dcl)
 
     while (1) {
         /* while there are any pending key strokes to process */
-        chr = getch();
+        chr = console_getch(&maybe_keycode);
 
-        if (chr == ERR)
+        if (chr == -1)
             break;
 
 #ifdef KEY_RESIZE
         /* this shouldn't occur when we use a custom SIGWINCH handler */
-        if (chr == KEY_RESIZE) {
+        if (maybe_keycode != 0 && chr == KEY_RESIZE) {
             clear();
             refresh();
             curses_calc_pad();
@@ -220,17 +271,19 @@ static void curses_refresh(DisplayChangeListener *dcl)
         }
 #endif
 
-        keycode = curses2keycode[chr];
+        keycode = curses2keycode(chr, maybe_keycode);
         keycode_alt = 0;
 
         /* alt or esc key */
         if (keycode == 1) {
-            int nextchr = getch();
+            int next_maybe_keycode;
+            int nextchr = console_getch(&next_maybe_keycode);
 
-            if (nextchr != ERR) {
+            if (nextchr != -1) {
                 chr = nextchr;
+                maybe_keycode = next_maybe_keycode;
                 keycode_alt = ALT;
-                keycode = curses2keycode[chr];
+                keycode = curses2keycode(chr, maybe_keycode);
 
                 if (keycode != -1) {
                     keycode |= ALT;
@@ -250,9 +303,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
         }
 
         if (kbd_layout) {
-            keysym = -1;
-            if (chr < CURSES_KEYS)
-                keysym = curses2keysym[chr];
+            keysym = curses2keysym(chr, maybe_keycode);
 
             if (keysym == -1) {
                 if (chr < ' ') {
@@ -317,10 +368,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
                 qemu_input_event_send_key_delay(0);
             }
         } else {
-            keysym = -1;
-            if (chr < CURSES_KEYS) {
-                keysym = curses2qemu[chr];
-            }
+            keysym = curses2qemu(chr, maybe_keycode);
             if (keysym == -1)
                 keysym = chr;
 
ui/curses_keys.h +65 -48

173 lines not on this page · raw message

Signature · 1 line
2.9.3
#8 lore raw
In reply to Samuel Thibault

Hello,

Ping?

Quoted 5 lines · Samuel Thibault, on Sat 15 Oct 2016 21:53:03 +0200, wrote:

This patch series adds wide character support to the curses frontend of qemu, thus allowing to fix a lot of input and output issues with e.g. accented letters and semi-graphic glyphs. Since qemu can't know the encoding of the VGA font, the user has to specify it (just like he has to specify the keyboard layout with -k). I used option -f to make it simple for now, but I welcome any other idea :)

I forgot to mention that I updated the patches according to the reviews on the list (assume cursesw support, and use -display option).

Samuel

Quoted 20 lines

Samuel Thibault (5):
curses: fix left/right arrow translation
curses: Use cursesw instead of curses
curses: use wide output functions
curses: add option to specify VGA font encoding
curses: support wide input

 configure               |  71 ++++++--
 hw/display/vga.c        |   4 +-
 include/sysemu/sysemu.h |   1 +
 include/ui/console.h    |  16 +-
 qemu-options.hx         |   5 +-
 ui/curses.c             | 436 +++++++++++++++++++++++++++++++++++++++++-------
 ui/curses_keys.h        | 113 +++++++------
 vl.c                    |  21 ++-
 8 files changed, 543 insertions(+), 124 deletions(-)
Signature · 1 line
2.9.3
Signature · 5 lines
Samuel
Tu as lu les docs. Tu es devenu un informaticien. Que tu le veuilles
ou non. Lire la doc, c'est le Premier et Unique Commandement de
l'informaticien.
-+- TP in: Guide du Linuxien pervers - "L'évangile selon St Thomas"
#9 lore raw
Quoted 3 lines · Samuel Thibault

Hello,

Ping?

Back online now after being sick for a while.
Sorry for the delay.

Quoted 9 lines
Quoted 5 lines · Samuel Thibault, on Sat 15 Oct 2016 21:53:03 +0200, wrote:

This patch series adds wide character support to the curses frontend of qemu, thus allowing to fix a lot of input and output issues with e.g. accented letters and semi-graphic glyphs. Since qemu can't know the encoding of the VGA font, the user has to specify it (just like he has to specify the keyboard layout with -k). I used option -f to make it simple for now, but I welcome any other idea :)

I forgot to mention that I updated the patches according to the reviews on the list (assume cursesw support, and use -display option).

Good, looks much better now without all the #ifdefs.

/me wonders whenever we should do the same with iconv. It's part of the POSIX.1-2001 specs, and we have 2016 now. Do we *really* need configure checks and #ifdefs for it? Also we could use iconv for the cp437-to-unicode mapping instead of having a hard-coded table for it.

Given how close the freeze deadline is now I'm tempted to cherry-pick patches 0-3 and prepare a pull request ASAP.

cheers,
Gerd

#10 lore raw

Hello,

Quoted 1 line · Gerd Hoffmann, on Wed 26 Oct 2016 12:05:55 +0200, wrote:

Back online now after being sick for a while.

Oh, sorry about that, hoping you're fine.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · Samuel Thibault, on Sat 15 Oct 2016 21:53:03 +0200, wrote:

This patch series adds wide character support to the curses frontend of qemu, thus allowing to fix a lot of input and output issues with e.g. accented letters and semi-graphic glyphs. Since qemu can't know the encoding of the VGA font, the user has to specify it (just like he has to specify the keyboard layout with -k). I used option -f to make it simple for now, but I welcome any other idea :)

Quoted 8 lines
Quoted 2 lines

I forgot to mention that I updated the patches according to the reviews on the list (assume cursesw support, and use -display option).

Good, looks much better now without all the #ifdefs.

/me wonders whenever we should do the same with iconv. It's part of the POSIX.1-2001 specs, and we have 2016 now. Do we *really* need configure checks and #ifdefs for it?

I would only say that libiconv is not always installed by default on BSD systems for instance.

Quoted 2 lines

Also we could use iconv for the cp437-to-unicode mapping instead of having a hard-coded table for it.

Ah, indeed.

Quoted 2 lines

Given how close the freeze deadline is now I'm tempted to cherry-pick patches 0-3 and prepare a pull request ASAP.

You mean patches 1-3? Patch 5 would be very useful too to fix typing accented letters, and it doesn't depend on patch 4.

Thanks,
Samuel

#11 lore raw

Hi,

Quoted 6 lines
Quoted 3 lines

/me wonders whenever we should do the same with iconv. It's part of the POSIX.1-2001 specs, and we have 2016 now. Do we *really* need configure checks and #ifdefs for it?

I would only say that libiconv is not always installed by default on BSD systems for instance.

Hmm, maybe keep the check but disable curses altogether in case iconv isn't there, so we can at least avoid the #ifdefs?

Quoted 2 lines

You mean patches 1-3? Patch 5 would be very useful too to fix typing accented letters, and it doesn't depend on patch 4.

Ok, then I'll go pick #5 too.

cheers,
Gerd

#12 lore raw
In reply to Samuel Thibault

Hi,

Quoted 5 lines
Quoted 2 lines

Given how close the freeze deadline is now I'm tempted to cherry-pick patches 0-3 and prepare a pull request ASAP.

You mean patches 1-3? Patch 5 would be very useful too to fix typing accented letters, and it doesn't depend on patch 4.

Hmm, seems #5 needs a rebase, doesn't apply cleanly. Picked 1-3 now. Current queue is at
http://localhost/cgit/projects/qemu/.git/log/?h=queue/ui

cheers,
Gerd

#13 lore raw
Quoted 7 lines · Gerd Hoffmann, on Wed 26 Oct 2016 14:40:26 +0200, wrote:
Quoted 5 lines
Quoted 2 lines

Given how close the freeze deadline is now I'm tempted to cherry-pick patches 0-3 and prepare a pull request ASAP.

You mean patches 1-3? Patch 5 would be very useful too to fix typing accented letters, and it doesn't depend on patch 4.

Hmm, seems #5 needs a rebase, doesn't apply cleanly.

Here is a patch rebased on current master.

Samuel

commit c230fb0bee630a1a138acce542ba6ed4aabdc232

Author: Samuel Thibault <[email protected]>
Date:   Wed Jun 22 23:41:50 2016 +0200

curses: support wide input

This makes use of wide curses functions instead of 8bit functions. This allows to type e.g. accented letters.

Unfortunately, key codes are then returned with values that could be confused with wide characters by ncurses, so we need to add a maybe_keycode variable to know whether the returned value is a key code or a character (wide support), or possibly both (non-wide support).

The translation tables thus also need to be separated into key code translation and character translation. The curses2foo helper makes it easier to use them.

ui/curses.c +62 -14
index f839a9d..441cc93 100644
@@ -43,6 +43,12 @@
 #define FONT_HEIGHT 16
 #define FONT_WIDTH 8
 
+enum maybe_keycode {
+    CURSES_KEYCODE,
+    CURSES_CHAR,
+    CURSES_CHAR_OR_KEYCODE,
+};
+
 static DisplayChangeListener *dcl;
 static console_ch_t screen[160 * 100];
 static WINDOW *screenpad = NULL;
@@ -51,6 +57,23 @@ static int px, py, sminx, sminy, smaxx, smaxy;
 
 console_ch_t vga_to_curses[256];
 
+static wint_t console_getch(int *maybe_keycode)
+{
+    wint_t ret;
+    switch (get_wch(&ret)) {
+    case KEY_CODE_YES:
+        *maybe_keycode = CURSES_KEYCODE;
+        break;
+    case OK:
+        *maybe_keycode = CURSES_CHAR;
+        break;
+    case ERR:
+        ret = -1;
+        break;
+    }
+    return ret;
+}
+
 static void curses_update(DisplayChangeListener *dcl,
                           int x, int y, int w, int h)
 {
@@ -186,9 +209,37 @@ static void curses_cursor_position(DisplayChangeListener *dcl,
 
 static kbd_layout_t *kbd_layout = NULL;
 
+static int curses2foo(const int _curses2foo[], const int _curseskey2foo[],
+                      int chr, int maybe_keycode)
+{
+    int ret = -1;
+    if (maybe_keycode == CURSES_CHAR) {
+        if (chr < CURSES_CHARS) {
+            ret = _curses2foo[chr];
+        }
+    } else {
+        if (chr < CURSES_KEYS) {
+            ret = _curseskey2foo[chr];
+        }
+        if (ret == -1 && maybe_keycode == CURSES_CHAR_OR_KEYCODE &&
+            chr < CURSES_CHARS) {
+            ret = _curses2foo[chr];
+        }
+    }
+    return ret;
+}
+
+#define curses2keycode(chr, maybe_keycode) \
+    curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
+#define curses2keysym(chr, maybe_keycode) \
+    curses2foo(_curses2keysym, _curseskey2keysym, chr, maybe_keycode)
+#define curses2qemu(chr, maybe_keycode) \
+    curses2foo(_curses2qemu, _curseskey2qemu, chr, maybe_keycode)
+
 static void curses_refresh(DisplayChangeListener *dcl)
 {
     int chr, keysym, keycode, keycode_alt;
+    int maybe_keycode;
 
     curses_winch_check();
 
@@ -204,14 +255,14 @@ static void curses_refresh(DisplayChangeListener *dcl)
 
     while (1) {
         /* while there are any pending key strokes to process */
-        chr = getch();
+        chr = console_getch(&maybe_keycode);
 
-        if (chr == ERR)
+        if (chr == -1)
             break;
 
 #ifdef KEY_RESIZE
         /* this shouldn't occur when we use a custom SIGWINCH handler */
-        if (chr == KEY_RESIZE) {
+        if (maybe_keycode != 0 && chr == KEY_RESIZE) {
             clear();
             refresh();
             curses_calc_pad();
@@ -220,17 +271,19 @@ static void curses_refresh(DisplayChangeListener *dcl)
         }
 #endif
 
-        keycode = curses2keycode[chr];
+        keycode = curses2keycode(chr, maybe_keycode);
         keycode_alt = 0;
 
         /* alt or esc key */
         if (keycode == 1) {
-            int nextchr = getch();
+            int next_maybe_keycode;
+            int nextchr = console_getch(&next_maybe_keycode);
 
-            if (nextchr != ERR) {
+            if (nextchr != -1) {
                 chr = nextchr;
+                maybe_keycode = next_maybe_keycode;
                 keycode_alt = ALT;
-                keycode = curses2keycode[chr];
+                keycode = curses2keycode(chr, maybe_keycode);
 
                 if (keycode != -1) {
                     keycode |= ALT;
@@ -250,9 +303,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
         }
 
         if (kbd_layout) {
-            keysym = -1;
-            if (chr < CURSES_KEYS)
-                keysym = curses2keysym[chr];
+            keysym = curses2keysym(chr, maybe_keycode);
 
             if (keysym == -1) {
                 if (chr < ' ') {
@@ -317,10 +368,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
                 qemu_input_event_send_key_delay(0);
             }
         } else {
-            keysym = -1;
-            if (chr < CURSES_KEYS) {
-                keysym = curses2qemu[chr];
-            }
+            keysym = curses2qemu(chr, maybe_keycode);
             if (keysym == -1)
                 keysym = chr;
 
ui/curses_keys.h +65 -48

173 lines not on this page · raw message