Reputation: 33
Example Code :
#include <menu.h>
#include <ncurses.h>
#include <stdlib.h>
#include <wchar.h>
#define ITEM_COUNT 2
int main() {
wchar_t *choices[] = {L"揺らぎ", L"a widecharacter string"};
ITEM **wide_items;
MENU *wide_menu;
initscr();
noecho();
cbreak();
refresh();
wide_items = (ITEM **)calloc(ITEM_COUNT + 1, sizeof(ITEM *));
wide_items[0] = new_item(choices[0], choices[0]);
wide_items[1] = new_item(choices[1], choices[1]);
wide_items[ITEM_COUNT + 1] = NULL;
wide_menu = new_menu(wide_items);
refresh();
getwchar();
free_item(wide_items[1]);
free_item(wide_items[0]);
free(wide_items);
free_menu(wide_menu);
endwin();
return 0;
}
I'm getting the following errors on compilation though:
wide_menu.c: In function ‘main’:
wide_menu.c:21:35: error: passing argument 1 of ‘new_item’ from incompatible pointer type [-Wincompatible-pointer-types]
21 | wide_items[0] = new_item(choices[0], choices[0]);
| ~~~~~~~^~~
| |
| wchar_t * {aka int *}
In file included from wide_menu.c:1:
/usr/include/menu.h:199:39: note: expected ‘const char *’ but argument is of type ‘wchar_t *’ {aka ‘int *’}
199 | extern MENU_EXPORT(ITEM *) new_item(const char *, const char *);
| ^~~~~~~~~~~~
wide_menu.c:21:47: error: passing argument 2 of ‘new_item’ from incompatible pointer type [-Wincompatible-pointer-types]
21 | wide_items[0] = new_item(choices[0], choices[0]);
| ~~~~~~~^~~
| |
| wchar_t * {aka int *}
/usr/include/menu.h:199:53: note: expected ‘const char *’ but argument is of type ‘wchar_t *’ {aka ‘int *’}
199 | extern MENU_EXPORT(ITEM *) new_item(const char *, const char *);
| ^~~~~~~~~~~~
wide_menu.c:22:35: error: passing argument 1 of ‘new_item’ from incompatible pointer type [-Wincompatible-pointer-types]
22 | wide_items[1] = new_item(choices[1], choices[1]);
| ~~~~~~~^~~
| |
| wchar_t * {aka int *}
/usr/include/menu.h:199:39: note: expected ‘const char *’ but argument is of type ‘wchar_t *’ {aka ‘int *’}
199 | extern MENU_EXPORT(ITEM *) new_item(const char *, const char *);
| ^~~~~~~~~~~~
wide_menu.c:22:47: error: passing argument 2 of ‘new_item’ from incompatible pointer type [-Wincompatible-pointer-types]
22 | wide_items[1] = new_item(choices[1], choices[1]);
| ~~~~~~~^~~
| |
| wchar_t * {aka int *}
/usr/include/menu.h:199:53: note: expected ‘const char *’ but argument is of type ‘wchar_t *’ {aka ‘int *’}
199 | extern MENU_EXPORT(ITEM *) new_item(const char *, const char *);
The compile command being used:
gcc wide_menu.c -lncursesw -lmenuw
I'm currently on an arch linux system where the ncurses file packages both ncurses and ncursesw so I don't think its a file inclusion issue
My question is, is there a separate function that for creating menus that stores wide character pointers in the item, or is it not possible at all? If there are no special wide character functions, then is there an alternate way to have a menu support wide characters?
Upvotes: 1
Views: 50
Reputation: 67476
Using wide-character strings with ncurses involves leveraging the wide-character functions provided by the ncursesw
(wide-character-enabled ncurses) library.
ncurses
provides a set of functions for working with wide-character strings.
Some examples:
addwstr()
: Print a wide-character string.mvaddwstr()
: Move to a position and print a wide-character string.waddwstr()
: Add a wide-character string to a window.add_wch()
: Print a single wide character.mvadd_wch()
: Move to a position and print a single wide character.Upvotes: 0