fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

tty.h

(1573B)


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