curses: Add support for wide output
cover curses: Add support for wide output
Hello,
This adds support for wide output in the curses frontend
Samuel Thibault (2):
iconv: detect and make curses depend on it
curses: add option to specify VGA font encoding
configure | 45 ++++++- qapi/ui.json | 4 +- qemu-options.hx | 5 +- ui/curses.c | 315 ++++++++++++++++++++++++++++++++++++++++-------- vl.c | 2 +- 5 files changed, 320 insertions(+), 51 deletions(-)
Signature · 1 line
2.20.1
PATCH 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
@@ -1217,6 +1217,10 @@ for opt do ;; --enable-curses) curses="yes" ;; + --disable-iconv) iconv="no" + ;; + --enable-iconv) iconv="yes" + ;; --disable-curl) curl="no" ;; --enable-curl) curl="yes"
@@ -1718,6 +1722,7 @@ disabled with --disable-FEATURE, default is enabled if available: gtk gtk UI 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
@@ -3398,8 +3403,39 @@ EOF fi 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):"
@@ -6111,6 +6147,7 @@ echo "libgcrypt $gcrypt" echo "nettle $nettle $(echo_version $nettle $nettle_version)" echo "libtasn1 $tasn1" echo "PAM $auth_pam" +echo "iconv support $iconv" echo "curses support $curses" echo "virgl support $virglrenderer $(echo_version $virglrenderer $virgl_version)" echo "curl support $curl"
@@ -6435,6 +6472,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=m" >> $config_host_mak echo "CURSES_CFLAGS=$curses_inc" >> $config_host_mak
vl.c +1 -1
@@ -3171,7 +3171,7 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_CURSES dpy.type =DISPLAY_TYPE_CURSES ;#else -error_report ("curses support is disabled" ); +error_report ("curses or iconv support is disabled" );exit (1 );#endif break ;
Signature · 1 line
2.20.1
PATCH 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 +- qapi/ui.json | 4 +- qemu-options.hx | 5 +- ui/curses.c | 315 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 279 insertions(+), 50 deletions(-)
configure +4 -1
@@ -3449,14 +3449,17 @@ if test "$curses" != "no" ; then #include <locale.h> #include <curses.h> #include <wchar.h> +#include <langinfo.h> int main(void) { + const char *codeset; wchar_t wch = L'w'; setlocale(LC_ALL, ""); resize_term(0, 0); addwstr(L"wide chars\n"); addnwstr(&wch, 1); add_wch(WACS_DEGREE); - return 0; + codeset = nl_langinfo(CODESET); + return codeset != 0; } EOF IFS=:
qapi/ui.json +3 -1
@@ -1131,6 +1131,7 @@ # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). # @gl: Enable OpenGL support (default: off). +# @charset: Font charset used by guest (default: CP437). # # Since: 2.12 #
@@ -1139,7 +1140,8 @@ 'base' : { 'type' : 'DisplayType', '*full-screen' : 'bool', '*window-close' : 'bool', - '*gl' : 'DisplayGLMode' }, + '*gl' : 'DisplayGLMode', + '*charset' : 'str' }, 'discriminator' : 'type', 'data' : { 'gtk' : 'DisplayGTK', 'egl-headless' : 'DisplayEGLHeadless'} }
qemu-options.hx +4 -1
@@ -1216,7 +1216,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, " [,window_close=on|off][,gl=on|core|es|off]\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\n" "-display egl-headless[,rendernode=<file>]" " select display type\n"
@@ -1248,6 +1248,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 +268 -47
359 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Quoted 41 lines · Samuel Thibault
This uses iconv to convert glyphs from the specified VGA font encoding to unicode, and makes use of
cchar_tinstead of chtype when using ncursesw, which allows to store all wide char as well as the WACS values.Signed-off-by Samuel Thibault <[email protected]>Cc Eddie Kohler <[email protected]>--- configure | 5 +- qapi/ui.json | 4 +- qemu-options.hx | 5 +- ui/curses.c | 315 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 279 insertions(+), 50 deletions(-)configure +4
-1@@ -3449,14 +3449,17 @@ if test "$curses" != "no" ; then #include <locale.h> #include <curses.h> #include <wchar.h> +#include <langinfo.h> int main(void) { + const char *codeset; wchar_t wch = L'w'; setlocale(LC_ALL, ""); resize_term(0, 0); addwstr(L"wide chars\n"); addnwstr(&wch, 1); add_wch(WACS_DEGREE); - return 0; + codeset = nl_langinfo(CODESET); + return codeset != 0; } EOF IFS=:qapi/ui.json +0
-0
qapi/ui.json line 1134
Quoted 4 lines
qapi/ui.json +1
-0@@ -1131,6 +1131,7 @@ # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). # @gl: Enable OpenGL support (default: off). +# @charset: Font charset used by guest (default: CP437).
Can you give brief rationale for defaulting to CP437?
Quoted 40 lines
qapi/ui.json +2
-1# # Since: 2.12 #@@ -1139,7 +1140,8 @@ 'base' : { 'type' : 'DisplayType', '*full-screen' : 'bool', '*window-close' : 'bool', - '*gl' : 'DisplayGLMode' }, + '*gl' : 'DisplayGLMode', + '*charset' : 'str' }, 'discriminator' : 'type', 'data' : { 'gtk' : 'DisplayGTK', 'egl-headless' : 'DisplayEGLHeadless'} }qemu-options.hx +4
-1@@ -1216,7 +1216,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, " [,window_close=on|off][,gl=on|core|es|off]\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\n" "-display egl-headless[,rendernode=<file>]" " select display type\n"@@ -1248,6 +1248,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 QEMUui/curses.c +0
-0
[...]
ui/curses.c static void curses_display_init(DisplayState *ds, DisplayOptions *opts) · line 712
Quoted 5 lines
ui/curses.c +1
-0@@ -492,6 +709,10 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts) }#endif +setlocale (LC_CTYPE ,"" );
General principles: any change to locale deserves prominent mention in the commit message.
Quoted 6 lines
ui/curses.c +3
-0+if (opts->charset) { + font_charset = opts->charset; + }curses_setup ();curses_keyboard_setup ();atexit (curses_atexit);
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Markus Armbruster, le lun. 04 mars 2019 07:44:34 +0100, a ecrit:
Quoted 10 lines
qapi/ui.json line 1134
Quoted 7 lines · Samuel Thibault
qapi/ui.json +1
-0@@ -1131,6 +1131,7 @@ # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). # @gl: Enable OpenGL support (default: off). +# @charset: Font charset used by guest (default: CP437).Can you give brief rationale for defaulting to CP437?
I have added to the commit message:
“
The default charset is made CP437 since that is the charset of the hardware default VGA font.
”
Quoted 8 lines
qapi/ui.json static void curses_display_init(DisplayState *ds, DisplayOptions *opts) · line 712
Quoted 5 lines
qapi/ui.json +1
-0@@ -492,6 +709,10 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts) } #endif + setlocale(LC_CTYPE, "");General principles: any change to locale deserves prominent mention in the commit message.
I have added to the commit message:
“
This also makes the curses backend set the LC_CTYPE locale to "" to allow curses to emit wide characters.
”
Samuel
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Quoted 28 lines · Samuel Thibault
Markus Armbruster, le lun. 04 mars 2019 07:44:34 +0100, a ecrit:
Quoted 10 lines
qapi/ui.json line 1134
Quoted 7 lines · Samuel Thibault
qapi/ui.json +1
-0@@ -1131,6 +1131,7 @@ # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). # @gl: Enable OpenGL support (default: off). +# @charset: Font charset used by guest (default: CP437).Can you give brief rationale for defaulting to CP437?
I have added to the commit message:
“
The default charset is made CP437 since that is the charset of the hardware default VGA font.
”Quoted 8 lines
qapi/ui.json static void curses_display_init(DisplayState *ds, DisplayOptions *opts) · line 712
Quoted 5 lines
qapi/ui.json +1
-0@@ -492,6 +709,10 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts) } #endif + setlocale(LC_CTYPE, "");General principles: any change to locale deserves prominent mention in the commit message.
Quoted 6 lines
I have added to the commit message:
“
This also makes the curses backend set theLC_CTYPElocale to "" to allow curses to emit wide characters.
”
Your commit message amendments work for me. Thanks!
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
In reply to Samuel ThibaultQuoted 6 lines · Samuel Thibault
This uses iconv to convert glyphs from the specified VGA font encoding to unicode, and makes use of
cchar_tinstead of chtype when using ncursesw, which allows to store all wide char as well as the WACS values.Signed-off-by Samuel Thibault <[email protected]>Cc Eddie Kohler <[email protected]>
So the difference to the patch from Eddie is that charset is configurable instead of being hard-coded to CP437?
qapi/ui.json line 1144
Quoted 9 lines
qapi/ui.json +3
-1+# @charset: Font charset used by guest (default: CP437).@@ -1139,7 +1140,8 @@ 'base' : { 'type' : 'DisplayType', '*full-screen' : 'bool', '*window-close' : 'bool', - '*gl' : 'DisplayGLMode' }, + '*gl' : 'DisplayGLMode', + '*charset' : 'str' },
No. Please add a new DisplayCurses struct for the charset option. It will only be used by the curses UI and it is highly unlikely that this will ever change as only curses needs this (the graphical UIs will just use whatever font the guest loaded into the vga).
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Gerd Hoffmann, le lun. 04 mars 2019 09:03:38 +0100, a ecrit:
Quoted 10 lines · Samuel Thibault
Quoted 6 lines
This uses iconv to convert glyphs from the specified VGA font encoding to unicode, and makes use of
cchar_tinstead of chtype when using ncursesw, which allows to store all wide char as well as the WACS values.Signed-off-by Samuel Thibault <[email protected]>Cc Eddie Kohler <[email protected]>So the difference to the patch from Eddie is that charset is configurable instead of being hard-coded to CP437?
Yes.
Samuel
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Another difference is that Samuel's patch supports platforms on which wchar_t is not Unicode.
I don't know if there are many/any such platforms but it does support them!
Quoted 18 lines · Samuel Thibault
Gerd Hoffmann, le lun. 04 mars 2019 09:03:38 +0100, a ecrit:
Quoted 2 lines · Samuel Thibault
Quoted 1 line
This uses iconv to convert glyphs from the specified VGA font encoding
to
Quoted 1 line
Quoted 1 line
unicode, and makes use of
cchar_tinstead of chtype when usingncursesw,
Quoted 7 lines
Quoted 4 lines
which allows to store all wide char as well as the WACS values.
Signed-off-by Samuel Thibault <[email protected]>Cc Eddie Kohler <[email protected]>So the difference to the patch from Eddie is that charset is configurable instead of being hard-coded to CP437?
Yes.
Samuel
Re: [Qemu-devel] [PATCH 2/2] curses: add option to specify VGA font encoding
Quoted 4 lines · Eddie Kohler
Another difference is that Samuel's patch supports platforms on which
wchar_tis not Unicode.I don't know if there are many/any such platforms but it does support them!
I know Cygwin is such a platform, and suspect that mingw is too (although I didn't actually check) - in general, Windows picked wchar_t to be 2 bytes, which is incompatible with full Unicode support requiring 4-byte wchar_t, and hence explaining why C11 introduced char16_t and char32_t to work around the legacy mess that wchar_t causes.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org