C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
mkcc.c File Reference

Go to the source code of this file.

Functions

cchar_t mkcc (short cp, attr_t attr, const char *s)
 Create a cchar_t with the specified color pair index and attributes.

Function Documentation

◆ mkcc()

cchar_t mkcc ( short cp,
attr_t attr,
const char * s )

Create a cchar_t with the specified color pair index and attributes.

mkcc

Parameters
cpColor pair index
attrAttributes to apply to the cchar_t
sMultibyte string to convert to wide character (only the first character is used)
Returns
cchar_t with the specified color pair index and a space character as the wide character

Definition at line 11 of file mkcc.c.

11 {
12 mbstate_t mbstate;
13 memset(&mbstate, 0, sizeof(mbstate));
14 size_t len;
15 size_t n;
16 cchar_t cc = {0};
17 wchar_t wstr[2] = {L'\0', L'\0'};
18 len = strlen(s);
19 if (len > 0) {
20 n = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
21 if (n <= 0) {
22 wstr[0] = L'?';
23 wstr[1] = L'\0';
24 } else {
25 wstr[1] = L'\0';
26 }
27 } else {
28 wstr[0] = L' ';
29 wstr[1] = L'\0';
30 }
31 ui_setcchar(&cc, wstr, attr, cp, nullptr);
32 return cc;
33}
int ui_setcchar(UiCell *wch, const wchar_t *wc, const attr_t attrs, short pair, const void *opts)