C-Menu
0.2.9
A User Interface Toolkit
Toggle main menu visibility
Loading...
Searching...
No Matches
nccell.c
Go to the documentation of this file.
1
#
include
<
locale
.
h
>
2
3
#
define
_XOPEN_SOURCE_EXTENDED
1
4
#
define
__USE_XOPEN
1
5
#
include
<
notcurses
/
notcurses
.
h
>
6
#
include
<
stdlib
.
h
>
7
#
include
<
string
.
h
>
8
#
include
<
unistd
.
h
>
9
#
include
<
wchar
.
h
>
10
11
size_t
ui_nccells_from_text
(
struct
ncplane *stdn,
const
char
*text,
struct
nccell
*cell);
12
13
int
main
() {
14
size_t count = 0;
15
setlocale(LC_ALL,
""
);
16
struct
notcurses_options opts = {0};
17
struct
notcurses *nc = notcurses_init(&opts, stdout);
18
if
(!nc)
19
return
1;
20
struct
ncplane *stdn = notcurses_stdplane(nc);
21
const
char
*text =
"Hi!"
;
22
23
size_t len = strlen(text);
24
struct
nccell
*cell_buf = calloc(len,
sizeof
(
struct
nccell
));
25
count =
ui_nccells_from_text
(
stdn
,
text
,
cell_buf
)
;
26
27
for
(size_t i = 0; i < count; i++) {
28
ncplane_putc(stdn, &cell_buf[i]);
29
nccell_release(stdn, &cell_buf[i]);
30
}
31
notcurses_render(nc);
32
free(cell_buf);
33
notcurses_stop(nc);
34
return
0;
35
}
36
37
size_t
ui_nccells_from_text
(
struct
ncplane *stdn,
const
char
*text,
struct
nccell
*cell_buf) {
38
uint64_t channels = 0;
39
ncchannels_set_fg_rgb8(&channels, 255, 255, 0);
// Yellow
40
size_t count = 0;
41
const
char
*p = text;
42
while
(*p) {
43
nccell_init(&cell_buf[count]);
44
int
bytes = nccell_load(stdn, &cell_buf[count], p);
45
if
(bytes < 0)
46
break
;
47
nccell_set_styles(&cell_buf[count], NCSTYLE_NONE);
48
nccell_set_channels(&cell_buf[count], channels);
49
p += bytes;
50
count++;
51
}
52
return
count;
53
}
ui_nccells_from_text
size_t ui_nccells_from_text(struct ncplane *stdn, const char *text, struct nccell *cell)
Definition
egc.c:37
main
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.
Definition
amort.c:30
nccell
Definition
nccell.h:3
ui
nccell.c
Generated by
1.17.0