diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2019-04-27 20:33:07 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-05-17 13:21:40 +0200 |
commit | 962cf8fd4faefb2d5f425abc5c988ea7ba2bbce9 (patch) | |
tree | ea59ff9831b169f7892f7ed7f81eb64d7113f0e7 /ui/curses.c | |
parent | b7b664a4fe9a955338f2e11a0f7433b29c8cbad0 (diff) | |
download | qemu-962cf8fd4faefb2d5f425abc5c988ea7ba2bbce9.zip qemu-962cf8fd4faefb2d5f425abc5c988ea7ba2bbce9.tar.gz qemu-962cf8fd4faefb2d5f425abc5c988ea7ba2bbce9.tar.bz2 |
ui/curses: manipulate cchar_t with standard curses functions
The chars/attr fields are curses internals, setcchar and getcchar have
to be used instead.
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Tested-by: Kamil Rytarowski <n54@gmx.com>
Message-Id: <20190427183307.12796-3-samuel.thibault@ens-lyon.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/curses.c')
-rw-r--r-- | ui/curses.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/ui/curses.c b/ui/curses.c index 81d4198..1f3fcab 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -66,20 +66,22 @@ static void curses_update(DisplayChangeListener *dcl, { console_ch_t *line; cchar_t curses_line[width]; + wchar_t wch[CCHARW_MAX]; + attr_t attrs; + short colors; + int ret; line = screen + y * width; for (h += y; y < h; y ++, line += width) { for (x = 0; x < width; x++) { chtype ch = line[x] & 0xff; chtype at = line[x] & ~0xff; - if (vga_to_curses[ch].chars[0]) { - curses_line[x] = vga_to_curses[ch]; - } else { - curses_line[x] = (cchar_t) { - .chars[0] = ch, - }; + ret = getcchar(&vga_to_curses[ch], wch, &attrs, &colors, NULL); + if (ret == ERR || wch[0] == 0) { + wch[0] = ch; + wch[1] = 0; } - curses_line[x].attr |= at; + setcchar(&curses_line[x], wch, at, 0, NULL); } mvwadd_wchnstr(screenpad, y, 0, curses_line, width); } @@ -412,7 +414,7 @@ static void curses_atexit(void) static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv) { char mbch[MB_LEN_MAX]; - wchar_t wch; + wchar_t wch[2]; char *puch, *pmbch; size_t such, smbch; mbstate_t ps; @@ -430,20 +432,22 @@ static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv) } memset(&ps, 0, sizeof(ps)); - if (mbrtowc(&wch, mbch, sizeof(mbch) - smbch, &ps) == -1) { + if (mbrtowc(&wch[0], mbch, sizeof(mbch) - smbch, &ps) == -1) { fprintf(stderr, "Could not convert 0x%04x " "from a multibyte character to wchar_t: %s\n", uch, strerror(errno)); return; } - vga_to_curses[fch].chars[0] = wch; + + wch[1] = 0; + setcchar(&vga_to_curses[fch], wch, 0, 0, NULL); } /* Setup wchar glyph for one font character */ static void convert_font(unsigned char fch, iconv_t conv) { char mbch[MB_LEN_MAX]; - wchar_t wch; + wchar_t wch[2]; char *pfch, *pmbch; size_t sfch, smbch; mbstate_t ps; @@ -461,13 +465,15 @@ static void convert_font(unsigned char fch, iconv_t conv) } memset(&ps, 0, sizeof(ps)); - if (mbrtowc(&wch, mbch, sizeof(mbch) - smbch, &ps) == -1) { + if (mbrtowc(&wch[0], mbch, sizeof(mbch) - smbch, &ps) == -1) { fprintf(stderr, "Could not convert font glyph 0x%02x " "from a multibyte character to wchar_t: %s\n", fch, strerror(errno)); return; } - vga_to_curses[fch].chars[0] = wch; + + wch[1] = 0; + setcchar(&vga_to_curses[fch], wch, 0, 0, NULL); } /* Convert one wchar to UCS-2 */ @@ -592,7 +598,16 @@ static void font_setup(void) if (strcmp(nl_langinfo(CODESET), "UTF-8")) { /* Non-Unicode capable, use termcap equivalents for those available */ for (i = 0; i <= 0xFF; i++) { - switch (get_ucs(vga_to_curses[i].chars[0], nativecharset_to_ucs2)) { + wchar_t wch[CCHARW_MAX]; + attr_t attr; + short color; + int ret; + + ret = getcchar(&vga_to_curses[i], wch, &attr, &color, NULL); + if (ret == ERR) + continue; + + switch (get_ucs(wch[0], nativecharset_to_ucs2)) { case 0x00a3: vga_to_curses[i] = *WACS_STERLING; break; |