tty.h (1402B)
1 #ifndef TTY_H 2 #define TTY_H TTY_H 3 4 #include <termios.h> 5 6 typedef struct { 7 int fdin; 8 FILE *fout; 9 struct termios original_termios; 10 int fgcolor; 11 size_t maxwidth; 12 size_t maxheight; 13 } tty_t; 14 15 void tty_reset(tty_t *tty); 16 void tty_close(tty_t *tty); 17 void tty_init(tty_t *tty, const char *tty_filename); 18 void tty_getwinsz(tty_t *tty); 19 char tty_getchar(tty_t *tty); 20 int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal); 21 22 void tty_setfg(tty_t *tty, int fg); 23 void tty_setinvert(tty_t *tty); 24 void tty_setunderline(tty_t *tty); 25 void tty_setnormal(tty_t *tty); 26 void tty_setnowrap(tty_t *tty); 27 void tty_setwrap(tty_t *tty); 28 29 #define TTY_COLOR_BLACK 0 30 #define TTY_COLOR_RED 1 31 #define TTY_COLOR_GREEN 2 32 #define TTY_COLOR_YELLOW 3 33 #define TTY_COLOR_BLUE 4 34 #define TTY_COLOR_MAGENTA 5 35 #define TTY_COLOR_CYAN 6 36 #define TTY_COLOR_WHITE 7 37 #define TTY_COLOR_NORMAL 9 38 39 /* tty_newline 40 * Move cursor to the beginning of the next line, clearing to the end of the 41 * current line 42 */ 43 void tty_newline(tty_t *tty); 44 45 /* tty_clearline 46 * Clear to the end of the current line without advancing the cursor. 47 */ 48 void tty_clearline(tty_t *tty); 49 50 void tty_moveup(tty_t *tty, int i); 51 void tty_setcol(tty_t *tty, int col); 52 53 void tty_printf(tty_t *tty, const char *fmt, ...); 54 void tty_putc(tty_t *tty, char c); 55 void tty_flush(tty_t *tty); 56 57 size_t tty_getwidth(tty_t *tty); 58 size_t tty_getheight(tty_t *tty); 59 60 #endif