forked from daujerrene/term
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tm.c
58 lines (48 loc) · 1.02 KB
/
tm.c
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
#include "tm.h"
void tm_init()
{
tcgetattr(0, &__tm_tstructi);
__tm_tstruct = __tm_tstructi;
}
void tm_reset()
{
tcsetattr(0, TCSANOW, &__tm_tstructi);
}
void tm_getwh(unsigned int *w, unsigned int *h)
{
ioctl(STDOUT_FILENO, TIOCGWINSZ, &__tm_wstruct);
*w = __tm_wstruct.ws_col;
*h = __tm_wstruct.ws_row;
}
void tm_setcan(char f)
{
__tm_tstruct.c_lflag &= ~((!f) ^ ICANON); // if f then set else unset
tcsetattr(0, TCSANOW, &__tm_tstruct);
}
void tm_setecho(char f)
{
__tm_tstruct.c_lflag &= ~((!f) ^ ECHO);
tcsetattr(0, TCSANOW, &__tm_tstruct);
}
void tm_setcv(char f)
{
f?fputs(TM_CRVIS, stdout):fputs(TM_CRIVIS,stdout);
}
void tm_setxy(unsigned int x, unsigned int y)
{
char q[_TM_CLIM];
sprintf(q, TM_ESC "[%u;%uH", y, x);
fputs(q, stdout);
}
void tm_f256(unsigned short int c, char *t)
{
sprintf(t, TM_ESC "[38;5;" "%u" "m", c);
}
void tm_b256(unsigned short int c, char *t)
{
sprintf(t, TM_ESC "[48;5;" "%u" "m", c);
}
void tm_cls()
{
fputs(TM_CLS, stdout);
}