File: yascreen.3

package info (click to toggle)
yascreen 2.06-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: ansic: 2,658; makefile: 10
file content (1157 lines) | stat: -rw-r--r-- 26,923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
'\" t
.nh
.TH YASCREEN 3 "January 15, 2025" yascreen "User-Manual"

.SH NAME
.PP
yascreen - Yet Another Screen Library (curses replacement for daemons and embedded apps)


.SH SYNOPSIS
.PP
\fB#include <yascreen.h>\fR


.SH DESCRIPTION
.SH Main features
.RS
.IP \(bu 2
small footprint
.IP \(bu 2
does not have external dependencies
.IP \(bu 2
allows both internal and external event loop
.IP \(bu 2
allows stdin/stdout or external input/output (can work over socket)
.IP \(bu 2
supports basic set of telnet sequences, making it suitable for built-in terminal interfaces for daemons
.IP \(bu 2
supports a limited set of input keystroke sequences
.IP \(bu 2
fully unicode compatible (parts of this depend on wcwidth in libc)
.IP \(bu 2
supports utf8 verification of input
.IP \(bu 2
supports utf8 input and wide character input
.IP \(bu 2
supports non-utf8 input mode
.IP \(bu 2
relies only on a limited subset of ansi/xterm ESC sequences, making it compatible with mostly all modern terminals (inspired by linenoise
\[la]https://github.com/antirez/linenoise\[ra])
.IP \(bu 2
there is no curses API and ancient terminal compatibility, hence less bloat
.IP \(bu 2
there is no autoconf - there is no need to have one
.IP \(bu 2
clean API with opaque private data, usable from C/C++
.IP \(bu 2
easy cross compilation setup (by setting CC, AR, STRIP and RANLIB)

.RE

.PP
Current development is done on Linux, with additional testing on OpenBSD/FreeBSD; other platforms may need minimal fixes.

.PP
On *BSD a \fBgmake\fR is required to build.

.SH Architecture
.PP
yascreen uses an opaque data structure, allocated by the library and dynamically resized when needed - \fByascreen_init(int sx, int sy)\fR / \fByascreen_resize(yascreen *s, int sx, int sy)\fR\&. An application may specify (0,0) for both calls to let yascreen detect the size or use a fixed size. In case the terminal has zero size or does not support the \fBTIOCGWINSZ\fR \fBioctl\fR, the size will default to 80x24.

.PP
There are two modes of operation - telnet protocol over socket or running in terminal. For sockets the event loop would typically be handled outside of the library while for terminals a built-in event loop may be used.

.PP
Modes of operation can be modified at runtime.

.PP
For terminal use signal handling (\fBSIGWINCH\fR) should always be handled by the application.

.SH Example initialization for terminal and handling of SIGWINCH
.EX
yascreen *s;
int winch=0;

void sigwinch(int sign) {
	winch=1;
}

s=yascreen_init(0,0); // let yascreen get term size
yascreen_term_set(s,YAS_NOBUFF|YAS_NOSIGN|YAS_NOECHO);
signal(SIGWINCH,sigwinch);

for (;;) { // main loop
	if (winch) {
		winch=0;
		if (yascreen_resize(s,0,0))
			// handle a fatal error - no memory
		// get the new sizes and redraw
		newsizex=yascreen_sx(s);
		newsizey=yascreen_sy(s);
	}

	// option 1

	// input is handled in external event loop and fed to yascreen via yascreen_feed
	if (FD_ISSET(STDIN_FILENO,&r)&&sizeof c==read(STDIN_FILENO,&c,sizeof c))
		yascreen_feed(s,c); // pump state machine with bytestream

	// keys are processed only when available without delay/blocking
	while ((ch=yascreen_getch_nowait(s))!=-1) {
		// handle processed keys
	}

	// option 2

	// input is handled by yascreen and key or -1 is returned not longer than TIMEOUT ms
	// note: if screen update is based on this, keypresses will force it
	while ((ch=yascreen_getch_to(s,TIMEOUT))!=-1) {
		// handle processed keys
	}

	// option 3

	// input is handled by yascreen and the following call will block until a key is pressed
	if ((ch=yascreen_getch(s))!=-1) {
		// handle processed key
	}
}
.EE

.PP
For sockets input is handled like option 1 in the example above and yascreen needs to be provided with a callback for output.

.PP
In multiprocess mode daemons where \fBstdin\fR/\fBstdout\fR are redirected to a socket the same model from the example above can be used. Obviously SIGWINCH will work only for terminals and for sockets the screen size can get to be known either via telnet or ASNI sequences.

.SH Example initialization for socket with external event loop and telnet sequences processing
.EX
yascreen *s;

s=yascreen_init(80,25); // there is no guarantee that screen size detection is supported on the remote end
yascreen_setout(s,output_cb); // set callback for output
yascreen_set_telnet(s,1); // enable processing of telnet sequences
yascreen_init_telnet(s); // try to negotiate telnet options (regardless if telnet processing is enabled)
yascreen_reqsize(s); // request initial screen size
for (;;) { // main loop
	yascreen_feed(s,c); // feed input from the socket to yascreen

	// keys are processed only when available without delay/blocking
	while ((ch=yascreen_getch_nowait(s))!=-1) {
		// handle processed keys

		// screen size change is reported as a special keypress code:
		if (ch==YAS_TELNET_SIZE||ch==YAS_SCREEN_SIZE) // screen size change reported via telnet or ANSI sequence
			// redraw
	}
}

.EE


.SH API Reference
.SH Predefined constants and Helper macros
.PP
Internally style is kept into bitfields in a single integer variable - that includes foreground/background colors, style modifiers (bold, italic, underline, inverse and blink.

.SS Style codes
.TS
allbox;
l l 
l l .
\fBName\fP	\fBFunction\fP
\fBYAS_ITALIC\fR	italic
\fBYAS_UNDERL\fR	underline
\fBYAS_STRIKE\fR	stikeout
\fBYAS_INVERSE\fR	inverse
\fBYAS_BOLD\fR	bold
\fBYAS_BLINK\fR	blink
.TE

.SS Color codes
.TS
allbox;
l l 
l l .
\fBName\fP	\fBColor\fP
\fBYAS_BLACK\fR	black
\fBYAS_RED\fR	red
\fBYAS_GREEN\fR	green
\fBYAS_YELLOW\fR	yellow
\fBYAS_BLUE\fR	blue
\fBYAS_MAGENTA\fR	magenta
\fBYAS_CYAN\fR	cyan
\fBYAS_WHITE\fR	white
\fBYAS_FGCOLORDEF\fR	default terminal foreground
\fBYAS_BGCOLORDEF\fR	default terminal background
.TE

.SS Helper macros
.TS
allbox;
l l 
l l .
\fBName\fP	\fBDescription\fP
\fBYAS_FG(attribute)\fR	extract foreground color
\fBYAS_BG(attribute)\fR	extract background color
\fBYAS_FGCOLOR(color)\fR	T{
shift simple color value into foreground color
T}
\fBYAS_BGCOLOR(color)\fR	T{
shift simple color value into background color
T}
\fBYAS_FGXCOLOR(color)\fR	T{
shift 256 palette color value into foreground color
T}
\fBYAS_BGXCOLOR(color)\fR	T{
shift 256 palette color value into background color
T}
.TE

.PP
All of the above can be or'ed into attribute, provided that the bits for foreground/background color are all zeroes.

.SS Key codes
.RS
.IP \(bu 2
Special, generated internally

.RE

.PP
Previous versions of the library used -1 and 0x100+ for these codes. In order to achieve unicode wide character compatibility and simpler API, the reserved Unicode range 0xf0000-0xffffd is used for the special codes both in narrow and wide character input modes.

.PP
There is a macro \fBYAS_IS_CC(code)\fR that will evaluate to non-zero for the special codes and to zero for normal characters. Note that all ASCII control characters in the range 0x00-0x7f are treated as normal ones.

.TS
allbox;
l l l 
l l l .
\fBName\fP	\fBValue\fP	\fBDescription\fP
\fBYAS_K_NONE\fR	0xf0000	T{
no key is available; in time limited mode means that the time limit expired
T}
\fBYAS_SCREEN_SIZE\fR	0xf0701	T{
notification for screen size change (may come because of telnet or ANSI sequence)
T}
\fBYAS_TELNET_SIZE\fR	0xf0702	T{
notification for screen size change; duplicates the above, may be used to differentiate how screen size change event was generated
T}
.TE

.RS
.IP \(bu 2
Normal keys

.RE

.TS
allbox;
l l l 
l l l .
\fBName\fP	\fBValue\fP	\fBDescription\fP
\fBYAS_K_NUL\fR	0x00	Nul; on some terminals Ctrl-2
\fBYAS_K_C_A\fR	0x01	Ctrl-A
\fBYAS_K_C_B\fR	0x02	Ctrl-B
\fBYAS_K_C_C\fR	0x03	Ctrl-C
\fBYAS_K_C_D\fR	0x04	Ctrl-D
\fBYAS_K_C_E\fR	0x05	Ctrl-E
\fBYAS_K_C_F\fR	0x06	Ctrl-F
\fBYAS_K_C_G\fR	0x07	Ctrl-G
\fBYAS_K_C_H\fR	0x08	T{
Ctrl-H; depends on terminal see YAS-K-BSP and YAS-K-C-8
T}
\fBYAS_K_C_I\fR	0x09	Ctrl-I
\fBYAS_K_TAB\fR	0x09	Tab
\fBYAS_K_C_J\fR	0x0a	Ctrl-J
\fBYAS_K_C_K\fR	0x0b	Ctrl-K
\fBYAS_K_C_L\fR	0x0c	Ctrl-L
\fBYAS_K_C_M\fR	0x0d	T{
Enter, Return, Ctrl-M; see below
T}
\fBYAS_K_RET\fR	0x0d	T{
Enter, Return, Ctrl-M; see above
T}
\fBYAS_K_C_N\fR	0x0e	Ctrl-N
\fBYAS_K_C_O\fR	0x0f	Ctrl-O
\fBYAS_K_C_P\fR	0x10	Ctrl-O
\fBYAS_K_C_Q\fR	0x11	Ctrl-Q
\fBYAS_K_C_R\fR	0x12	Ctrl-R
\fBYAS_K_C_S\fR	0x13	Ctrl-S
\fBYAS_K_C_T\fR	0x14	Ctrl-T
\fBYAS_K_C_U\fR	0x15	Ctrl-U
\fBYAS_K_C_V\fR	0x16	Ctrl-V
\fBYAS_K_C_W\fR	0x17	Ctrl-W
\fBYAS_K_C_X\fR	0x18	Ctrl-X
\fBYAS_K_C_Y\fR	0x19	Ctrl-Y
\fBYAS_K_C_Z\fR	0x1a	Ctrl-Z
\fBYAS_K_ESC\fR	0x1b	T{
Esc, Ctrl-3; see below; All ANSI sequences start with Esc, this is returned after a timeout or double Esc
T}
\fBYAS_K_C_3\fR	0x1b	T{
Esc, Ctrl-3; see above; All ANSI sequences start with Esc, this is returned after a timeout or double Esc
T}
\fBYAS_K_C_4\fR	0x1c	Ctrl-4
\fBYAS_K_C_5\fR	0x1d	Ctrl-5
\fBYAS_K_C_6\fR	0x1e	Ctrl-6
\fBYAS_K_C_7\fR	0x1f	Ctrl-7
\fBYAS_K_SPACE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e	Tilde
\fBYAS_K_C_8\fR	0x7f	T{
Backspace; see below; depends on terminal see YAS-K-C-H
T}
\fBYAS_K_BSP\fR	0x7f	T{
Backspace; see below; depends on terminal see YAS-K-C-H
T}
.TE

.RS
.IP \(bu 2
Extended keys, parsed from ANSI sequences

.RE

.TS
allbox;
l l l 
l l l .
\fBName\fP	\fBValue\fP	\fBDescription\fP
\fBYAS_K_F1\fR	0xf0001	F1
\fBYAS_K_F2\fR	0xf0002	F2
\fBYAS_K_F3\fR	0xf0003	F3
\fBYAS_K_F4\fR	0xf0004	F4
\fBYAS_K_F5\fR	0xf0005	F5
\fBYAS_K_F6\fR	0xf0006	F6
\fBYAS_K_F7\fR	0xf0007	F7
\fBYAS_K_F8\fR	0xf0008	F8
\fBYAS_K_F9\fR	0xf0009	F9
\fBYAS_K_F10\fR	0xf000a	F10
\fBYAS_K_F11\fR	0xf000b	F11
\fBYAS_K_F12\fR	0xf000c	F12
\fBYAS_K_S_F1\fR	0xf000d	Shift-F1
\fBYAS_K_S_F2\fR	0xf000e	Shift-F2
\fBYAS_K_S_F3\fR	0xf000f	Shift-F3
\fBYAS_K_S_F4\fR	0xf0010	Shift-F4
\fBYAS_K_S_F5\fR	0xf0011	Shift-F5
\fBYAS_K_S_F6\fR	0xf0012	Shift-F6
\fBYAS_K_S_F7\fR	0xf0013	Shift-F7
\fBYAS_K_S_F8\fR	0xf0014	Shift-F8
\fBYAS_K_S_F9\fR	0xf0015	Shift-F9
\fBYAS_K_S_F10\fR	0xf0016	Shift-F10
\fBYAS_K_S_F11\fR	0xf0017	Shift-F11
\fBYAS_K_S_F12\fR	0xf0018	Shift-F12
\fBYAS_K_C_F1\fR	0xf0019	Ctrl-F1
\fBYAS_K_C_F2\fR	0xf001a	Ctrl-F2
\fBYAS_K_C_F3\fR	0xf001b	Ctrl-F3
\fBYAS_K_C_F4\fR	0xf001c	Ctrl-F4
\fBYAS_K_C_F5\fR	0xf001d	Ctrl-F5
\fBYAS_K_C_F6\fR	0xf001e	Ctrl-F6
\fBYAS_K_C_F7\fR	0xf001f	Ctrl-F7
\fBYAS_K_C_F8\fR	0xf0020	Ctrl-F8
\fBYAS_K_C_F9\fR	0xf0021	Ctrl-F9
\fBYAS_K_C_F10\fR	0xf0022	Ctrl-F10
\fBYAS_K_C_F11\fR	0xf0023	Ctrl-F11
\fBYAS_K_C_F12\fR	0xf0024	Ctrl-F12
\fBYAS_K_A_F1\fR	0xf0025	Alt-F1
\fBYAS_K_A_F2\fR	0xf0026	Alt-F2
\fBYAS_K_A_F3\fR	0xf0027	Alt-F3
\fBYAS_K_A_F4\fR	0xf0028	Alt-F4
\fBYAS_K_A_F5\fR	0xf0029	Alt-F5
\fBYAS_K_A_F6\fR	0xf002a	Alt-F6
\fBYAS_K_A_F7\fR	0xf002b	Alt-F7
\fBYAS_K_A_F8\fR	0xf002c	Alt-F8
\fBYAS_K_A_F9\fR	0xf002d	Alt-F9
\fBYAS_K_A_F10\fR	0xf002e	Alt-F10
\fBYAS_K_A_F11\fR	0xf002f	Alt-F11
\fBYAS_K_A_F12\fR	0xf0030	Alt-F12
\fBYAS_K_LEFT\fR	0xf0031	Left
\fBYAS_K_UP\fR	0xf0032	Up
\fBYAS_K_DOWN\fR	0xf0033	Down
\fBYAS_K_RIGHT\fR	0xf0034	Right
\fBYAS_K_HOME\fR	0xf0035	Home
\fBYAS_K_END\fR	0xf0036	End
\fBYAS_K_PGUP\fR	0xf0037	PageUp
\fBYAS_K_PGDN\fR	0xf0038	PageDown
\fBYAS_K_INS\fR	0xf0039	Insert
\fBYAS_K_DEL\fR	0xf003a	Delete
\fBYAS_K_C_LEFT\fR	0xf003b	Ctrl-Left
\fBYAS_K_C_UP\fR	0xf003c	Ctrl-Up
\fBYAS_K_C_DOWN\fR	0xf003d	Ctrl-Down
\fBYAS_K_C_RIGHT\fR	0xf003e	Ctrl-Right
\fBYAS_K_S_LEFT\fR	0xf003f	Shift-Left
\fBYAS_K_S_UP\fR	0xf0040	Shift-Up
\fBYAS_K_S_DOWN\fR	0xf0041	Shift-Down
\fBYAS_K_S_RIGHT\fR	0xf0042	Shift-Right
\fBYAS_K_A_LEFT\fR	0xf0043	Alt-Left
\fBYAS_K_A_UP\fR	0xf0044	Alt-Up
\fBYAS_K_A_DOWN\fR	0xf0045	Alt-Down
\fBYAS_K_A_RIGHT\fR	0xf0046	Alt-Right
.TE

.RS
.IP \(bu 2
Alt-<letter>

.RE

.PP
These codes are generated by a helper macro - \fBYAS_K_ALT(keycode)\fR\&.

.TS
allbox;
l l 
l l .
\fBName\fP	\fBDescription\fP
\fBYAS_K_A_BT\fR	Alt-Backtick
\fBYAS_K_A_1\fR	Alt-1
\fBYAS_K_A_2\fR	Alt-2
\fBYAS_K_A_3\fR	Alt-3
\fBYAS_K_A_4\fR	Alt-4
\fBYAS_K_A_5\fR	Alt-5
\fBYAS_K_A_6\fR	Alt-6
\fBYAS_K_A_7\fR	Alt-7
\fBYAS_K_A_8\fR	Alt-8
\fBYAS_K_A_9\fR	Alt-9
\fBYAS_K_A_0\fR	Alt-0
\fBYAS_K_A_MINUS\fR	Alt-Minus
\fBYAS_K_A_EQ\fR	Alt-=
\fBYAS_K_A_BSP\fR	Alt-Backspace
\fBYAS_K_A_TLD\fR	Alt-Tilde
\fBYAS_K_A_EXCL\fR	Alt-!
\fBYAS_K_A_AT\fR	Alt-@
\fBYAS_K_A_HASH\fR	Alt-#
\fBYAS_K_A_POUND\fR	Alt-$
\fBYAS_K_A_PERC\fR	Alt-%
\fBYAS_K_A_CARRET\fR	Alt-^
\fBYAS_K_A_AND\fR	Alt-Ampersand
\fBYAS_K_A_STAR\fR	Alt-Star
\fBYAS_K_A_OBRA\fR	Alt-(
\fBYAS_K_A_CBRA\fR	Alt-)
\fBYAS_K_A_UND\fR	Alt-_
\fBYAS_K_A_PLUS\fR	Alt-+
\fBYAS_K_A_a\fR	Alt-a
\fBYAS_K_A_b\fR	Alt-b
\fBYAS_K_A_c\fR	Alt-c
\fBYAS_K_A_d\fR	Alt-d
\fBYAS_K_A_e\fR	Alt-e
\fBYAS_K_A_f\fR	Alt-f
\fBYAS_K_A_g\fR	Alt-g
\fBYAS_K_A_h\fR	Alt-h
\fBYAS_K_A_i\fR	Alt-i
\fBYAS_K_A_j\fR	Alt-j
\fBYAS_K_A_k\fR	Alt-k
\fBYAS_K_A_l\fR	Alt-l
\fBYAS_K_A_m\fR	Alt-m
\fBYAS_K_A_n\fR	Alt-n
\fBYAS_K_A_o\fR	Alt-o
\fBYAS_K_A_p\fR	Alt-p
\fBYAS_K_A_q\fR	Alt-q
\fBYAS_K_A_r\fR	Alt-r
\fBYAS_K_A_s\fR	Alt-s
\fBYAS_K_A_t\fR	Alt-t
\fBYAS_K_A_u\fR	Alt-u
\fBYAS_K_A_v\fR	Alt-v
\fBYAS_K_A_w\fR	Alt-w
\fBYAS_K_A_x\fR	Alt-x
\fBYAS_K_A_y\fR	Alt-y
\fBYAS_K_A_z\fR	Alt-z
.TE

.SH Functions
.PP
All functions in the API work with a pointer to an opaque \fByascreen\fR structure.

.PP
The structure is allocated internally in the library by \fByascreen_init\fR and it is the job of the user program to keep track of it.

.PP
The library is thread safe, as long as each \fBstruct yascreen\fR object is accessed by a single thread.

.SS yascreen_init
.EX
inline yascreen *yascreen_init(int sx,int sy);
.EE

.PP
allocate and initialize screen data

.PP
output defaults to stdout

.PP
in case output is a terminal and initial size is (0,0), the screen size is autodetected
in case the autodetection fails or returns 0x0, it will default to 80x24

.PP
in case of error, returns \fBNULL\fR

.SS yascreen_ver
.EX
inline const char *yascreen_ver(void);
.EE

.PP
returns a string with the library version

.SS yascreen_setout
.EX
inline int yascreen_setout(yascreen *s,ssize_t (*out)(yascreen *s,const void *data,size_t len));
.EE

.PP
set callback that handles output

.PP
if out=NULL, the output goes to \fBstdout\fR

.PP
the callback may implement internal buffering, a flush is signalled by calling \fBout\fR with len=0

.SS yascreen_set_unicode
.EX
inline void yascreen_set_unicode(yascreen *s,int on);
.EE

.PP
enable (on is non-zero) or disable (on=0) unicode input processing

.PP
by default unicode mode is on

.PP
changing the unicode input processing will flush all pending input

.SS yascreen_set_telnet
.EX
inline void yascreen_set_telnet(yascreen *s,int on);
.EE

.PP
enable (on is non-zero) or disable (on=0) telnet sequence processing

.PP
by default telnet mode is off

.SS yascreen_init_telnet
.EX
inline void yascreen_init_telnet(yascreen *s);
.EE

.PP
depending on telnet sequence processing, sends a set of telnet initialization sequences

.SS yascreen_resize
.EX
inline int yascreen_resize(yascreen *s,int sx,int sy);
.EE

.PP
resize screen

.PP
should redraw afterwards

.PP
since allocation is involved, this may fail and return -1

.SS yascreen_free
.EX
inline void yascreen_free(yascreen *s);
.EE

.PP
finish the lifecycle of \fBstruct yascreen\fR - all internally allocated memory is freed

.SS yascreen_term_save
.EX
inline void yascreen_term_save(yascreen *s);
.EE

.PP
save current terminal state on top of state stack

.SS yascreen_term_restore
.EX
inline void yascreen_term_restore(yascreen *s);
.EE

.PP
restore previously saved terminal state from top of state stack

.SS yascreen_term_push
.EX
inline void yascreen_term_push(yascreen *s);
.EE

.PP
push current terminal state to state stack

.SS yascreen_term_pop
.EX
inline void yascreen_term_pop(yascreen *s);
.EE

.PP
pop and restore previously saved terminal state from state stack

.SS yascreen_term_set
.EX
inline void yascreen_term_set(yascreen *s,int mode);
.EE

.PP
set terminal for proper screen operation

.SS \fBmode\fR is a bitmask, containing one of
.TS
allbox;
l l l 
l l l .
\fBName\fP	\fBValue\fP	\fBDescription\fP
\fBYAS_NOBUFF\fR	1	T{
turn off canonical mode (disable ICANON and IEXTEN)
T}
\fBYAS_NOSIGN\fR	2	disable ISIG
\fBYAS_NOECHO\fR	4	disable local echo (ECHO)
\fBYAS_ONLCR\fR	8	ONLCR or OPOST
.TE

.SS yascreen_printxy
.EX
inline int yascreen_printxy(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6)));
.EE

.SS yascreen_putsxy
.EX
inline int yascreen_putsxy(yascreen *s,int x,int y,uint32_t attr,const char *str);
.EE

.PP
print at position, if data exceeds buffer, then it gets truncated

.SS yascreen_printxyu
.EX
inline int yascreen_printxyu(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6)));
.EE

.SS yascreen_putsxyu
.EX
inline int yascreen_putsxyu(yascreen *s,int x,int y,uint32_t attr,const char *str);
.EE

.PP
print at position, if data exceeds buffer, then it gets truncated

.PP
screen is immediately updated

.SS yascreen_update
.EX
inline int yascreen_update(yascreen *s);
.EE

.PP
sync memory state to screen

.PP
since allocation is involved, this may fail and return -1

.SS yascreen_redraw
.EX
inline void yascreen_redraw(yascreen *s);
.EE

.PP
set next update to be a full redraw

.SS yascreen_clear_mem
.EX
inline void yascreen_clear_mem(yascreen *s,uint32_t attr);
.EE

.PP
clear memory buffer

.PP
all cells in the screen are set to \fBSpace\fR, using \fBattr\fR for colors and style

.SS yascreen_cursor
.EX
inline void yascreen_cursor(yascreen *s,int on);
.EE

.PP
hide (\fBon\fR=0) or show (\fBon\fR is non-zero) cusror

.PP
screen is updated immediately

.SS yascreen_cursor_xy
.EX
inline void yascreen_cursor_xy(yascreen *s,int x,int y);
.EE

.PP
set cursor position

.PP
screen is updated immediately

.SS yascreen_altbuf
.EX
inline void yascreen_altbuf(yascreen *s,int on);
.EE

.PP
switch between regular and alternative buffer

.PP
screen is updated immediately

.SS yascreen_clear
.EX
inline void yascreen_clear(yascreen *s);
.EE

.PP
clear real screen, no change to memory buffers

.SS yascreen_clearln
.EX
inline void yascreen_clearln(yascreen *s);
.EE

.PP
clear current line, no change to memory buffers

.SS yascreen_update_attr
.EX
inline void yascreen_update_attr(yascreen *s,uint32_t oattr,uint32_t nattr);
.EE

.PP
apply difference between two attrs and output the optimized ANSI sequence to switch from \fBoattr\fR to \fBnattr\fR

.PP
if \fBoattr\fR=0xffffffff, the full ANSI sequence will be generated

.PP
no change to memory buffers

.SS yascreen_set_attr
.EX
yascreen_set_attr(s,attr)
.EE

.PP
reset all attrs and set specific one (\fBattr\fR)

.SS yascreen_print
.EX
inline int yascreen_print(yascreen *s,const char *format,...) __attribute__((format(printf,2,3)));
.EE

.SS yascreen_write
.EX
inline int yascreen_write(yascreen *s,const char *str,int len);
.EE

.SS yascreen_puts
.EX
inline int yascreen_puts(yascreen *s,const char *str);
.EE

.SS yascreen_clearln_s
.EX
inline const char *yascreen_clearln_s(yascreen *s);
.EE

.PP
print in line mode

.SS yascreen_sx
.EX
inline int yascreen_sx(yascreen *s);
.EE

.PP
get current x size

.SS yascreen_sy
.EX
inline int yascreen_sy(yascreen *s);
.EE

.PP
get current y size

.SS yascreen_x
.EX
inline int yascreen_x(yascreen *s);
.EE

.PP
get current x

.SS yascreen_y
.EX
inline int yascreen_y(yascreen *s);
.EE

.PP
get current y

.SS yascreen_esc_to
.EX
inline void yascreen_esc_to(yascreen *s,int timeout);
.EE

.PP
set timeout for single ESC key press

.SS yascreen_ckto
.EX
inline void yascreen_ckto(yascreen *s);
.EE

.PP
in case of external event loop, this call will check for single ESC key

.PP
should be called regularly enough so that the above specified timeout is not extended too much

.PP
if not called often enough then single ESC will be yielded after longer timeout

.PP
if not called at all then single ESC will be yielded with next key press

.SS yascreen_getch_to
.EX
inline int yascreen_getch_to(yascreen *s,int timeout);
.EE

.PP
wait for a key, return ASCII or extended keycode, wait no more than timeout in milliseconds

.SS yascreen_getch
.EX
yascreen_getch(s)
.EE

.PP
get a key without timeout

.PP
this macro expands to \fByascreen_getch_to(s,0)\fR

.PP
zero timeout=wait forever

.SS yascreen_getch_nowait
.EX
yascreen_getch_nowait(s)
.EE

.PP
get a key, if available, return immediately

.PP
this macro expands to \fByascreen_getch_to(s,-1)\fR

.PP
negative timeout=do not wait

.SS yascreen_ungetch
.EX
inline void yascreen_ungetch(yascreen *s,int key);
.EE

.PP
put back key value in key buffer

.PP
the internal key buffer is dynamically allocated, hence there is no limit of how many key codes may be put back, but in case of memory allocation failure, the error will not be reported and the key will not be put into the buffer

.SS yascreen_pushch
.EX
inline void yascreen_pushch(yascreen *s,int key);
.EE

.PP
push key value at end of key buffer

.PP
similar to \fByascreen_ungetch\fR but the \fBkey\fR code will be returned after all other key codes currently in the buffer

.PP
the internal key buffer is dynamically allocated, hence there is no limit of how many key codes may be put back, but in case of memory allocation failure, the error will not be reported and the key will not be put into the buffer

.SS yascreen_feed
.EX
inline void yascreen_feed(yascreen *s,unsigned char c);
.EE

.PP
feed key sequence state machine with byte stream

.PP
this is useful to implement external event loop and read key codes by \fByascreen_getch_nowait\fR until it returns -1

.SS yascreen_peekch
.EX
inline int yascreen_peekch(yascreen *s);
.EE

.PP
peek for key without removing it from input queue

.SS yascreen_getsize
.EX
inline void yascreen_getsize(yascreen *s,int *sx,int *sy);
.EE

.PP
get last reported screen size

.PP
set both to 0 if there is none

.PP
this will yield valid result after \fBYAS_SCREEN_SIZE\fR is returned as keypress

.SS yascreen_reqsize
.EX
inline void yascreen_reqsize(yascreen *s);
.EE

.PP
request terminal to report its size via ANSI sequence

.SS yascreen_set_hint_i
.EX
inline void yascreen_set_hint_i(yascreen *s,int hint);
.EE

.SS yascreen_get_hint_i
.EX
inline int yascreen_get_hint_i(yascreen *s);
.EE

.SS yascreen_set_hint_p
.EX
inline void yascreen_set_hint_p(yascreen *s,void *hint);
.EE

.SS yascreen_get_hint_p
.EX
inline void *yascreen_get_hint_p(yascreen *s);
.EE

.PP
get/set opaque hint values

.PP
integer and pointer hints are stored separately and both can be used at the same time

.PP
these are useful to link the \fByascreen\fR instance to user program data

.PP
for example a single output callback may output to socket or a terminal, depending on the hint values

.SS yascreen_line_flush
.EX
inline void yascreen_line_flush(yascreen *s,int on);
.EE

.PP
enable/disable auto flush for line and direct screen oriented operations

.PP
yascreen versions before 1.77 didn't use buffered output and would immediately send the output to the screen

.PP
disabling internal flush can help an application optimize the number of \fBwrite\fR calls at the cost of performing explicit flush after each group of operations

.PP
explicit flush example:

.EX
yascreen_write(s,"",0);
.EE

.SS yascreen_getwch_to
.EX
inline wchar_t yascreen_getwch_to(yascreen *s,int timeout);
.EE

.PP
wait for a key, return wide character or extended keycode, wait no more than timeout in milliseconds

.PP
\fByascreen_getwch_to\fR does not work in non-unicode mode and will always return \fBYAS_K_NONE\fR

.PP
mixing the utf8 and wide character input modes will break on multibyte utf8 sequences and is not supported

.SS yascreen_getwch
.EX
yascreen_getwch(s)
.EE

.PP
get a key as wide character without timeout

.PP
this macro expands to \fByascreen_getwch_to(s,0)\fR

.PP
zero timeout=wait forever

.PP
\fByascreen_getwch\fR does not work in non-unicode mode and will always return \fBYAS_K_NONE\fR

.SS yascreen_getwch_nowait
.EX
yascreen_getwch_nowait(s)
.EE

.PP
get a key as a wide character, if available, return immediately

.PP
this macro expands to \fByascreen_getwch_to(s,-1)\fR

.PP
negative timeout=do not wait

.PP
\fByascreen_getwch_nowait\fR does not work in non-unicode mode and will always return \fBYAS_K_NONE\fR

.SS yascreen_ungetwch
.EX
inline void yascreen_ungetwch(yascreen *s,wchar_t key);
.EE

.PP
put back wide character key value in key buffer

.PP
the internal key buffer is dynamically allocated, hence there is no limit of how many key codes may be put back, but in case of memory allocation failure, the error will not be reported and the key will not be put into the buffer

.PP
the internal key buffer contains utf8 and the wide character will be expanded to the appropriate utf8 sequence

.PP
\fByascreen_ungetwch\fR does not do anything in non-unicode mode

.SS yascreen_peekwch
.EX
inline wchar_t yascreen_peekwch(yascreen *s);
.EE

.PP
peek for key without removing it from input queue

.PP
\fByascreen_peekwch\fR does not work in non-unicode mode and will always return \fBYAS_K_NONE\fR