1YASCREEN(3)                       User-Manual                      YASCREEN(3)
2
3
4

NAME

6       yascreen  -  Yet Another Screen Library (curses replacement for daemons
7       and embedded apps)
8
9
10

SYNOPSIS

12       #include <yascreen.h>
13
14
15

DESCRIPTION

Main features

18              • small footprint
19
20              • does not have external dependencies
21
22              • allows both internal and external event loop
23
24              • allows stdin/stdout or external input/output  (can  work  over
25                socket)
26
27              • supports basic set of telnet sequences, making it suitable for
28                built-in terminal interfaces for daemons
29
30              • supports a limited set of input keystroke sequences
31
32              • fully unicode compatible (parts of this depend on  wcwidth  in
33                libc)
34
35              • supports utf8 verification of input
36
37              • supports utf8 input and wide character input
38
39              • supports non-utf8 input mode
40
41              • relies  only  on a limited subset of ansi/xterm ESC sequences,
42                making it compatible with mostly  all  modern  terminals  (in‐
43                spired by linenoise ⟨https://github.com/antirez/linenoise⟩)
44
45              • there  is  no  curses  API and ancient terminal compatibility,
46                hence less bloat
47
48              • there is no autoconf - there is no need to have one
49
50              • clean API with opaque private data, usable from C/C++
51
52              • easy cross compilation setup (by setting  CC,  AR,  STRIP  and
53                RANLIB)
54
55
56
57       Current  development is done on Linux, with additional testing on Open‐
58       BSD/FreeBSD; other platforms may need minimal fixes.
59
60
61       On *BSD a gmake is required to build.
62
63

Architecture

65       yascreen uses an opaque data structure, allocated by  the  library  and
66       dynamically  resized  when  needed  -  yascreen_init(int  sx, int sy) /
67       yascreen_resize(yascreen *s, int sx, int sy). An application may  spec‐
68       ify (0,0) for both calls to let yascreen detect the size or use a fixed
69       size.
70
71
72       There are two modes of operation - telnet protocol over socket or  run‐
73       ning in terminal. For sockets the event loop would typically be handled
74       outside of the library while for terminals a built-in event loop may be
75       used.
76
77
78       Modes of operation can be modified at runtime.
79
80
81       For terminal use signal handling (SIGWINCH) should always be handled by
82       the application.
83
84

Example initialization for terminal and handling of SIGWINCH

86              yascreen *s;
87              int winch=0;
88
89              void sigwinch(int sign) {
90                   winch=1;
91              }
92
93              s=yascreen_init(0,0); // let yascreen get term size
94              yascreen_term_set(s,YAS_NOBUFF|YAS_NOSIGN|YAS_NOECHO);
95              signal(SIGWINCH,sigwinch);
96
97              for (;;) { // main loop
98                   if (winch) {
99                        winch=0;
100                        if (yascreen_resize(s,0,0))
101                             // handle a fatal error - no memory
102                        // get the new sizes and redraw
103                        newsizex=yascreen_sx(s);
104                        newsizey=yascreen_sy(s);
105                   }
106
107
108                   // option 1
109
110                   // input is handled in external event loop and fed to yascreen via yascreen_feed
111                   if (FD_ISSET(STDIN_FILENO,&r)&&sizeof c==read(STDIN_FILENO,&c,sizeof c))
112                        yascreen_feed(s,c); // pump state machine with bytestream
113
114                   // keys are processed only when available without delay/blocking
115                   while ((ch=yascreen_getch_nowait(s))!=-1) {
116                        // handle processed keys
117                   }
118
119
120                   // option 2
121
122                   // input is handled by yascreen and key or -1 is returned not longer than TIMEOUT ms
123                   // note: if screen update is based on this, keypresses will force it
124                   while ((ch=yascreen_getch_to(s,TIMEOUT))!=-1) {
125                        // handle processed keys
126                   }
127
128
129                   // option 3
130
131                   // input is handled by yascreen and the following call will block until a key is pressed
132                   if ((ch=yascreen_getch(s))!=-1) {
133                        // handle processed key
134                   }
135              }
136
137
138
139       For sockets input is handled like option 1 in  the  example  above  and
140       yascreen needs to be provided with a callback for output.
141
142
143       In  multiprocess  mode  daemons  where stdin/stdout are redirected to a
144       socket the same model from the example above  can  be  used.  Obviously
145       SIGWINCH  will  work only for terminals and for sockets the screen size
146       can get to be known either via telnet or ASNI sequences.
147
148

Example initialization for socket with external event loop and telnet se‐

150       quences processing
151              yascreen *s;
152
153              s=yascreen_init(80,25); // there is no guarantee that screen size detection is supported on the remote end
154              yascreen_setout(s,output_cb); // set callback for output
155              yascreen_set_telnet(s,1); // enable processing of telnet sequences
156              yascreen_init_telnet(s); // try to negotiate telnet options (regardless if telnet processing is enabled)
157              yascreen_reqsize(s); // request initial screen size
158              for (;;) { // main loop
159
160                   yascreen_feed(s,c); // feed input from the socket to yascreen
161
162                   // keys are processed only when available without delay/blocking
163                   while ((ch=yascreen_getch_nowait(s))!=-1) {
164                        // handle processed keys
165
166                        // screen size change is reported as a special keypress code:
167                        if (ch==YAS_TELNET_SIZE||ch==YAS_SCREEN_SIZE) // screen size change reported via telnet or ANSI sequence
168                             // redraw
169                   }
170              }
171
172
173
174
175

API Reference

Predefined constants and Helper macros

178       Internally  style is kept into bitfields in a single integer variable -
179       that includes  foreground/background  colors,  style  modifiers  (bold,
180       italic, underline, inverse and blink.
181
182
183   Style codes
184       ┌────────────┬───────────┐
185Name        Function  
186       ├────────────┼───────────┤
187YAS_ITALIC  │ italic    │
188       ├────────────┼───────────┤
189YAS_UNDERL  │ underline │
190       ├────────────┼───────────┤
191YAS_STRIKE  │ stikeout  │
192       ├────────────┼───────────┤
193YAS_INVERSE │ inverse   │
194       ├────────────┼───────────┤
195YAS_BOLD    │ bold      │
196       ├────────────┼───────────┤
197YAS_BLINK   │ blink     │
198       └────────────┴───────────┘
199
200   Color codes
201       ┌───────────────┬─────────────────────────────┐
202Name           Color                       
203       ├───────────────┼─────────────────────────────┤
204YAS_BLACK      │ black                       │
205       ├───────────────┼─────────────────────────────┤
206YAS_RED        │ red                         │
207       ├───────────────┼─────────────────────────────┤
208YAS_GREEN      │ green                       │
209       ├───────────────┼─────────────────────────────┤
210YAS_YELLOW     │ yellow                      │
211       ├───────────────┼─────────────────────────────┤
212YAS_BLUE       │ blue                        │
213       ├───────────────┼─────────────────────────────┤
214YAS_MAGENTA    │ magenta                     │
215       ├───────────────┼─────────────────────────────┤
216YAS_CYAN       │ cyan                        │
217       ├───────────────┼─────────────────────────────┤
218YAS_WHITE      │ white                       │
219       ├───────────────┼─────────────────────────────┤
220YAS_FGCOLORDEF │ default terminal foreground │
221       ├───────────────┼─────────────────────────────┤
222YAS_BGCOLORDEF │ default terminal background │
223       └───────────────┴─────────────────────────────┘
224
225   Helper macros
226       ┌────────────────────┬────────────────────────────┐
227Name                Description                
228       ├────────────────────┼────────────────────────────┤
229YAS_FG(attribute)   │ extract foreground color   │
230       ├────────────────────┼────────────────────────────┤
231YAS_BG(attribute)   │ extract background color   │
232       ├────────────────────┼────────────────────────────┤
233YAS_FGCOLOR(color)  │ shift  simple  color value │
234       │                    │ into foreground color      │
235       ├────────────────────┼────────────────────────────┤
236YAS_BGCOLOR(color)  │ shift simple  color  value │
237       │                    │ into background color      │
238       ├────────────────────┼────────────────────────────┤
239YAS_FGXCOLOR(color) │ shift  256  palette  color │
240       │                    │ value   into    foreground │
241       │                    │ color                      │
242       ├────────────────────┼────────────────────────────┤
243YAS_BGXCOLOR(color) │ shift  256  palette  color │
244       │                    │ value   into    background │
245       │                    │ color                      │
246       └────────────────────┴────────────────────────────┘
247
248       All  of  the  above can be or'ed into attribute, provided that the bits
249       for foreground/background color are all zeroes.
250
251
252   Key codes
253              • Special, generated internally
254
255
256
257       Previous versions of the library used -1 and 0x100+ for these codes. In
258       order  to achieve unicode wide character compatibility and simpler API,
259       the reserved Unicode range 0xf0000-0xffffd  is  used  for  the  special
260       codes both in narrow and wide character input modes.
261
262
263       There is a macro YAS_IS_CC(code) that will evaluate to non-zero for the
264       special codes and to zero for normal characters. Note  that  all  ASCII
265       control characters in the range 0x00-0x7f are treated as normal ones.
266
267
268       ┌────────────────┬─────────┬─────────────────────┐
269Name            Value   Description         
270       ├────────────────┼─────────┼─────────────────────┤
271YAS_K_NONE      │ 0xf0000 │ no  key  is  avail‐ │
272       │                │         │ able; in time  lim‐ │
273       │                │         │ ited   mode   means │
274       │                │         │ that the time limit │
275       │                │         │ expired             │
276       ├────────────────┼─────────┼─────────────────────┤
277YAS_SCREEN_SIZE │ 0xf0701 │ notification    for │
278       │                │         │ screen size  change │
279       │                │         │ (may  come  because │
280       │                │         │ of telnet  or  ANSI │
281       │                │         │ sequence)           │
282       ├────────────────┼─────────┼─────────────────────┤
283YAS_TELNET_SIZE │ 0xf0702 │ notification    for │
284       │                │         │ screen size change; │
285       │                │         │ duplicates      the │
286       │                │         │ above, may be  used │
287       │                │         │ to    differentiate │
288       │                │         │ how   screen   size │
289       │                │         │ change   event  was │
290       │                │         │ generated           │
291       └────────────────┴─────────┴─────────────────────┘
292
293              • Normal keys
294
295
296
297       ┌─────────────┬───────┬───────────────────────────────┐
298Name         Value Description                   
299       ├─────────────┼───────┼───────────────────────────────┤
300YAS_K_NUL    │ 0x00  │ Nul; on some terminals Ctrl-2 │
301       ├─────────────┼───────┼───────────────────────────────┤
302YAS_K_C_A    │ 0x01  │ Ctrl-A                        │
303       ├─────────────┼───────┼───────────────────────────────┤
304YAS_K_C_B    │ 0x02  │ Ctrl-B                        │
305       ├─────────────┼───────┼───────────────────────────────┤
306YAS_K_C_C    │ 0x03  │ Ctrl-C                        │
307       ├─────────────┼───────┼───────────────────────────────┤
308YAS_K_C_D    │ 0x04  │ Ctrl-D                        │
309       ├─────────────┼───────┼───────────────────────────────┤
310YAS_K_C_E    │ 0x05  │ Ctrl-E                        │
311       ├─────────────┼───────┼───────────────────────────────┤
312YAS_K_C_F    │ 0x06  │ Ctrl-F                        │
313       ├─────────────┼───────┼───────────────────────────────┤
314YAS_K_C_G    │ 0x07  │ Ctrl-G                        │
315       ├─────────────┼───────┼───────────────────────────────┤
316YAS_K_C_H    │ 0x08  │ Ctrl-H; depends  on  terminal │
317       │             │       │ see YAS-K-BSP and YAS-K-C-8   │
318       ├─────────────┼───────┼───────────────────────────────┤
319YAS_K_C_I    │ 0x09  │ Ctrl-I                        │
320       ├─────────────┼───────┼───────────────────────────────┤
321YAS_K_TAB    │ 0x09  │ Tab                           │
322       ├─────────────┼───────┼───────────────────────────────┤
323YAS_K_C_J    │ 0x0a  │ Ctrl-J                        │
324       ├─────────────┼───────┼───────────────────────────────┤
325YAS_K_C_K    │ 0x0b  │ Ctrl-K                        │
326       ├─────────────┼───────┼───────────────────────────────┤
327YAS_K_C_L    │ 0x0c  │ Ctrl-L                        │
328       ├─────────────┼───────┼───────────────────────────────┤
329YAS_K_C_M    │ 0x0d  │ Enter,  Return,  Ctrl-M;  see │
330       │             │       │ below                         │
331       ├─────────────┼───────┼───────────────────────────────┤
332YAS_K_RET    │ 0x0d  │ Enter,  Return,  Ctrl-M;  see │
333       │             │       │ above                         │
334       ├─────────────┼───────┼───────────────────────────────┤
335YAS_K_C_N    │ 0x0e  │ Ctrl-N                        │
336       ├─────────────┼───────┼───────────────────────────────┤
337YAS_K_C_O    │ 0x0f  │ Ctrl-O                        │
338       ├─────────────┼───────┼───────────────────────────────┤
339YAS_K_C_P    │ 0x10  │ Ctrl-O                        │
340       ├─────────────┼───────┼───────────────────────────────┤
341YAS_K_C_Q    │ 0x11  │ Ctrl-Q                        │
342       ├─────────────┼───────┼───────────────────────────────┤
343YAS_K_C_R    │ 0x12  │ Ctrl-R                        │
344       ├─────────────┼───────┼───────────────────────────────┤
345YAS_K_C_S    │ 0x13  │ Ctrl-S                        │
346       ├─────────────┼───────┼───────────────────────────────┤
347YAS_K_C_T    │ 0x14  │ Ctrl-T                        │
348       ├─────────────┼───────┼───────────────────────────────┤
349YAS_K_C_U    │ 0x15  │ Ctrl-U                        │
350       ├─────────────┼───────┼───────────────────────────────┤
351YAS_K_C_V    │ 0x16  │ Ctrl-V                        │
352       ├─────────────┼───────┼───────────────────────────────┤
353YAS_K_C_W    │ 0x17  │ Ctrl-W                        │
354       ├─────────────┼───────┼───────────────────────────────┤
355YAS_K_C_X    │ 0x18  │ Ctrl-X                        │
356       ├─────────────┼───────┼───────────────────────────────┤
357YAS_K_C_Y    │ 0x19  │ Ctrl-Y                        │
358       ├─────────────┼───────┼───────────────────────────────┤
359YAS_K_C_Z    │ 0x1a  │ Ctrl-Z                        │
360       ├─────────────┼───────┼───────────────────────────────┤
361YAS_K_ESC    │ 0x1b  │ Esc,  Ctrl-3;  see below; All │
362       │             │       │ ANSI  sequences  start   with │
363       │             │       │ Esc, this is returned after a │
364       │             │       │ timeout or double Esc         │
365       ├─────────────┼───────┼───────────────────────────────┤
366YAS_K_C_3    │ 0x1b  │ Esc, Ctrl-3; see  above;  All │
367       │             │       │ ANSI   sequences  start  with │
368       │             │       │ Esc, this is returned after a │
369       │             │       │ timeout or double Esc         │
370       ├─────────────┼───────┼───────────────────────────────┤
371YAS_K_C_4    │ 0x1c  │ Ctrl-4                        │
372       ├─────────────┼───────┼───────────────────────────────┤
373YAS_K_C_5    │ 0x1d  │ Ctrl-5                        │
374       ├─────────────┼───────┼───────────────────────────────┤
375YAS_K_C_6    │ 0x1e  │ Ctrl-6                        │
376       ├─────────────┼───────┼───────────────────────────────┤
377YAS_K_C_7    │ 0x1f  │ Ctrl-7                        │
378       ├─────────────┼───────┼───────────────────────────────┤
379YAS_K_SPACE  │ 0x20  │ Space                         │
380       ├─────────────┼───────┼───────────────────────────────┤
381YAS_K_EXCL   │ 0x21  │ !                             │
382       ├─────────────┼───────┼───────────────────────────────┤
383YAS_K_DQUOT  │ 0x22  │ "                             │
384       ├─────────────┼───────┼───────────────────────────────┤
385YAS_K_HASH   │ 0x23  │ #                             │
386       ├─────────────┼───────┼───────────────────────────────┤
387YAS_K_POUND  │ 0x24  │ $                             │
388       ├─────────────┼───────┼───────────────────────────────┤
389YAS_K_PERC   │ 0x25  │ %                             │
390       ├─────────────┼───────┼───────────────────────────────┤
391YAS_K_AND    │ 0x26  │ Ampersand                     │
392       ├─────────────┼───────┼───────────────────────────────┤
393YAS_K_QUOT   │ 0x27  │ '                             │
394       ├─────────────┼───────┼───────────────────────────────┤
395YAS_K_OBRA   │ 0x28  │ (                             │
396       ├─────────────┼───────┼───────────────────────────────┤
397YAS_K_CBRA   │ 0x29  │ )                             │
398       ├─────────────┼───────┼───────────────────────────────┤
399YAS_K_STAR   │ 0x2a  │ *                             │
400       ├─────────────┼───────┼───────────────────────────────┤
401YAS_K_PLUS   │ 0x2b  │ +                             │
402       ├─────────────┼───────┼───────────────────────────────┤
403YAS_K_COMMA  │ 0x2c  │ ,                             │
404       ├─────────────┼───────┼───────────────────────────────┤
405YAS_K_MINUS  │ 0x2d  │ -                             │
406       ├─────────────┼───────┼───────────────────────────────┤
407YAS_K_DOT    │ 0x2e  │ .                             │
408       ├─────────────┼───────┼───────────────────────────────┤
409YAS_K_SLASH  │ 0x2f  │ /                             │
410       ├─────────────┼───────┼───────────────────────────────┤
411YAS_K_0      │ 0x30  │ 0                             │
412       ├─────────────┼───────┼───────────────────────────────┤
413YAS_K_1      │ 0x31  │ 1                             │
414       ├─────────────┼───────┼───────────────────────────────┤
415YAS_K_2      │ 0x32  │ 2                             │
416       ├─────────────┼───────┼───────────────────────────────┤
417YAS_K_3      │ 0x33  │ 3                             │
418       ├─────────────┼───────┼───────────────────────────────┤
419YAS_K_4      │ 0x34  │ 4                             │
420       ├─────────────┼───────┼───────────────────────────────┤
421YAS_K_5      │ 0x35  │ 5                             │
422       ├─────────────┼───────┼───────────────────────────────┤
423YAS_K_6      │ 0x36  │ 6                             │
424       ├─────────────┼───────┼───────────────────────────────┤
425YAS_K_7      │ 0x37  │ 7                             │
426       ├─────────────┼───────┼───────────────────────────────┤
427YAS_K_8      │ 0x38  │ 8                             │
428       ├─────────────┼───────┼───────────────────────────────┤
429YAS_K_9      │ 0x39  │ 9                             │
430       ├─────────────┼───────┼───────────────────────────────┤
431YAS_K_COLON  │ 0x3a  │ :                             │
432       ├─────────────┼───────┼───────────────────────────────┤
433YAS_K_SEMI   │ 0x3b  │ ;                             │
434       ├─────────────┼───────┼───────────────────────────────┤
435YAS_K_LT     │ 0x3c  │ <                             │
436       ├─────────────┼───────┼───────────────────────────────┤
437YAS_K_EQ     │ 0x3d  │ Equal                         │
438       ├─────────────┼───────┼───────────────────────────────┤
439YAS_K_GT     │ 0x3e  │ >                             │
440       ├─────────────┼───────┼───────────────────────────────┤
441YAS_K_QUEST  │ 0x3f  │ ?                             │
442       ├─────────────┼───────┼───────────────────────────────┤
443YAS_K_AT     │ 0x40  │ @                             │
444       ├─────────────┼───────┼───────────────────────────────┤
445YAS_K_A      │ 0x41  │ A                             │
446       ├─────────────┼───────┼───────────────────────────────┤
447YAS_K_B      │ 0x42  │ B                             │
448       ├─────────────┼───────┼───────────────────────────────┤
449YAS_K_C      │ 0x43  │ C                             │
450       ├─────────────┼───────┼───────────────────────────────┤
451YAS_K_D      │ 0x44  │ D                             │
452       ├─────────────┼───────┼───────────────────────────────┤
453YAS_K_E      │ 0x45  │ E                             │
454       ├─────────────┼───────┼───────────────────────────────┤
455YAS_K_F      │ 0x46  │ F                             │
456       ├─────────────┼───────┼───────────────────────────────┤
457YAS_K_G      │ 0x47  │ G                             │
458       ├─────────────┼───────┼───────────────────────────────┤
459YAS_K_H      │ 0x48  │ H                             │
460       ├─────────────┼───────┼───────────────────────────────┤
461YAS_K_I      │ 0x49  │ I                             │
462       ├─────────────┼───────┼───────────────────────────────┤
463YAS_K_J      │ 0x4a  │ J                             │
464       ├─────────────┼───────┼───────────────────────────────┤
465YAS_K_K      │ 0x4b  │ K                             │
466       ├─────────────┼───────┼───────────────────────────────┤
467YAS_K_L      │ 0x4c  │ L                             │
468       ├─────────────┼───────┼───────────────────────────────┤
469YAS_K_M      │ 0x4d  │ M                             │
470       ├─────────────┼───────┼───────────────────────────────┤
471YAS_K_N      │ 0x4e  │ N                             │
472       ├─────────────┼───────┼───────────────────────────────┤
473YAS_K_O      │ 0x4f  │ O                             │
474       ├─────────────┼───────┼───────────────────────────────┤
475YAS_K_P      │ 0x50  │ P                             │
476       ├─────────────┼───────┼───────────────────────────────┤
477YAS_K_Q      │ 0x51  │ Q                             │
478       ├─────────────┼───────┼───────────────────────────────┤
479YAS_K_R      │ 0x52  │ R                             │
480       ├─────────────┼───────┼───────────────────────────────┤
481YAS_K_S      │ 0x53  │ S                             │
482       ├─────────────┼───────┼───────────────────────────────┤
483YAS_K_T      │ 0x54  │ T                             │
484       ├─────────────┼───────┼───────────────────────────────┤
485YAS_K_U      │ 0x55  │ U                             │
486       ├─────────────┼───────┼───────────────────────────────┤
487YAS_K_V      │ 0x56  │ V                             │
488       ├─────────────┼───────┼───────────────────────────────┤
489YAS_K_W      │ 0x57  │ W                             │
490       ├─────────────┼───────┼───────────────────────────────┤
491YAS_K_X      │ 0x58  │ X                             │
492       ├─────────────┼───────┼───────────────────────────────┤
493YAS_K_Y      │ 0x59  │ Y                             │
494       ├─────────────┼───────┼───────────────────────────────┤
495YAS_K_Z      │ 0x5a  │ Z                             │
496       ├─────────────┼───────┼───────────────────────────────┤
497YAS_K_OSQ    │ 0x5b  │ OpenSquareBracket             │
498       ├─────────────┼───────┼───────────────────────────────┤
499YAS_K_BSLASH │ 0x5c  │ Backslash                     │
500       ├─────────────┼───────┼───────────────────────────────┤
501YAS_K_CSQ    │ 0x5d  │ CloseSquareBracket            │
502       ├─────────────┼───────┼───────────────────────────────┤
503YAS_K_CARRET │ 0x5e  │ ^                             │
504       ├─────────────┼───────┼───────────────────────────────┤
505YAS_K_USCORE │ 0x5f  │ Underscore                    │
506       ├─────────────┼───────┼───────────────────────────────┤
507YAS_K_BTICK  │ 0x60  │ Backtick                      │
508       ├─────────────┼───────┼───────────────────────────────┤
509YAS_K_a      │ 0x61  │ a                             │
510       ├─────────────┼───────┼───────────────────────────────┤
511YAS_K_b      │ 0x62  │ b                             │
512       ├─────────────┼───────┼───────────────────────────────┤
513YAS_K_c      │ 0x63  │ c                             │
514       ├─────────────┼───────┼───────────────────────────────┤
515YAS_K_d      │ 0x64  │ d                             │
516       ├─────────────┼───────┼───────────────────────────────┤
517YAS_K_e      │ 0x65  │ e                             │
518       ├─────────────┼───────┼───────────────────────────────┤
519YAS_K_f      │ 0x66  │ f                             │
520       ├─────────────┼───────┼───────────────────────────────┤
521YAS_K_g      │ 0x67  │ g                             │
522       ├─────────────┼───────┼───────────────────────────────┤
523YAS_K_h      │ 0x68  │ h                             │
524       ├─────────────┼───────┼───────────────────────────────┤
525YAS_K_i      │ 0x69  │ i                             │
526       ├─────────────┼───────┼───────────────────────────────┤
527YAS_K_j      │ 0x6a  │ j                             │
528       ├─────────────┼───────┼───────────────────────────────┤
529YAS_K_k      │ 0x6b  │ k                             │
530       ├─────────────┼───────┼───────────────────────────────┤
531YAS_K_l      │ 0x6c  │ l                             │
532       ├─────────────┼───────┼───────────────────────────────┤
533YAS_K_m      │ 0x6d  │ m                             │
534       ├─────────────┼───────┼───────────────────────────────┤
535YAS_K_n      │ 0x6e  │ n                             │
536       ├─────────────┼───────┼───────────────────────────────┤
537YAS_K_o      │ 0x6f  │ o                             │
538       ├─────────────┼───────┼───────────────────────────────┤
539YAS_K_p      │ 0x70  │ p                             │
540       ├─────────────┼───────┼───────────────────────────────┤
541YAS_K_q      │ 0x71  │ q                             │
542       ├─────────────┼───────┼───────────────────────────────┤
543YAS_K_r      │ 0x72  │ r                             │
544       ├─────────────┼───────┼───────────────────────────────┤
545YAS_K_s      │ 0x73  │ s                             │
546       ├─────────────┼───────┼───────────────────────────────┤
547YAS_K_t      │ 0x74  │ t                             │
548       ├─────────────┼───────┼───────────────────────────────┤
549YAS_K_u      │ 0x75  │ u                             │
550       ├─────────────┼───────┼───────────────────────────────┤
551YAS_K_v      │ 0x76  │ v                             │
552       ├─────────────┼───────┼───────────────────────────────┤
553YAS_K_w      │ 0x77  │ w                             │
554       ├─────────────┼───────┼───────────────────────────────┤
555YAS_K_x      │ 0x78  │ x                             │
556       ├─────────────┼───────┼───────────────────────────────┤
557YAS_K_y      │ 0x79  │ y                             │
558       ├─────────────┼───────┼───────────────────────────────┤
559YAS_K_z      │ 0x7a  │ z                             │
560       ├─────────────┼───────┼───────────────────────────────┤
561YAS_K_OCUR   │ 0x7b  │ {                             │
562       ├─────────────┼───────┼───────────────────────────────┤
563YAS_K_PIPE   │ 0x7c  │ Pipe                          │
564       ├─────────────┼───────┼───────────────────────────────┤
565YAS_K_CCUR   │ 0x7d  │ }                             │
566       ├─────────────┼───────┼───────────────────────────────┤
567YAS_K_TLD    │ 0x7e  │ Tilde                         │
568       ├─────────────┼───────┼───────────────────────────────┤
569YAS_K_C_8    │ 0x7f  │ Backspace; see below; depends │
570       │             │       │ on terminal see YAS-K-C-H     │
571       ├─────────────┼───────┼───────────────────────────────┤
572YAS_K_BSP    │ 0x7f  │ Backspace; see below; depends │
573       │             │       │ on terminal see YAS-K-C-H     │
574       └─────────────┴───────┴───────────────────────────────┘
575
576              • Extended keys, parsed from ANSI sequences
577
578
579
580       ┌──────────────┬─────────┬─────────────┐
581Name          Value   Description 
582       ├──────────────┼─────────┼─────────────┤
583YAS_K_F1      │ 0xf0001 │ F1          │
584       ├──────────────┼─────────┼─────────────┤
585YAS_K_F2      │ 0xf0002 │ F2          │
586       ├──────────────┼─────────┼─────────────┤
587YAS_K_F3      │ 0xf0003 │ F3          │
588       ├──────────────┼─────────┼─────────────┤
589YAS_K_F4      │ 0xf0004 │ F4          │
590       ├──────────────┼─────────┼─────────────┤
591YAS_K_F5      │ 0xf0005 │ F5          │
592       ├──────────────┼─────────┼─────────────┤
593YAS_K_F6      │ 0xf0006 │ F6          │
594       ├──────────────┼─────────┼─────────────┤
595YAS_K_F7      │ 0xf0007 │ F7          │
596       ├──────────────┼─────────┼─────────────┤
597YAS_K_F8      │ 0xf0008 │ F8          │
598       ├──────────────┼─────────┼─────────────┤
599YAS_K_F9      │ 0xf0009 │ F9          │
600       ├──────────────┼─────────┼─────────────┤
601YAS_K_F10     │ 0xf000a │ F10         │
602       ├──────────────┼─────────┼─────────────┤
603YAS_K_F11     │ 0xf000b │ F11         │
604       ├──────────────┼─────────┼─────────────┤
605YAS_K_F12     │ 0xf000c │ F12         │
606       ├──────────────┼─────────┼─────────────┤
607YAS_K_S_F1    │ 0xf000d │ Shift-F1    │
608       ├──────────────┼─────────┼─────────────┤
609YAS_K_S_F2    │ 0xf000e │ Shift-F2    │
610       ├──────────────┼─────────┼─────────────┤
611YAS_K_S_F3    │ 0xf000f │ Shift-F3    │
612       ├──────────────┼─────────┼─────────────┤
613YAS_K_S_F4    │ 0xf0010 │ Shift-F4    │
614       ├──────────────┼─────────┼─────────────┤
615YAS_K_S_F5    │ 0xf0011 │ Shift-F5    │
616       ├──────────────┼─────────┼─────────────┤
617YAS_K_S_F6    │ 0xf0012 │ Shift-F6    │
618       ├──────────────┼─────────┼─────────────┤
619YAS_K_S_F7    │ 0xf0013 │ Shift-F7    │
620       ├──────────────┼─────────┼─────────────┤
621YAS_K_S_F8    │ 0xf0014 │ Shift-F8    │
622       ├──────────────┼─────────┼─────────────┤
623YAS_K_S_F9    │ 0xf0015 │ Shift-F9    │
624       ├──────────────┼─────────┼─────────────┤
625YAS_K_S_F10   │ 0xf0016 │ Shift-F10   │
626       ├──────────────┼─────────┼─────────────┤
627YAS_K_S_F11   │ 0xf0017 │ Shift-F11   │
628       ├──────────────┼─────────┼─────────────┤
629YAS_K_S_F12   │ 0xf0018 │ Shift-F12   │
630       ├──────────────┼─────────┼─────────────┤
631YAS_K_C_F1    │ 0xf0019 │ Ctrl-F1     │
632       ├──────────────┼─────────┼─────────────┤
633YAS_K_C_F2    │ 0xf001a │ Ctrl-F2     │
634       ├──────────────┼─────────┼─────────────┤
635YAS_K_C_F3    │ 0xf001b │ Ctrl-F3     │
636       ├──────────────┼─────────┼─────────────┤
637YAS_K_C_F4    │ 0xf001c │ Ctrl-F4     │
638       ├──────────────┼─────────┼─────────────┤
639YAS_K_C_F5    │ 0xf001d │ Ctrl-F5     │
640       ├──────────────┼─────────┼─────────────┤
641YAS_K_C_F6    │ 0xf001e │ Ctrl-F6     │
642       ├──────────────┼─────────┼─────────────┤
643YAS_K_C_F7    │ 0xf001f │ Ctrl-F7     │
644       ├──────────────┼─────────┼─────────────┤
645YAS_K_C_F8    │ 0xf0020 │ Ctrl-F8     │
646       ├──────────────┼─────────┼─────────────┤
647YAS_K_C_F9    │ 0xf0021 │ Ctrl-F9     │
648       ├──────────────┼─────────┼─────────────┤
649YAS_K_C_F10   │ 0xf0022 │ Ctrl-F10    │
650       ├──────────────┼─────────┼─────────────┤
651YAS_K_C_F11   │ 0xf0023 │ Ctrl-F11    │
652       ├──────────────┼─────────┼─────────────┤
653YAS_K_C_F12   │ 0xf0024 │ Ctrl-F12    │
654       ├──────────────┼─────────┼─────────────┤
655YAS_K_A_F1    │ 0xf0025 │ Alt-F1      │
656       ├──────────────┼─────────┼─────────────┤
657YAS_K_A_F2    │ 0xf0026 │ Alt-F2      │
658       ├──────────────┼─────────┼─────────────┤
659YAS_K_A_F3    │ 0xf0027 │ Alt-F3      │
660       ├──────────────┼─────────┼─────────────┤
661YAS_K_A_F4    │ 0xf0028 │ Alt-F4      │
662       ├──────────────┼─────────┼─────────────┤
663YAS_K_A_F5    │ 0xf0029 │ Alt-F5      │
664       ├──────────────┼─────────┼─────────────┤
665YAS_K_A_F6    │ 0xf002a │ Alt-F6      │
666       ├──────────────┼─────────┼─────────────┤
667YAS_K_A_F7    │ 0xf002b │ Alt-F7      │
668       ├──────────────┼─────────┼─────────────┤
669YAS_K_A_F8    │ 0xf002c │ Alt-F8      │
670       ├──────────────┼─────────┼─────────────┤
671YAS_K_A_F9    │ 0xf002d │ Alt-F9      │
672       ├──────────────┼─────────┼─────────────┤
673YAS_K_A_F10   │ 0xf002e │ Alt-F10     │
674       ├──────────────┼─────────┼─────────────┤
675YAS_K_A_F11   │ 0xf002f │ Alt-F11     │
676       ├──────────────┼─────────┼─────────────┤
677YAS_K_A_F12   │ 0xf0030 │ Alt-F12     │
678       ├──────────────┼─────────┼─────────────┤
679YAS_K_LEFT    │ 0xf0031 │ Left        │
680       ├──────────────┼─────────┼─────────────┤
681YAS_K_UP      │ 0xf0032 │ Up          │
682       ├──────────────┼─────────┼─────────────┤
683YAS_K_DOWN    │ 0xf0033 │ Down        │
684       ├──────────────┼─────────┼─────────────┤
685YAS_K_RIGHT   │ 0xf0034 │ Right       │
686       ├──────────────┼─────────┼─────────────┤
687YAS_K_HOME    │ 0xf0035 │ Home        │
688       ├──────────────┼─────────┼─────────────┤
689YAS_K_END     │ 0xf0036 │ End         │
690       ├──────────────┼─────────┼─────────────┤
691YAS_K_PGUP    │ 0xf0037 │ PageUp      │
692       ├──────────────┼─────────┼─────────────┤
693YAS_K_PGDN    │ 0xf0038 │ PageDown    │
694       ├──────────────┼─────────┼─────────────┤
695YAS_K_INS     │ 0xf0039 │ Insert      │
696       ├──────────────┼─────────┼─────────────┤
697YAS_K_DEL     │ 0xf003a │ Delete      │
698       ├──────────────┼─────────┼─────────────┤
699YAS_K_C_LEFT  │ 0xf003b │ Ctrl-Left   │
700       ├──────────────┼─────────┼─────────────┤
701YAS_K_C_UP    │ 0xf003c │ Ctrl-Up     │
702       ├──────────────┼─────────┼─────────────┤
703YAS_K_C_DOWN  │ 0xf003d │ Ctrl-Down   │
704       ├──────────────┼─────────┼─────────────┤
705YAS_K_C_RIGHT │ 0xf003e │ Ctrl-Right  │
706       ├──────────────┼─────────┼─────────────┤
707YAS_K_S_LEFT  │ 0xf003f │ Shift-Left  │
708       ├──────────────┼─────────┼─────────────┤
709YAS_K_S_UP    │ 0xf0040 │ Shift-Up    │
710       ├──────────────┼─────────┼─────────────┤
711YAS_K_S_DOWN  │ 0xf0041 │ Shift-Down  │
712       ├──────────────┼─────────┼─────────────┤
713YAS_K_S_RIGHT │ 0xf0042 │ Shift-Right │
714       └──────────────┴─────────┴─────────────┘
715
716              • Alt-<letter>
717
718
719
720       These codes are generated by a helper macro - YAS_K_ALT(keycode).
721
722
723       ┌───────────────┬───────────────┐
724Name           Description   
725       ├───────────────┼───────────────┤
726YAS_K_A_BT     │ Alt-Backtick  │
727       ├───────────────┼───────────────┤
728YAS_K_A_1      │ Alt-1         │
729       ├───────────────┼───────────────┤
730YAS_K_A_2      │ Alt-2         │
731       ├───────────────┼───────────────┤
732YAS_K_A_3      │ Alt-3         │
733       ├───────────────┼───────────────┤
734YAS_K_A_4      │ Alt-4         │
735       ├───────────────┼───────────────┤
736YAS_K_A_5      │ Alt-5         │
737       ├───────────────┼───────────────┤
738YAS_K_A_6      │ Alt-6         │
739       ├───────────────┼───────────────┤
740YAS_K_A_7      │ Alt-7         │
741       ├───────────────┼───────────────┤
742YAS_K_A_8      │ Alt-8         │
743       ├───────────────┼───────────────┤
744YAS_K_A_9      │ Alt-9         │
745       ├───────────────┼───────────────┤
746YAS_K_A_0      │ Alt-0         │
747       ├───────────────┼───────────────┤
748YAS_K_A_MINUS  │ Alt-Minus     │
749       ├───────────────┼───────────────┤
750YAS_K_A_EQ     │ Alt-=         │
751       ├───────────────┼───────────────┤
752YAS_K_A_BSP    │ Alt-Backspace │
753       ├───────────────┼───────────────┤
754YAS_K_A_TLD    │ Alt-Tilde     │
755       ├───────────────┼───────────────┤
756YAS_K_A_EXCL   │ Alt-!         │
757       ├───────────────┼───────────────┤
758YAS_K_A_AT     │ Alt-@         │
759       ├───────────────┼───────────────┤
760YAS_K_A_HASH   │ Alt-#         │
761       ├───────────────┼───────────────┤
762YAS_K_A_POUND  │ Alt-$         │
763       ├───────────────┼───────────────┤
764YAS_K_A_PERC   │ Alt-%         │
765       ├───────────────┼───────────────┤
766YAS_K_A_CARRET │ Alt-^         │
767       ├───────────────┼───────────────┤
768YAS_K_A_AND    │ Alt-Ampersand │
769       ├───────────────┼───────────────┤
770YAS_K_A_STAR   │ Alt-Star      │
771       ├───────────────┼───────────────┤
772YAS_K_A_OBRA   │ Alt-(         │
773       ├───────────────┼───────────────┤
774YAS_K_A_CBRA   │ Alt-)         │
775       ├───────────────┼───────────────┤
776YAS_K_A_UND    │ Alt-_         │
777       ├───────────────┼───────────────┤
778YAS_K_A_PLUS   │ Alt-+         │
779       ├───────────────┼───────────────┤
780YAS_K_A_a      │ Alt-a         │
781       ├───────────────┼───────────────┤
782YAS_K_A_b      │ Alt-b         │
783       ├───────────────┼───────────────┤
784YAS_K_A_c      │ Alt-c         │
785       ├───────────────┼───────────────┤
786YAS_K_A_d      │ Alt-d         │
787       ├───────────────┼───────────────┤
788YAS_K_A_e      │ Alt-e         │
789       ├───────────────┼───────────────┤
790YAS_K_A_f      │ Alt-f         │
791       ├───────────────┼───────────────┤
792YAS_K_A_g      │ Alt-g         │
793       ├───────────────┼───────────────┤
794YAS_K_A_h      │ Alt-h         │
795       ├───────────────┼───────────────┤
796YAS_K_A_i      │ Alt-i         │
797       ├───────────────┼───────────────┤
798YAS_K_A_j      │ Alt-j         │
799       ├───────────────┼───────────────┤
800YAS_K_A_k      │ Alt-k         │
801       ├───────────────┼───────────────┤
802YAS_K_A_l      │ Alt-l         │
803       ├───────────────┼───────────────┤
804YAS_K_A_m      │ Alt-m         │
805       ├───────────────┼───────────────┤
806YAS_K_A_n      │ Alt-n         │
807       ├───────────────┼───────────────┤
808YAS_K_A_o      │ Alt-o         │
809       ├───────────────┼───────────────┤
810YAS_K_A_p      │ Alt-p         │
811       ├───────────────┼───────────────┤
812YAS_K_A_q      │ Alt-q         │
813       ├───────────────┼───────────────┤
814YAS_K_A_r      │ Alt-r         │
815       ├───────────────┼───────────────┤
816YAS_K_A_s      │ Alt-s         │
817       ├───────────────┼───────────────┤
818YAS_K_A_t      │ Alt-t         │
819       ├───────────────┼───────────────┤
820YAS_K_A_u      │ Alt-u         │
821       ├───────────────┼───────────────┤
822YAS_K_A_v      │ Alt-v         │
823       ├───────────────┼───────────────┤
824YAS_K_A_w      │ Alt-w         │
825       ├───────────────┼───────────────┤
826YAS_K_A_x      │ Alt-x         │
827       ├───────────────┼───────────────┤
828YAS_K_A_y      │ Alt-y         │
829       ├───────────────┼───────────────┤
830YAS_K_A_z      │ Alt-z         │
831       └───────────────┴───────────────┘
832

Functions

834       All  functions  in  the  API  work with a pointer to an opaque yascreen
835       structure.
836
837
838       The structure is allocated internally in the library  by  yascreen_init
839       and it is the job of the user program to keep track of it.
840
841
842       The  library  is thread safe, as long as each struct yascreen object is
843       accessed by a single thread.
844
845
846   yascreen_init
847              inline yascreen *yascreen_init(int sx,int sy);
848
849
850
851       allocate and initialize screen data
852
853
854       output defaults to stdout
855
856
857       in case output is a terminal and initial size is (0,0), the screen size
858       is autodetected
859
860
861       in case of error, returns NULL
862
863
864   yascreen_ver
865              inline const char *yascreen_ver(void);
866
867
868
869       returns a string with the library version
870
871
872   yascreen_setout
873              inline int yascreen_setout(yascreen *s,ssize_t (*out)(yascreen *s,const void *data,size_t len));
874
875
876
877       set callback that handles output
878
879
880       if out=NULL, the output goes to stdout
881
882
883       the  callback may implement internal buffering, a flush is signalled by
884       calling out with len=0
885
886
887   yascreen_set_unicode
888              inline void yascreen_set_unicode(yascreen *s,int on);
889
890
891
892       enable (on is non-zero) or disable (on=0) unicode input processing
893
894
895       by default unicode mode is on
896
897
898       changing the unicode input processing will flush all pending input
899
900
901   yascreen_set_telnet
902              inline void yascreen_set_telnet(yascreen *s,int on);
903
904
905
906       enable (on is non-zero) or disable (on=0) telnet sequence processing
907
908
909       by default telnet mode is off
910
911
912   yascreen_init_telnet
913              inline void yascreen_init_telnet(yascreen *s);
914
915
916
917       depending on telnet sequence processing, sends a set of telnet initial‐
918       ization sequences
919
920
921   yascreen_resize
922              inline int yascreen_resize(yascreen *s,int sx,int sy);
923
924
925
926       resize screen
927
928
929       should redraw afterwards
930
931
932       since allocation is involved, this may fail and return -1
933
934
935   yascreen_free
936              inline void yascreen_free(yascreen *s);
937
938
939
940       finish the lifecycle of struct yascreen - all internally allocated mem‐
941       ory is freed
942
943
944   yascreen_term_save
945              inline void yascreen_term_save(yascreen *s);
946
947
948
949       save current terminal state on top of state stack
950
951
952   yascreen_term_restore
953              inline void yascreen_term_restore(yascreen *s);
954
955
956
957       restore previously saved terminal state from top of state stack
958
959
960   yascreen_term_push
961              inline void yascreen_term_push(yascreen *s);
962
963
964
965       push current terminal state to state stack
966
967
968   yascreen_term_pop
969              inline void yascreen_term_pop(yascreen *s);
970
971
972
973       pop and restore previously saved terminal state from state stack
974
975
976   yascreen_term_set
977              inline void yascreen_term_set(yascreen *s,int mode);
978
979
980
981       set terminal for proper screen operation
982
983
984   mode is a bitmask, containing one of
985       ┌───────────┬───────┬───────────────────────────┐
986Name       Value Description               
987       ├───────────┼───────┼───────────────────────────┤
988YAS_NOBUFF │ 1     │ turn off  canonical  mode │
989       │           │       │ (disable  ICANON and IEX‐ │
990       │           │       │ TEN)                      │
991       ├───────────┼───────┼───────────────────────────┤
992YAS_NOSIGN │ 2     │ disable ISIG              │
993       ├───────────┼───────┼───────────────────────────┤
994YAS_NOECHO │ 4     │ disable local echo (ECHO) │
995       ├───────────┼───────┼───────────────────────────┤
996YAS_ONLCR  │ 8     │ ONLCR or OPOST            │
997       └───────────┴───────┴───────────────────────────┘
998
999   yascreen_printxy
1000              inline int yascreen_printxy(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6)));
1001
1002
1003
1004   yascreen_putsxy
1005              inline int yascreen_putsxy(yascreen *s,int x,int y,uint32_t attr,const char *str);
1006
1007
1008
1009       print at position, if data exceeds buffer, then it gets truncated
1010
1011
1012   yascreen_printxyu
1013              inline int yascreen_printxyu(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6)));
1014
1015
1016
1017   yascreen_putsxyu
1018              inline int yascreen_putsxyu(yascreen *s,int x,int y,uint32_t attr,const char *str);
1019
1020
1021
1022       print at position, if data exceeds buffer, then it gets truncated
1023
1024
1025       screen is immediately updated
1026
1027
1028   yascreen_update
1029              inline int yascreen_update(yascreen *s);
1030
1031
1032
1033       sync memory state to screen
1034
1035
1036       since allocation is involved, this may fail and return -1
1037
1038
1039   yascreen_redraw
1040              inline void yascreen_redraw(yascreen *s);
1041
1042
1043
1044       set next update to be a full redraw
1045
1046
1047   yascreen_clear_mem
1048              inline void yascreen_clear_mem(yascreen *s,uint32_t attr);
1049
1050
1051
1052       clear memory buffer
1053
1054
1055       all cells in the screen are set to Space, using  attr  for  colors  and
1056       style
1057
1058
1059   yascreen_cursor
1060              inline void yascreen_cursor(yascreen *s,int on);
1061
1062
1063
1064       hide (on=0) or show (on is non-zero) cusror
1065
1066
1067       screen is updated immediately
1068
1069
1070   yascreen_cursor_xy
1071              inline void yascreen_cursor_xy(yascreen *s,int x,int y);
1072
1073
1074
1075       set cursor position
1076
1077
1078       screen is updated immediately
1079
1080
1081   yascreen_altbuf
1082              inline void yascreen_altbuf(yascreen *s,int on);
1083
1084
1085
1086       switch between regular and alternative buffer
1087
1088
1089       screen is updated immediately
1090
1091
1092   yascreen_clear
1093              inline void yascreen_clear(yascreen *s);
1094
1095
1096
1097       clear real screen, no change to memory buffers
1098
1099
1100   yascreen_clearln
1101              inline void yascreen_clearln(yascreen *s);
1102
1103
1104
1105       clear current line, no change to memory buffers
1106
1107
1108   yascreen_update_attr
1109              inline void yascreen_update_attr(yascreen *s,uint32_t oattr,uint32_t nattr);
1110
1111
1112
1113       apply  difference  between  two attrs and output the optimized ANSI se‐
1114       quence to switch from oattr to nattr
1115
1116
1117       if oattr=0xffffffff, the full ANSI sequence will be generated
1118
1119
1120       no change to memory buffers
1121
1122
1123   yascreen_set_attr
1124              yascreen_set_attr(s,attr)
1125
1126
1127
1128       reset all attrs and set specific one (attr)
1129
1130
1131   yascreen_print
1132              inline int yascreen_print(yascreen *s,const char *format,...) __attribute__((format(printf,2,3)));
1133
1134
1135
1136   yascreen_write
1137              inline int yascreen_write(yascreen *s,const char *str,int len);
1138
1139
1140
1141   yascreen_puts
1142              inline int yascreen_puts(yascreen *s,const char *str);
1143
1144
1145
1146   yascreen_clearln_s
1147              inline const char *yascreen_clearln_s(yascreen *s);
1148
1149
1150
1151       print in line mode
1152
1153
1154   yascreen_sx
1155              inline int yascreen_sx(yascreen *s);
1156
1157
1158
1159       get current x size
1160
1161
1162   yascreen_sy
1163              inline int yascreen_sy(yascreen *s);
1164
1165
1166
1167       get current y size
1168
1169
1170   yascreen_x
1171              inline int yascreen_x(yascreen *s);
1172
1173
1174
1175       get current x
1176
1177
1178   yascreen_y
1179              inline int yascreen_y(yascreen *s);
1180
1181
1182
1183       get current y
1184
1185
1186   yascreen_esc_to
1187              inline void yascreen_esc_to(yascreen *s,int timeout);
1188
1189
1190
1191       set timeout for single ESC key press
1192
1193
1194   yascreen_ckto
1195              inline void yascreen_ckto(yascreen *s);
1196
1197
1198
1199       in case of external event loop, this call will check for single ESC key
1200
1201
1202       should be called regularly enough so that the above  specified  timeout
1203       is not extended too much
1204
1205
1206       if not called often enough then single ESC will be yielded after longer
1207       timeout
1208
1209
1210       if not called at all then single ESC will  be  yielded  with  next  key
1211       press
1212
1213
1214   yascreen_getch_to
1215              inline int yascreen_getch_to(yascreen *s,int timeout);
1216
1217
1218
1219       wait  for  a  key,  return ASCII or extended keycode, wait no more than
1220       timeout in milliseconds
1221
1222
1223   yascreen_getch
1224              yascreen_getch(s)
1225
1226
1227
1228       get a key without timeout
1229
1230
1231       this macro expands to yascreen_getch_to(s,0)
1232
1233
1234       zero timeout=wait forever
1235
1236
1237   yascreen_getch_nowait
1238              yascreen_getch_nowait(s)
1239
1240
1241
1242       get a key, if available, return immediately
1243
1244
1245       this macro expands to yascreen_getch_to(s,-1)
1246
1247
1248       negative timeout=do not wait
1249
1250
1251   yascreen_ungetch
1252              inline void yascreen_ungetch(yascreen *s,int key);
1253
1254
1255
1256       put back key value in key buffer
1257
1258
1259       the internal key buffer is dynamically allocated,  hence  there  is  no
1260       limit  of how many key codes may be put back, but in case of memory al‐
1261       location failure, the error will not be reported and the key  will  not
1262       be put into the buffer
1263
1264
1265   yascreen_pushch
1266              inline void yascreen_pushch(yascreen *s,int key);
1267
1268
1269
1270       push key value at end of key buffer
1271
1272
1273       similar to yascreen_ungetch but the key code will be returned after all
1274       other key codes currently in the buffer
1275
1276
1277       the internal key buffer is dynamically allocated,  hence  there  is  no
1278       limit  of how many key codes may be put back, but in case of memory al‐
1279       location failure, the error will not be reported and the key  will  not
1280       be put into the buffer
1281
1282
1283   yascreen_feed
1284              inline void yascreen_feed(yascreen *s,unsigned char c);
1285
1286
1287
1288       feed key sequence state machine with byte stream
1289
1290
1291       this  is  useful to implement external event loop and read key codes by
1292       yascreen_getch_nowait until it returns -1
1293
1294
1295   yascreen_peekch
1296              inline int yascreen_peekch(yascreen *s);
1297
1298
1299
1300       peek for key without removing it from input queue
1301
1302
1303   yascreen_getsize
1304              inline void yascreen_getsize(yascreen *s,int *sx,int *sy);
1305
1306
1307
1308       get last reported screen size
1309
1310
1311       set both to 0 if there is none
1312
1313
1314       this will yield valid result after YAS_SCREEN_SIZE is returned as  key‐
1315       press
1316
1317
1318   yascreen_reqsize
1319              inline void yascreen_reqsize(yascreen *s);
1320
1321
1322
1323       request terminal to report its size via ANSI sequence
1324
1325
1326   yascreen_set_hint_i
1327              inline void yascreen_set_hint_i(yascreen *s,int hint);
1328
1329
1330
1331   yascreen_get_hint_i
1332              inline int yascreen_get_hint_i(yascreen *s);
1333
1334
1335
1336   yascreen_set_hint_p
1337              inline void yascreen_set_hint_p(yascreen *s,void *hint);
1338
1339
1340
1341   yascreen_get_hint_p
1342              inline void *yascreen_get_hint_p(yascreen *s);
1343
1344
1345
1346       get/set opaque hint values
1347
1348
1349       integer and pointer hints are stored separately and both can be used at
1350       the same time
1351
1352
1353       these are useful to link the yascreen instance to user program data
1354
1355
1356       for example a single output callback may output to socket or  a  termi‐
1357       nal, depending on the hint values
1358
1359
1360   yascreen_line_flush
1361              inline void yascreen_line_flush(yascreen *s,int on);
1362
1363
1364
1365       enable/disable  auto  flush  for line and direct screen oriented opera‐
1366       tions
1367
1368
1369       yascreen versions before 1.77 didn't use buffered output and would  im‐
1370       mediately send the output to the screen
1371
1372
1373       disabling internal flush can help an application optimize the number of
1374       write calls at the cost of performing explicit flush after  each  group
1375       of operations
1376
1377
1378       explicit flush example:
1379
1380
1381              yascreen_write(s,"",0);
1382
1383
1384
1385   yascreen_getwch_to
1386              inline wchar_t yascreen_getwch_to(yascreen *s,int timeout);
1387
1388
1389
1390       wait for a key, return wide character or extended keycode, wait no more
1391       than timeout in milliseconds
1392
1393
1394       yascreen_getwch_to does not work in non-unicode mode  and  will  always
1395       return YAS_K_NONE
1396
1397
1398       mixing  the utf8 and wide character input modes will break on multibyte
1399       utf8 sequences and is not supported
1400
1401
1402   yascreen_getwch
1403              yascreen_getwch(s)
1404
1405
1406
1407       get a key as wide character without timeout
1408
1409
1410       this macro expands to yascreen_getwch_to(s,0)
1411
1412
1413       zero timeout=wait forever
1414
1415
1416       yascreen_getwch does not work in non-unicode mode and will  always  re‐
1417       turn YAS_K_NONE
1418
1419
1420   yascreen_getwch_nowait
1421              yascreen_getwch_nowait(s)
1422
1423
1424
1425       get a key as a wide character, if available, return immediately
1426
1427
1428       this macro expands to yascreen_getwch_to(s,-1)
1429
1430
1431       negative timeout=do not wait
1432
1433
1434       yascreen_getwch_nowait  does  not work in non-unicode mode and will al‐
1435       ways return YAS_K_NONE
1436
1437
1438   yascreen_ungetwch
1439              inline void yascreen_ungetwch(yascreen *s,wchar_t key);
1440
1441
1442
1443       put back wide character key value in key buffer
1444
1445
1446       the internal key buffer is dynamically allocated,  hence  there  is  no
1447       limit  of how many key codes may be put back, but in case of memory al‐
1448       location failure, the error will not be reported and the key  will  not
1449       be put into the buffer
1450
1451
1452       the  internal  key  buffer contains utf8 and the wide character will be
1453       expanded to the appropriate utf8 sequence
1454
1455
1456       yascreen_ungetwch does not do anything in non-unicode mode
1457
1458
1459   yascreen_peekwch
1460              inline wchar_t yascreen_peekwch(yascreen *s);
1461
1462
1463
1464       peek for key without removing it from input queue
1465
1466
1467       yascreen_peekwch does not work in non-unicode mode and will always  re‐
1468       turn YAS_K_NONE
1469
1470
1471
1472yascreen                      September 30, 2020                   YASCREEN(3)
Impressum