curses: use wide output functions
v2 cover curses: use wide output functions
Hello,
This is a respin of the output part of curses wide output.
- curses has been made to now depend on iconv
- this allowed to just always use iconv, including to convert from the default CP437 encoding.
- this also avoids the problematic usage of L'\uxxxx'.
Samuel Thibault (2):
iconv: detect and make curses depend on it
curses: add option to specify VGA font encoding
configure | 45 ++++++- hw/display/vga.c | 4 +- include/sysemu/sysemu.h | 1 + include/ui/console.h | 16 ++- qemu-options.hx | 5 +- ui/curses.c | 304 ++++++++++++++++++++++++++++++++++++++++-------- vl.c | 23 +++- 7 files changed, 340 insertions(+), 58 deletions(-)
Signature · 1 line
2.10.1
PATCH v2 1/2 iconv: detect and make curses depend on it
curses will use it for proper wide output support.
--- configure | 40 ++++++++++++++++++++++++++++++++++++++++ vl.c | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-)
configure +40 -0
@@ -979,6 +979,10 @@ for opt do ;; --enable-curses) curses="yes" ;; + --disable-iconv) iconv="no" + ;; + --enable-iconv) iconv="yes" + ;; --disable-curl) curl="no" ;; --enable-curl) curl="yes"
@@ -1353,6 +1357,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
@@ -2914,7 +2919,38 @@ EOF fi ########################################## +# iconv probe +if test "$iconv" != "no" ; then + cat > $TMPC << EOF +#include <iconv.h> +int main(void) { + iconv_t conv = iconv_open("WCHAR_T", "UCS-2"); + 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 + +########################################## # curses probe +if test "$iconv" = "no" ; then + # curses will need iconv + curses=no +fi if test "$curses" != "no" ; then if test "$mingw32" = "yes" ; then curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
@@ -4972,6 +5008,7 @@ echo "libgcrypt kdf $gcrypt_kdf" echo "nettle $nettle $(echo_version $nettle $nettle_version)" echo "nettle kdf $nettle_kdf" echo "libtasn1 $tasn1" +echo "iconv support $iconv" echo "curses support $curses" echo "virgl support $virglrenderer" echo "curl support $curl"
@@ -5226,6 +5263,9 @@ fi if test "$cocoa" = "yes" ; then echo "CONFIG_COCOA=y" >> $config_host_mak fi +if test "$iconv" = "yes" ; then + echo "CONFIG_ICONV=y" >> $config_host_mak +fi if test "$curses" = "yes" ; then echo "CONFIG_CURSES=y" >> $config_host_mak fi
vl.c +1 -1
@@ -2185,7 +2185,7 @@ static DisplayType select_display(const char *p)#ifdef CONFIG_CURSES display =DT_CURSES ;#else -error_report ("curses support is disabled" ); +error_report ("curses or iconv support is disabled" );exit (1 );#endif }else if (strstart (p,"gtk" , &opts)) {
Signature · 1 line
2.10.1
PATCH v2 2/2 curses: add option to specify VGA font encoding
In reply to Samuel ThibaultThis uses iconv to convert glyphs from the specified VGA font encoding to unicode, and makes use of cchar_t instead of chtype when using ncursesw, which allows to store all wide char as well as the WACS values.
--- configure | 5 +- hw/display/vga.c | 4 +- include/sysemu/sysemu.h | 1 + include/ui/console.h | 16 ++- qemu-options.hx | 5 +- ui/curses.c | 304 ++++++++++++++++++++++++++++++++++++++++-------- vl.c | 21 +++- 7 files changed, 299 insertions(+), 57 deletions(-)
configure +4 -1
@@ -2964,14 +2964,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
@@ -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/sysemu/sysemu.h +1 -0
@@ -145,6 +145,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;
include/ui/console.h +10 -6
@@ -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 {
qemu-options.hx +4 -1
@@ -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 +258 -46
341 lines not on this page · raw message
vl.c +20 -1
@@ -133,7 +133,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 ="CP437" ;ram_addr_t ram_size;const char *mem_path =NULL ;int mem_prealloc =0 ;/* force preallocation of physical target memory */
@@ -2184,6 +2185,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 or iconv support is disabled" );exit (1 );
Signature · 1 line
2.10.1