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
|
/* $Id$ */
#include "bbs.h"
#include <termios.h>
/* ----------------------------------------------------- */
/* basic tty control */
/* ----------------------------------------------------- */
void
init_tty(void)
{
struct termios tty_state, tty_new;
if (tcgetattr(1, &tty_state) < 0) {
syslog(LOG_ERR, "tcgetattr(): %m");
return;
}
memcpy(&tty_new, &tty_state, sizeof(tty_new));
tty_new.c_lflag &= ~(ICANON | ECHO | ISIG);
/*
* tty_new.c_cc[VTIME] = 0; tty_new.c_cc[VMIN] = 1;
*/
#if 1
cfmakeraw(&tty_new);
tty_new.c_cflag &= ~(CSIZE|PARENB);
tty_new.c_cflag |= CS8;
tcsetattr(1, TCSANOW, &tty_new);
#else
tcsetattr(1, TCSANOW, &tty_new);
system("stty raw -echo");
#endif
}
/* ----------------------------------------------------- */
/* init tty control code */
/* ----------------------------------------------------- */
#define TERMCOMSIZE (40)
static void
sig_term_resize(int sig)
{
struct winsize newsize;
Signal(SIGWINCH, SIG_IGN); /* Don't bother me! */
ioctl(0, TIOCGWINSZ, &newsize);
term_resize(newsize.ws_col, newsize.ws_row);
}
void term_resize(int w, int h)
{
int dorefresh = 0;
Signal(SIGWINCH, SIG_IGN); /* Don't bother me! */
/* make sure reasonable size */
h = MAX(24, MIN(100, h));
w = MAX(80, MIN(200, w));
if (w != t_columns || h != t_lines)
{
// invoke terminal system resize
resizeterm(h, w);
t_lines = h;
t_columns = w;
dorefresh = 1;
}
scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */
b_lines = t_lines - 1;
p_lines = t_lines - 4;
Signal(SIGWINCH, sig_term_resize);
if (dorefresh)
{
redrawwin();
refresh();
}
}
int
term_init(void)
{
Signal(SIGWINCH, sig_term_resize);
return YEA;
}
void
bell(void)
{
const char c = Ctrl('G');
write(1, &c, 1);
}
|