Skip to content

Commit 104ef4d

Browse files
committed
ensure VERASE setting restored on exit
1 parent f0e9125 commit 104ef4d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kirc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ kbhit(void) {
2929

3030
int byteswaiting;
3131
struct termios term;
32-
term.c_cc[VERASE] = 127;
3332
tcgetattr(0, &term);
3433
fd_set fds;
3534
struct timespec ts = {0};
@@ -54,9 +53,7 @@ raw(char *fmt, ...) {
5453
va_start(ap, fmt);
5554
vsnprintf(sbuf, BUFF, fmt, ap);
5655
va_end(ap);
57-
5856
if (verb) printf("<< %s", sbuf);
59-
6057
write(conn, sbuf, strlen(sbuf));
6158
}
6259

@@ -162,7 +159,6 @@ main(int argc, char **argv) {
162159

163160
int fd[2], cval;
164161

165-
166162
while ((cval = getopt(argc, argv, "s:p:n:k:c:w:W:vV")) != -1) {
167163
switch (cval) {
168164
case 'v' : puts("kirc 0.0.1"); break;
@@ -200,23 +196,27 @@ main(int argc, char **argv) {
200196
pars(sl, sbuf);
201197
if (read(fd[0], u, cmax) > 0) {
202198
for (i = 0; u[i] != '\n'; i++) continue;
203-
if (u[0] != ':') {
204-
raw("%-*.*s\r\n", i, i, u);
205-
printf("\x1b[1A\x1b[K\x1b[36m%-*.*s\x1b[0m\n", i, i, u);
206-
}
199+
if (u[0] != ':') raw("%-*.*s\r\n", i, i, u);
207200
}
208201
}
209-
printf("%*s \x1b[31mpress <RETURN> key to quit...\x1b[0m", gutl, " ");
202+
printf("%*s \x1b[31mpress <RETURN> key to exit\x1b[0m\n", gutl, " ");
210203
}
211204
else {
212205
char usrin[cmax], val1[cmax], val2[20];
206+
struct termios tp, save;
207+
208+
tcgetattr(STDIN_FILENO, &tp);
209+
save = tp;
210+
tp.c_cc[VERASE] = 127;
213211

214212
while (waitpid(pid, NULL, WNOHANG) == 0) {
215213
while (!kbhit() && waitpid(pid, NULL, WNOHANG) == 0) {
216214
dprintf(fd[1], ":\n");
217215
}
218216

217+
tcsetattr(STDIN_FILENO, TCSANOW, &tp);
219218
fgets(usrin, cmax, stdin);
219+
tcsetattr(STDIN_FILENO, TCSANOW, &save);
220220

221221
if (usrin[0] == ':') {
222222
switch (usrin[1]) {

0 commit comments

Comments
 (0)