.nh .TH YASCREEN 3 "September 30, 2020" yascreen "User-Manual" .SH NAME .PP yascreen - Yet Another Screen Library (curses replacement for daemons and embedded apps) .SH SYNOPSIS .PP \fB\fC#include \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 \fB\fCgmake\fR is required to build. .SH Architecture .PP yascreen uses an opaque data structure, allocated by the library and dynamically resized when needed - \fB\fCyascreen_init(int sx, int sy)\fR / \fB\fCyascreen_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. .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 (\fB\fCSIGWINCH\fR) should always be handled by the application. .SH Example initialization for terminal and handling of SIGWINCH .PP .RS .nf 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 } } .fi .RE .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 \fB\fCstdin\fR/\fB\fCstdout\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 .PP .RS .nf 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 } } .fi .RE .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 . \fB\fCName\fR \fB\fCFunction\fR \fB\fCYAS_ITALIC\fR italic \fB\fCYAS_UNDERL\fR underline \fB\fCYAS_STRIKE\fR stikeout \fB\fCYAS_INVERSE\fR inverse \fB\fCYAS_BOLD\fR bold \fB\fCYAS_BLINK\fR blink .TE .SS Color codes .TS allbox; l l l l . \fB\fCName\fR \fB\fCColor\fR \fB\fCYAS_BLACK\fR black \fB\fCYAS_RED\fR red \fB\fCYAS_GREEN\fR green \fB\fCYAS_YELLOW\fR yellow \fB\fCYAS_BLUE\fR blue \fB\fCYAS_MAGENTA\fR magenta \fB\fCYAS_CYAN\fR cyan \fB\fCYAS_WHITE\fR white \fB\fCYAS_FGCOLORDEF\fR default terminal foreground \fB\fCYAS_BGCOLORDEF\fR default terminal background .TE .SS Helper macros .TS allbox; l l l l . \fB\fCName\fR \fB\fCDescription\fR \fB\fCYAS_FG(attribute)\fR extract foreground color \fB\fCYAS_BG(attribute)\fR extract background color \fB\fCYAS_FGCOLOR(color)\fR T{ shift simple color value into foreground color T} \fB\fCYAS_BGCOLOR(color)\fR T{ shift simple color value into background color T} \fB\fCYAS_FGXCOLOR(color)\fR T{ shift 256 palette color value into foreground color T} \fB\fCYAS_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 \fB\fCYAS_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 . \fB\fCName\fR \fB\fCValue\fR \fB\fCDescription\fR \fB\fCYAS_K_NONE\fR 0xf0000 T{ no key is available; in time limited mode means that the time limit expired T} \fB\fCYAS_SCREEN_SIZE\fR 0xf0701 T{ notification for screen size change (may come because of telnet or ANSI sequence) T} \fB\fCYAS_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 . \fB\fCName\fR \fB\fCValue\fR \fB\fCDescription\fR \fB\fCYAS_K_NUL\fR 0x00 Nul; on some terminals Ctrl-2 \fB\fCYAS_K_C_A\fR 0x01 Ctrl-A \fB\fCYAS_K_C_B\fR 0x02 Ctrl-B \fB\fCYAS_K_C_C\fR 0x03 Ctrl-C \fB\fCYAS_K_C_D\fR 0x04 Ctrl-D \fB\fCYAS_K_C_E\fR 0x05 Ctrl-E \fB\fCYAS_K_C_F\fR 0x06 Ctrl-F \fB\fCYAS_K_C_G\fR 0x07 Ctrl-G \fB\fCYAS_K_C_H\fR 0x08 T{ Ctrl-H; depends on terminal see YAS-K-BSP and YAS-K-C-8 T} \fB\fCYAS_K_C_I\fR 0x09 Ctrl-I \fB\fCYAS_K_TAB\fR 0x09 Tab \fB\fCYAS_K_C_J\fR 0x0a Ctrl-J \fB\fCYAS_K_C_K\fR 0x0b Ctrl-K \fB\fCYAS_K_C_L\fR 0x0c Ctrl-L \fB\fCYAS_K_C_M\fR 0x0d T{ Enter, Return, Ctrl-M; see below T} \fB\fCYAS_K_RET\fR 0x0d T{ Enter, Return, Ctrl-M; see above T} \fB\fCYAS_K_C_N\fR 0x0e Ctrl-N \fB\fCYAS_K_C_O\fR 0x0f Ctrl-O \fB\fCYAS_K_C_P\fR 0x10 Ctrl-O \fB\fCYAS_K_C_Q\fR 0x11 Ctrl-Q \fB\fCYAS_K_C_R\fR 0x12 Ctrl-R \fB\fCYAS_K_C_S\fR 0x13 Ctrl-S \fB\fCYAS_K_C_T\fR 0x14 Ctrl-T \fB\fCYAS_K_C_U\fR 0x15 Ctrl-U \fB\fCYAS_K_C_V\fR 0x16 Ctrl-V \fB\fCYAS_K_C_W\fR 0x17 Ctrl-W \fB\fCYAS_K_C_X\fR 0x18 Ctrl-X \fB\fCYAS_K_C_Y\fR 0x19 Ctrl-Y \fB\fCYAS_K_C_Z\fR 0x1a Ctrl-Z \fB\fCYAS_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} \fB\fCYAS_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} \fB\fCYAS_K_C_4\fR 0x1c Ctrl-4 \fB\fCYAS_K_C_5\fR 0x1d Ctrl-5 \fB\fCYAS_K_C_6\fR 0x1e Ctrl-6 \fB\fCYAS_K_C_7\fR 0x1f Ctrl-7 \fB\fCYAS_K_SPACE\fR 0x20 Space \fB\fCYAS_K_EXCL\fR 0x21 ! \fB\fCYAS_K_DQUOT\fR 0x22 " \fB\fCYAS_K_HASH\fR 0x23 # \fB\fCYAS_K_POUND\fR 0x24 $ \fB\fCYAS_K_PERC\fR 0x25 % \fB\fCYAS_K_AND\fR 0x26 Ampersand \fB\fCYAS_K_QUOT\fR 0x27 \&' \fB\fCYAS_K_OBRA\fR 0x28 ( \fB\fCYAS_K_CBRA\fR 0x29 ) \fB\fCYAS_K_STAR\fR 0x2a * \fB\fCYAS_K_PLUS\fR 0x2b + \fB\fCYAS_K_COMMA\fR 0x2c , \fB\fCYAS_K_MINUS\fR 0x2d - \fB\fCYAS_K_DOT\fR 0x2e \&. \fB\fCYAS_K_SLASH\fR 0x2f / \fB\fCYAS_K_0\fR 0x30 0 \fB\fCYAS_K_1\fR 0x31 1 \fB\fCYAS_K_2\fR 0x32 2 \fB\fCYAS_K_3\fR 0x33 3 \fB\fCYAS_K_4\fR 0x34 4 \fB\fCYAS_K_5\fR 0x35 5 \fB\fCYAS_K_6\fR 0x36 6 \fB\fCYAS_K_7\fR 0x37 7 \fB\fCYAS_K_8\fR 0x38 8 \fB\fCYAS_K_9\fR 0x39 9 \fB\fCYAS_K_COLON\fR 0x3a : \fB\fCYAS_K_SEMI\fR 0x3b ; \fB\fCYAS_K_LT\fR 0x3c < \fB\fCYAS_K_EQ\fR 0x3d Equal \fB\fCYAS_K_GT\fR 0x3e > \fB\fCYAS_K_QUEST\fR 0x3f ? \fB\fCYAS_K_AT\fR 0x40 @ \fB\fCYAS_K_A\fR 0x41 A \fB\fCYAS_K_B\fR 0x42 B \fB\fCYAS_K_C\fR 0x43 C \fB\fCYAS_K_D\fR 0x44 D \fB\fCYAS_K_E\fR 0x45 E \fB\fCYAS_K_F\fR 0x46 F \fB\fCYAS_K_G\fR 0x47 G \fB\fCYAS_K_H\fR 0x48 H \fB\fCYAS_K_I\fR 0x49 I \fB\fCYAS_K_J\fR 0x4a J \fB\fCYAS_K_K\fR 0x4b K \fB\fCYAS_K_L\fR 0x4c L \fB\fCYAS_K_M\fR 0x4d M \fB\fCYAS_K_N\fR 0x4e N \fB\fCYAS_K_O\fR 0x4f O \fB\fCYAS_K_P\fR 0x50 P \fB\fCYAS_K_Q\fR 0x51 Q \fB\fCYAS_K_R\fR 0x52 R \fB\fCYAS_K_S\fR 0x53 S \fB\fCYAS_K_T\fR 0x54 T \fB\fCYAS_K_U\fR 0x55 U \fB\fCYAS_K_V\fR 0x56 V \fB\fCYAS_K_W\fR 0x57 W \fB\fCYAS_K_X\fR 0x58 X \fB\fCYAS_K_Y\fR 0x59 Y \fB\fCYAS_K_Z\fR 0x5a Z \fB\fCYAS_K_OSQ\fR 0x5b OpenSquareBracket \fB\fCYAS_K_BSLASH\fR 0x5c Backslash \fB\fCYAS_K_CSQ\fR 0x5d CloseSquareBracket \fB\fCYAS_K_CARRET\fR 0x5e ^ \fB\fCYAS_K_USCORE\fR 0x5f Underscore \fB\fCYAS_K_BTICK\fR 0x60 Backtick \fB\fCYAS_K_a\fR 0x61 a \fB\fCYAS_K_b\fR 0x62 b \fB\fCYAS_K_c\fR 0x63 c \fB\fCYAS_K_d\fR 0x64 d \fB\fCYAS_K_e\fR 0x65 e \fB\fCYAS_K_f\fR 0x66 f \fB\fCYAS_K_g\fR 0x67 g \fB\fCYAS_K_h\fR 0x68 h \fB\fCYAS_K_i\fR 0x69 i \fB\fCYAS_K_j\fR 0x6a j \fB\fCYAS_K_k\fR 0x6b k \fB\fCYAS_K_l\fR 0x6c l \fB\fCYAS_K_m\fR 0x6d m \fB\fCYAS_K_n\fR 0x6e n \fB\fCYAS_K_o\fR 0x6f o \fB\fCYAS_K_p\fR 0x70 p \fB\fCYAS_K_q\fR 0x71 q \fB\fCYAS_K_r\fR 0x72 r \fB\fCYAS_K_s\fR 0x73 s \fB\fCYAS_K_t\fR 0x74 t \fB\fCYAS_K_u\fR 0x75 u \fB\fCYAS_K_v\fR 0x76 v \fB\fCYAS_K_w\fR 0x77 w \fB\fCYAS_K_x\fR 0x78 x \fB\fCYAS_K_y\fR 0x79 y \fB\fCYAS_K_z\fR 0x7a z \fB\fCYAS_K_OCUR\fR 0x7b { \fB\fCYAS_K_PIPE\fR 0x7c Pipe \fB\fCYAS_K_CCUR\fR 0x7d } \fB\fCYAS_K_TLD\fR 0x7e Tilde \fB\fCYAS_K_C_8\fR 0x7f T{ Backspace; see below; depends on terminal see YAS-K-C-H T} \fB\fCYAS_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 . \fB\fCName\fR \fB\fCValue\fR \fB\fCDescription\fR \fB\fCYAS_K_F1\fR 0xf0001 F1 \fB\fCYAS_K_F2\fR 0xf0002 F2 \fB\fCYAS_K_F3\fR 0xf0003 F3 \fB\fCYAS_K_F4\fR 0xf0004 F4 \fB\fCYAS_K_F5\fR 0xf0005 F5 \fB\fCYAS_K_F6\fR 0xf0006 F6 \fB\fCYAS_K_F7\fR 0xf0007 F7 \fB\fCYAS_K_F8\fR 0xf0008 F8 \fB\fCYAS_K_F9\fR 0xf0009 F9 \fB\fCYAS_K_F10\fR 0xf000a F10 \fB\fCYAS_K_F11\f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\fR 0xf002a Alt-F6 \fB\fCYAS_K_A_F7\fR 0xf002b Alt-F7 \fB\fCYAS_K_A_F8\fR 0xf002c Alt-F8 \fB\fCYAS_K_A_F9\fR 0xf002d Alt-F9 \fB\fCYAS_K_A_F10\fR 0xf002e Alt-F10 \fB\fCYAS_K_A_F11\fR 0xf002f Alt-F11 \fB\fCYAS_K_A_F12\fR 0xf0030 Alt-F12 \fB\fCYAS_K_LEFT\fR 0xf0031 Left \fB\fCYAS_K_UP\fR 0xf0032 Up \fB\fCYAS_K_DOWN\fR 0xf0033 Down \fB\fCYAS_K_RIGHT\fR 0xf0034 Right \fB\fCYAS_K_HOME\fR 0xf0035 Home \fB\fCYAS_K_END\fR 0xf0036 End \fB\fCYAS_K_PGUP\fR 0xf0037 PageUp \fB\fCYAS_K_PGDN\fR 0xf0038 PageDown \fB\fCYAS_K_INS\fR 0xf0039 Insert \fB\fCYAS_K_DEL\fR 0xf003a Delete \fB\fCYAS_K_C_LEFT\fR 0xf003b Ctrl-Left \fB\fCYAS_K_C_UP\fR 0xf003c Ctrl-Up \fB\fCYAS_K_C_DOWN\fR 0xf003d Ctrl-Down \fB\fCYAS_K_C_RIGHT\fR 0xf003e Ctrl-Right \fB\fCYAS_K_S_LEFT\fR 0xf003f Shift-Left \fB\fCYAS_K_S_UP\fR 0xf0040 Shift-Up \fB\fCYAS_K_S_DOWN\fR 0xf0041 Shift-Down \fB\fCYAS_K_S_RIGHT\fR 0xf0042 Shift-Right .TE .RS .IP \(bu 2 Alt- .RE .PP These codes are generated by a helper macro - \fB\fCYAS_K_ALT(keycode)\fR\&. .TS allbox; l l l l . \fB\fCName\fR \fB\fCDescription\fR \fB\fCYAS_K_A_BT\fR Alt-Backtick \fB\fCYAS_K_A_1\fR Alt-1 \fB\fCYAS_K_A_2\fR Alt-2 \fB\fCYAS_K_A_3\fR Alt-3 \fB\fCYAS_K_A_4\fR Alt-4 \fB\fCYAS_K_A_5\fR Alt-5 \fB\fCYAS_K_A_6\fR Al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t-v \fB\fCYAS_K_A_w\fR Alt-w \fB\fCYAS_K_A_x\fR Alt-x \fB\fCYAS_K_A_y\fR Alt-y \fB\fCYAS_K_A_z\fR Alt-z .TE .SH Functions .PP All functions in the API work with a pointer to an opaque \fB\fCyascreen\fR structure. .PP The structure is allocated internally in the library by \fB\fCyascreen_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 \fB\fCstruct yascreen\fR object is accessed by a single thread. .SS yascreen_init .PP .RS .nf inline yascreen *yascreen_init(int sx,int sy); .fi .RE .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 .PP in case of error, returns \fB\fCNULL\fR .SS yascreen_ver .PP .RS .nf inline const char *yascreen_ver(void); .fi .RE .PP returns a string with the library version .SS yascreen_setout .PP .RS .nf inline int yascreen_setout(yascreen *s,ssize_t (*out)(yascreen *s,const void *data,size_t len)); .fi .RE .PP set callback that handles output .PP if out=NULL, the output goes to \fB\fCstdout\fR .PP the callback may implement internal buffering, a flush is signalled by calling \fB\fCout\fR with len=0 .SS yascreen_set_unicode .PP .RS .nf inline void yascreen_set_unicode(yascreen *s,int on); .fi .RE .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 .PP .RS .nf inline void yascreen_set_telnet(yascreen *s,int on); .fi .RE .PP enable (on is non-zero) or disable (on=0) telnet sequence processing .PP by default telnet mode is off .SS yascreen_init_telnet .PP .RS .nf inline void yascreen_init_telnet(yascreen *s); .fi .RE .PP depending on telnet sequence processing, sends a set of telnet initialization sequences .SS yascreen_resize .PP .RS .nf inline int yascreen_resize(yascreen *s,int sx,int sy); .fi .RE .PP resize screen .PP should redraw afterwards .PP since allocation is involved, this may fail and return -1 .SS yascreen_free .PP .RS .nf inline void yascreen_free(yascreen *s); .fi .RE .PP finish the lifecycle of \fB\fCstruct yascreen\fR - all internally allocated memory is freed .SS yascreen_term_save .PP .RS .nf inline void yascreen_term_save(yascreen *s); .fi .RE .PP save current terminal state on top of state stack .SS yascreen_term_restore .PP .RS .nf inline void yascreen_term_restore(yascreen *s); .fi .RE .PP restore previously saved terminal state from top of state stack .SS yascreen_term_push .PP .RS .nf inline void yascreen_term_push(yascreen *s); .fi .RE .PP push current terminal state to state stack .SS yascreen_term_pop .PP .RS .nf inline void yascreen_term_pop(yascreen *s); .fi .RE .PP pop and restore previously saved terminal state from state stack .SS yascreen_term_set .PP .RS .nf inline void yascreen_term_set(yascreen *s,int mode); .fi .RE .PP set terminal for proper screen operation .SS \fB\fCmode\fR is a bitmask, containing one of .TS allbox; l l l l l l . \fB\fCName\fR \fB\fCValue\fR \fB\fCDescription\fR \fB\fCYAS_NOBUFF\fR 1 T{ turn off canonical mode (disable ICANON and IEXTEN) T} \fB\fCYAS_NOSIGN\fR 2 disable ISIG \fB\fCYAS_NOECHO\fR 4 disable local echo (ECHO) \fB\fCYAS_ONLCR\fR 8 ONLCR or OPOST .TE .SS yascreen_printxy .PP .RS .nf inline int yascreen_printxy(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6))); .fi .RE .SS yascreen_putsxy .PP .RS .nf inline int yascreen_putsxy(yascreen *s,int x,int y,uint32_t attr,const char *str); .fi .RE .PP print at position, if data exceeds buffer, then it gets truncated .SS yascreen_printxyu .PP .RS .nf inline int yascreen_printxyu(yascreen *s,int x,int y,uint32_t attr,const char *format,...) __attribute__((format(printf,5,6))); .fi .RE .SS yascreen_putsxyu .PP .RS .nf inline int yascreen_putsxyu(yascreen *s,int x,int y,uint32_t attr,const char *str); .fi .RE .PP print at position, if data exceeds buffer, then it gets truncated .PP screen is immediately updated .SS yascreen_update .PP .RS .nf inline int yascreen_update(yascreen *s); .fi .RE .PP sync memory state to screen .PP since allocation is involved, this may fail and return -1 .SS yascreen_redraw .PP .RS .nf inline void yascreen_redraw(yascreen *s); .fi .RE .PP set next update to be a full redraw .SS yascreen_clear_mem .PP .RS .nf inline void yascreen_clear_mem(yascreen *s,uint32_t attr); .fi .RE .PP clear memory buffer .PP all cells in the screen are set to \fB\fCSpace\fR, using \fB\fCattr\fR for colors and style .SS yascreen_cursor .PP .RS .nf inline void yascreen_cursor(yascreen *s,int on); .fi .RE .PP hide (\fB\fCon\fR=0) or show (\fB\fCon\fR is non-zero) cusror .PP screen is updated immediately .SS yascreen_cursor_xy .PP .RS .nf inline void yascreen_cursor_xy(yascreen *s,int x,int y); .fi .RE .PP set cursor position .PP screen is updated immediately .SS yascreen_altbuf .PP .RS .nf inline void yascreen_altbuf(yascreen *s,int on); .fi .RE .PP switch between regular and alternative buffer .PP screen is updated immediately .SS yascreen_clear .PP .RS .nf inline void yascreen_clear(yascreen *s); .fi .RE .PP clear real screen, no change to memory buffers .SS yascreen_clearln .PP .RS .nf inline void yascreen_clearln(yascreen *s); .fi .RE .PP clear current line, no change to memory buffers .SS yascreen_update_attr .PP .RS .nf inline void yascreen_update_attr(yascreen *s,uint32_t oattr,uint32_t nattr); .fi .RE .PP apply difference between two attrs and output the optimized ANSI sequence to switch from \fB\fCoattr\fR to \fB\fCnattr\fR .PP if \fB\fCoattr\fR=0xffffffff, the full ANSI sequence will be generated .PP no change to memory buffers .SS yascreen_set_attr .PP .RS .nf yascreen_set_attr(s,attr) .fi .RE .PP reset all attrs and set specific one (\fB\fCattr\fR) .SS yascreen_print .PP .RS .nf inline int yascreen_print(yascreen *s,const char *format,...) __attribute__((format(printf,2,3))); .fi .RE .SS yascreen_write .PP .RS .nf inline int yascreen_write(yascreen *s,const char *str,int len); .fi .RE .SS yascreen_puts .PP .RS .nf inline int yascreen_puts(yascreen *s,const char *str); .fi .RE .SS yascreen_clearln_s .PP .RS .nf inline const char *yascreen_clearln_s(yascreen *s); .fi .RE .PP print in line mode .SS yascreen_sx .PP .RS .nf inline int yascreen_sx(yascreen *s); .fi .RE .PP get current x size .SS yascreen_sy .PP .RS .nf inline int yascreen_sy(yascreen *s); .fi .RE .PP get current y size .SS yascreen_x .PP .RS .nf inline int yascreen_x(yascreen *s); .fi .RE .PP get current x .SS yascreen_y .PP .RS .nf inline int yascreen_y(yascreen *s); .fi .RE .PP get current y .SS yascreen_esc_to .PP .RS .nf inline void yascreen_esc_to(yascreen *s,int timeout); .fi .RE .PP set timeout for single ESC key press .SS yascreen_ckto .PP .RS .nf inline void yascreen_ckto(yascreen *s); .fi .RE .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 .PP .RS .nf inline int yascreen_getch_to(yascreen *s,int timeout); .fi .RE .PP wait for a key, return ASCII or extended keycode, wait no more than timeout in milliseconds .SS yascreen_getch .PP .RS .nf yascreen_getch(s) .fi .RE .PP get a key without timeout .PP this macro expands to \fB\fCyascreen_getch_to(s,0)\fR .PP zero timeout=wait forever .SS yascreen_getch_nowait .PP .RS .nf yascreen_getch_nowait(s) .fi .RE .PP get a key, if available, return immediately .PP this macro expands to \fB\fCyascreen_getch_to(s,-1)\fR .PP negative timeout=do not wait .SS yascreen_ungetch .PP .RS .nf inline void yascreen_ungetch(yascreen *s,int key); .fi .RE .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 .PP .RS .nf inline void yascreen_pushch(yascreen *s,int key); .fi .RE .PP push key value at end of key buffer .PP similar to \fB\fCyascreen_ungetch\fR but the \fB\fCkey\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 .PP .RS .nf inline void yascreen_feed(yascreen *s,unsigned char c); .fi .RE .PP feed key sequence state machine with byte stream .PP this is useful to implement external event loop and read key codes by \fB\fCyascreen_getch_nowait\fR until it returns -1 .SS yascreen_peekch .PP .RS .nf inline int yascreen_peekch(yascreen *s); .fi .RE .PP peek for key without removing it from input queue .SS yascreen_getsize .PP .RS .nf inline void yascreen_getsize(yascreen *s,int *sx,int *sy); .fi .RE .PP get last reported screen size .PP set both to 0 if there is none .PP this will yield valid result after \fB\fCYAS_SCREEN_SIZE\fR is returned as keypress .SS yascreen_reqsize .PP .RS .nf inline void yascreen_reqsize(yascreen *s); .fi .RE .PP request terminal to report its size via ANSI sequence .SS yascreen_set_hint_i .PP .RS .nf inline void yascreen_set_hint_i(yascreen *s,int hint); .fi .RE .SS yascreen_get_hint_i .PP .RS .nf inline int yascreen_get_hint_i(yascreen *s); .fi .RE .SS yascreen_set_hint_p .PP .RS .nf inline void yascreen_set_hint_p(yascreen *s,void *hint); .fi .RE .SS yascreen_get_hint_p .PP .RS .nf inline void *yascreen_get_hint_p(yascreen *s); .fi .RE .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 \fB\fCyascreen\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 .PP .RS .nf inline void yascreen_line_flush(yascreen *s,int on); .fi .RE .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 \fB\fCwrite\fR calls at the cost of performing explicit flush after each group of operations .PP explicit flush example: .PP .RS .nf yascreen_write(s,"",0); .fi .RE .SS yascreen_getwch_to .PP .RS .nf inline wchar_t yascreen_getwch_to(yascreen *s,int timeout); .fi .RE .PP wait for a key, return wide character or extended keycode, wait no more than timeout in milliseconds .PP \fB\fCyascreen_getwch_to\fR does not work in non-unicode mode and will always return \fB\fCYAS_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 .PP .RS .nf yascreen_getwch(s) .fi .RE .PP get a key as wide character without timeout .PP this macro expands to \fB\fCyascreen_getwch_to(s,0)\fR .PP zero timeout=wait forever .PP \fB\fCyascreen_getwch\fR does not work in non-unicode mode and will always return \fB\fCYAS_K_NONE\fR .SS yascreen_getwch_nowait .PP .RS .nf yascreen_getwch_nowait(s) .fi .RE .PP get a key as a wide character, if available, return immediately .PP this macro expands to \fB\fCyascreen_getwch_to(s,-1)\fR .PP negative timeout=do not wait .PP \fB\fCyascreen_getwch_nowait\fR does not work in non-unicode mode and will always return \fB\fCYAS_K_NONE\fR .SS yascreen_ungetwch .PP .RS .nf inline void yascreen_ungetwch(yascreen *s,wchar_t key); .fi .RE .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 \fB\fCyascreen_ungetwch\fR does not do anything in non-unicode mode .SS yascreen_peekwch .PP .RS .nf inline wchar_t yascreen_peekwch(yascreen *s); .fi .RE .PP peek for key without removing it from input queue .PP \fB\fCyascreen_peekwch\fR does not work in non-unicode mode and will always return \fB\fCYAS_K_NONE\fR