]>
git.gir.st - minesVIiper.git/blob - mines.c
1 /*******************************************************************************
3 By Tobias Girstmair, 2015 - 2018
6 (see ./minesviiper -h for full list of options)
8 MOUSE MODE: - left click to open and choord
9 - right click to flag/unflag
10 VI MODE: - hjkl to move cursor left/down/up/right
11 - o/space to open and choord
13 - (see `./minesviiper -h' for all keybindings)
15 GNU GPL v3, see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt
16 *******************************************************************************/
19 #define _POSIX_C_SOURCE 2 /*for getopt, sigaction in c99*/
24 #include <sys/ioctl.h>
39 #define MIN(a,b) (a>b?b:a)
40 #define MAX(a,b) (a>b?a:b)
41 #define CLAMP(a,m,M) (a<m?m:(a>M?M:a))
42 #define printm(n, s) for (int _loop = 0; _loop < n; _loop++) fputs (s, stdout)
43 #define print(str) fputs (str?str:"", stdout)
44 #define EMOT(e) op.scheme->emoticons[EMOT_ ## e]
45 #define BORDER(l, c) op.scheme->border[B_ ## l][B_ ## c]
46 #define CW op.scheme->cell_width /* for brevity */
52 int main (int argc
, char** argv
) {
57 op
.scheme
= &symbols_mono
;
62 opterr
= 0; /* don't print message on unrecognized option */
63 while ((optget
= getopt (argc
, argv
, "+hnfqcdx")) != -1) {
65 case 'n': op
.mode
= NOFLAG
; break;
66 case 'f': op
.mode
= FLAG
; break; /*default*/
67 case 'q': op
.mode
= QUESM
; break;
68 case 'c': op
.scheme
= &symbols_col1
; break;
69 case 'd': op
.scheme
= &symbols_doublewidth
; break;
72 fprintf (stderr
, SHORTHELP LONGHELP
, argv
[0]);
73 return !(optget
=='h');
76 /* end parse options*/
77 if (optind
< argc
) { /* parse Fieldspec */
78 if (parse_fieldspec (argv
[optind
])) {
79 fprintf (stderr
, "FIELDSPEC: WxH[xM]"
80 " (width 'x' height 'x' mines)\n");
84 /* check boundaries */
85 if (f
.m
> (f
.w
-1) * (f
.h
-1)) {
86 f
.m
= (f
.w
-1) * (f
.h
-1);
87 fprintf (stderr
, "too many mines. reduced to %d.\r\n", f
.m
);
94 f
.c
= alloc_array (f
.h
, f
.w
);
105 struct line_col markers
[26];
106 for (int i
=26; i
; markers
[--i
].l
= -1);
108 /* setup the screen: */
111 /* save cursor and switch to alternate screen */
112 printf ("\033[s\033[?47h");
113 /* reset cursor, clear screen */
114 printf ("\033[H\033[J");
116 /* swich charset, if necessary */
117 if (op
.scheme
->init_seq
!= NULL
) print (op
.scheme
->init_seq
);
119 show_minefield (NORMAL
);
121 /* enable mouse, hide cursor */
122 printf ("\033[?1000h\033[?25l");
126 unsigned char mouse
[3];
128 action
= getch(mouse
);
131 if (g
.s
== MODE_OPEN
||
132 f
.c
[g
.p
[0]][g
.p
[1]].o
== OPENED
) {
133 switch (do_uncover(&is_newgame
)) {
134 case GAME_LOST
: goto lose
;
135 case GAME_WON
: goto win
;
137 } else if (g
.s
== MODE_FLAG
) {
138 flag_square (g
.p
[0], g
.p
[1]);
139 } else if (g
.s
== MODE_QUESM
) {
140 quesm_square (g
.p
[0], g
.p
[1]);
144 g
.s
= (g
.s
+1)%(op
.mode
+1);
145 show_minefield (cheatmode
?SHOWMINES
:NORMAL
);
147 case CTRSEQ_MOUSE_LEFT
:
148 if (clicked_emoticon(mouse
)) {
152 if (screen2field_c (mouse
[1]) < 0 ||
153 screen2field_c (mouse
[1]) >= f
.w
||
154 screen2field_l (mouse
[2]) < 0 ||
155 screen2field_l (mouse
[2]) >= f
.h
) break;
156 g
.p
[0] = screen2field_l (mouse
[2]);
157 g
.p
[1] = screen2field_c (mouse
[1]);
160 switch (do_uncover(&is_newgame
)) {
161 case GAME_LOST
: goto lose
;
162 case GAME_WON
: goto win
;
165 case CTRSEQ_MOUSE_RIGHT
:
166 if (screen2field_c (mouse
[1]) < 0 ||
167 screen2field_c (mouse
[1]) >= f
.w
||
168 screen2field_l (mouse
[2]) < 0 ||
169 screen2field_l (mouse
[2]) >= f
.h
) break;
170 g
.p
[0] = screen2field_l (mouse
[2]);
171 g
.p
[1] = screen2field_c (mouse
[1]);
173 case 'i': flag_square (g
.p
[0], g
.p
[1]); break;
174 case '?':quesm_square (g
.p
[0], g
.p
[1]); break;
175 case CTRSEQ_CURSOR_LEFT
:
176 case 'h': move_hi (g
.p
[0], g
.p
[1]-1 ); break;
177 case CTRSEQ_CURSOR_DOWN
:
178 case 'j': move_hi (g
.p
[0]+1, g
.p
[1] ); break;
179 case CTRSEQ_CURSOR_UP
:
180 case 'k': move_hi (g
.p
[0]-1, g
.p
[1] ); break;
181 case CTRSEQ_CURSOR_RIGHT
:
182 case 'l': move_hi (g
.p
[0], g
.p
[1]+1 ); break;
183 case 'w': to_next_boundary (g
.p
[0], g
.p
[1], '>'); break;
184 case 'b': to_next_boundary (g
.p
[0], g
.p
[1], '<'); break;
185 case 'u': to_next_boundary (g
.p
[0], g
.p
[1], '^'); break;
186 case 'd': to_next_boundary (g
.p
[0], g
.p
[1], 'v'); break;
187 case '0': /* fallthrough */
188 case '^': move_hi (g
.p
[0], 0 ); break;
189 case '$': move_hi (g
.p
[0], f
.w
-1 ); break;
190 case 'g': move_hi (0, g
.p
[1] ); break;
191 case 'G': move_hi (f
.h
-1, g
.p
[1] ); break;
192 case 'z': move_hi (f
.h
/2, f
.w
/2); break;
194 action
= tolower(getch(mouse
));
195 if (action
< 'a' || action
> 'z') break;/*out of bound*/
196 markers
[action
-'a'].l
= g
.p
[0];
197 markers
[action
-'a'].c
= g
.p
[1];
199 case'\'': /* fallthrough */
201 action
= tolower(getch(mouse
));
202 if (action
< 'a' || action
> 'z' /* out of bound or */
203 || markers
[action
-'a'].l
== -1) break; /* unset */
204 move_hi (markers
[action
-'a'].l
, markers
[action
-'a'].c
);
206 case 'r': /* start a new game */
211 case '\014': /* Ctrl-L -- redraw */
212 show_minefield (NORMAL
);
217 fill_minefield (-1, -1);
220 show_minefield (cheatmode
?NORMAL
:SHOWMINES
);
221 cheatmode
= !cheatmode
;
226 win
: g
.o
= GAME_WON
; goto endgame
;
227 lose
: g
.o
= GAME_LOST
; goto endgame
;
229 timer_setup(0); /* stop timer */
230 show_minefield (SHOWMINES
);
233 unsigned char mouse
[3];
234 gotaction
= getch(mouse
);
235 if (gotaction
==CTRSEQ_MOUSE_LEFT
&& clicked_emoticon(mouse
)) {
238 } else if (gotaction
== 'r') {
241 } else if (gotaction
== 'q') {
251 printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */
252 print (op
.scheme
->reset_seq
); /* reset charset, if necessary */
253 printf ("\033[?47l\033[u"); /*revert to primary screen, restore cursor*/
258 /* I haven't won as long as a cell exists, that
259 - I haven't opened, and
261 int everything_opened (void) {
262 for (int row
= 0; row
< f
.h
; row
++)
263 for (int col
= 0; col
< f
.w
; col
++)
264 if (f
.c
[row
][col
].o
== CLOSED
&&
265 f
.c
[row
][col
].m
== NO_MINE
) return 0;
269 void print_help(char* progname
) {
272 int wait_mouse_up (int l
, int c
) {
273 unsigned char mouse2
[3];
278 move_ph (1, field2screen_c (f
.w
/2)-1); print (EMOT(OHH
));
280 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
281 /* show a pushed-in button if cursor is on minefield */
282 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
283 fputs (op
.scheme
->mouse_highlight
, stdout
);
287 if (getctrlseq (mouse2
) == CTRSEQ_MOUSE
) {
288 /* ignore mouse wheel events: */
289 if (mouse2
[0] & 0x40) continue;
291 else if (mouse2
[0]&3 == 3) level
--; /* release event */
292 else level
++; /* another button pressed */
296 move_ph (1, field2screen_c (f
.w
/2)-1); print (get_emoticon());
298 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
299 partial_show_minefield (l
, c
, NORMAL
);
301 c2
= screen2field_c(mouse2
[1]);
302 l2
= screen2field_l(mouse2
[2]);
303 return ((l2
== l
) && (c2
== c
));
306 int choord_square (int line
, int col
) {
307 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
308 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
309 if (f
.c
[l
][c
].f
!= FLAG
) {
310 if (uncover_square (l
, c
))
319 int uncover_square (int l
, int c
) {
320 f
.c
[l
][c
].o
= OPENED
;
321 f
.c
[l
][c
].f
= NOFLAG
; /*must not be QUESM, otherwise rendering issues*/
322 partial_show_minefield (l
, c
, NORMAL
);
325 f
.c
[l
][c
].m
= DEATH_MINE
;
329 /* check for chording */
330 if (f
.c
[l
][c
].n
== 0) {
331 for (int choord_l
= -1; choord_l
<= 1; choord_l
++) {
332 for (int choord_c
= -1; choord_c
<= 1; choord_c
++) {
333 int newl
= l
+ choord_l
;
334 int newc
= c
+ choord_c
;
335 if (newl
>= 0 && newl
< f
.h
&&
336 newc
>= 0 && newc
< f
.w
&&
337 f
.c
[newl
][newc
].o
== CLOSED
&&
338 uncover_square (newl
, newc
)) {
348 void flag_square (int l
, int c
) {
349 static char modechar
[] = {'*', '!', '?'};
351 if (f
.c
[l
][c
].o
!= CLOSED
) return;
352 /* cycle through flag/quesm/noflag: */
353 f
.c
[l
][c
].f
= (f
.c
[l
][c
].f
+ 1) % (op
.mode
+ 1);
354 if (f
.c
[l
][c
].f
==FLAG
) g
.f
++;
355 else if ((op
.mode
==FLAG
&& f
.c
[l
][c
].f
==NOFLAG
) ||
356 (op
.mode
==QUESM
&& f
.c
[l
][c
].f
==QUESM
)) g
.f
--;
357 partial_show_minefield (l
, c
, NORMAL
);
358 move_ph (1, op
.scheme
->cell_width
);
359 printf ("[%03d%c]", f
.m
- g
.f
, modechar
[g
.s
]);
362 void quesm_square (int l
, int c
) {
363 /* toggle question mark / none. won't turn flags into question marks.
364 unlike flag_square, this function doesn't respect `-q'. */
365 if (f
.c
[l
][c
].o
!= CLOSED
) return;
366 else if (f
.c
[l
][c
].f
== NOFLAG
) f
.c
[l
][c
].f
= QUESM
;
367 else if (f
.c
[l
][c
].f
== QUESM
) f
.c
[l
][c
].f
= NOFLAG
;
368 partial_show_minefield (l
, c
, NORMAL
);
371 int do_uncover (int* is_newgame
) {
374 fill_minefield (g
.p
[0], g
.p
[1]);
378 if (f
.c
[g
.p
[0]][g
.p
[1]].f
== FLAG
) return GAME_INPROGRESS
;
379 if (f
.c
[g
.p
[0]][g
.p
[1]].o
== CLOSED
) {
380 if (uncover_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
381 } else if (get_neighbours (g
.p
[0], g
.p
[1], 1) == 0) {
382 if (choord_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
384 if (everything_opened()) return GAME_WON
;
386 return GAME_INPROGRESS
;
389 void fill_minefield (int l
, int c
) {
393 int line
= rand() % f
.h
;
394 int col
= rand() % f
.w
;
396 if (f
.c
[line
][col
].m
) {
397 /* skip if field already has a mine */
399 } else if ((line
== l
) && (col
== c
)) {
400 /* don't put a mine on the already opened (first click) field */
404 f
.c
[line
][col
].m
= STD_MINE
;
408 /* precalculate neighbours */
409 for (int l
=0; l
< f
.h
; l
++)
410 for (int c
=0; c
< f
.w
; c
++)
411 f
.c
[l
][c
].n
= get_neighbours (l
, c
, NORMAL
);
414 void move_ph (int line
, int col
) {
415 /* move printhead to zero-indexed position */
416 printf ("\033[%d;%dH", line
+1, col
+1);
419 void move_hi (int l
, int c
) {
420 /* move cursor and highlight to absolute coordinates */
422 partial_show_minefield (g
.p
[0], g
.p
[1], NORMAL
);
424 g
.p
[0] = CLAMP(l
, 0, f
.h
-1);
425 g
.p
[1] = CLAMP(c
, 0, f
.w
-1);
426 move_ph (g
.p
[0]+LINE_OFFSET
, field2screen_c(g
.p
[1]));
428 print("\033[7m"); /* reverse video */
429 partial_show_minefield (g
.p
[0], g
.p
[1], HIGHLIGHT
);
430 print("\033[0m"); /* un-invert */
433 /* to_next_boundary(): move into the supplied direction until a change in open-
434 state or flag-state is found and move there. falls back to BIG_MOVE. */
435 #define FIND_NEXT(X, L, C, L1, C1, MAX, OP) do {\
436 new_ ## X OP ## = BIG_MOVE;\
437 for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\
438 if (((f.c[L ][C ].o<<2) + f.c[L ][C ].f) \
439 != ((f.c[L1][C1].o<<2) + f.c[L1][C1].f)) {\
444 void to_next_boundary (int l
, int c
, char direction
) {
448 case '>': FIND_NEXT(c
, l
, i
, l
, i
+1, w
, +); break;
449 case '<': FIND_NEXT(c
, l
, i
, l
, i
-1, w
, -); break;
450 case '^': FIND_NEXT(l
, i
, c
, i
-1, c
, h
, -); break;
451 case 'v': FIND_NEXT(l
, i
, c
, i
+1, c
, h
, +); break;
454 move_hi (new_l
, new_c
);
458 char* cell2schema (int l
, int c
, int mode
) {
459 struct minecell cell
= f
.c
[l
][c
];
461 if (mode
== SHOWMINES
) return (
462 cell
.f
== FLAG
&& cell
.m
? op
.scheme
->field_flagged
:
463 cell
.f
== FLAG
&& !cell
.m
? op
.scheme
->mine_wrongf
:
464 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
465 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
466 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
467 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
469 cell
.f
== FLAG
? op
.scheme
->field_flagged
:
470 cell
.f
== QUESM
? op
.scheme
->field_question
:
471 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
472 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
473 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
474 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
477 void partial_show_minefield (int l
, int c
, int mode
) {
478 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
480 print (cell2schema(l
, c
, mode
));
483 char* get_emoticon(void) {
484 return g
.o
==GAME_WON
? EMOT(WON
):
485 g
.o
==GAME_LOST
? EMOT(DEAD
):
489 /* https://zserge.com/blog/c-for-loop-tricks.html */
490 #define print_line(which) \
491 for (int _break = (printf("%s", BORDER(which,LEFT)), 1); _break; \
492 _break = 0, printf("%s\r\n", BORDER(which,RIGHT)))
493 #define print_border(which, width) \
494 print_line(which) printm (width, BORDER(which,MIDDLE))
495 void show_minefield (int mode
) {
496 int dtime
= difftime (time(NULL
), g
.t
)*!!g
.t
;
497 int half_spaces
= f
.w
*op
.scheme
->cell_width
/2;
498 int left_spaces
= MAX(0,half_spaces
-7-(f
.m
-g
.f
>999));
499 int right_spaces
= MAX(0,half_spaces
-6-(dtime
>999));
500 static char modechar
[] = {'*', '!', '?'};
504 print_border(TOP
, f
.w
);
506 printf("[%03d%c]%*s%s%*s[%03d]",
507 /* [ */ f
.m
- g
.f
, modechar
[g
.s
], /* ] */
508 left_spaces
,"", get_emoticon(), right_spaces
,"",
509 /* [ */ dtime
/* ] */);
511 print_border(DIVIDER
, f
.w
);
513 for (int l
= 0; l
< f
.h
; l
++) print_line(FIELD
)
514 printm (f
.w
, cell2schema(l
, _loop
, mode
));
515 print_border(BOTTOM
, f
.w
);
518 int get_neighbours (int line
, int col
, int reduced_mode
) {
519 /* counts mines surrounding a square
520 modes: 0=normal; 1=reduced */
524 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
525 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
526 if (!l
&& !c
) continue;
528 count
+= !!f
.c
[l
][c
].m
;
529 count
-= reduced_mode
* f
.c
[l
][c
].f
==FLAG
;
535 struct minecell
** alloc_array (int lines
, int cols
) {
536 struct minecell
** a
= malloc (lines
* sizeof(struct minecell
*));
537 if (a
== NULL
) return NULL
;
538 for (int l
= 0; l
< lines
; l
++) {
539 a
[l
] = calloc (cols
, sizeof(struct minecell
));
540 if (a
[l
] == NULL
) goto unalloc
;
545 for (int l
= 0; l
< lines
; l
++)
550 void free_field (void) {
551 if (f
.c
== NULL
) return;
552 for (int l
= 0; l
< f
.h
; l
++) {
560 int screen2field_l (int l
) {
561 return (l
-LINE_OFFSET
) - 1;
563 int screen2field_c (int c
) {
564 /* this depends on the cell width and only works when it is 1 or 2. */
565 return (c
-COL_OFFSET
+1 - 2*(CW
%2))/2 - CW
/2;
567 int field2screen_c (int c
) {
568 return (CW
*c
+COL_OFFSET
- (CW
%2));
570 int clicked_emoticon (unsigned char* mouse
) {
571 return (mouse
[2] == LINE_OFFSET
-1 && (
572 mouse
[1] == f
.w
+COL_OFFSET
||
573 mouse
[1] == f
.w
+COL_OFFSET
+1));
582 int getctrlseq (unsigned char* buf
) {
585 int offset
= 0x20; /* never sends control chars as data */
586 while ((c
= getchar()) != EOF
) {
590 case '\033': state
=ESC_SENT
; break;
596 case '[': state
=CSI_SENT
; break;
597 default: return CTRSEQ_INVALID
;
602 case 'A': return CTRSEQ_CURSOR_UP
;
603 case 'B': return CTRSEQ_CURSOR_DOWN
;
604 case 'C': return CTRSEQ_CURSOR_RIGHT
;
605 case 'D': return CTRSEQ_CURSOR_LEFT
;
606 case 'M': state
=MOUSE_EVENT
; break;
607 default: return CTRSEQ_INVALID
;
612 buf
[1] = getchar() - offset
;
613 buf
[2] = getchar() - offset
;
616 return CTRSEQ_INVALID
;
622 int getch(unsigned char* buf
) {
623 /* returns a character, EOF, or constant for an escape/control sequence - NOT
624 compatible with the ncurses implementation of same name */
625 int action
= getctrlseq(buf
);
629 l
= screen2field_l (buf
[2]);
630 c
= screen2field_c (buf
[1]);
632 if (buf
[0] > 3) break; /* ignore all but left/middle/right/up */
633 int success
= wait_mouse_up(l
, c
);
635 /* mouse moved while pressed: */
636 if (!success
) return CTRSEQ_INVALID
;
639 case 0: return CTRSEQ_MOUSE_LEFT
;
640 case 1: return CTRSEQ_MOUSE_MIDDLE
;
641 case 2: return CTRSEQ_MOUSE_RIGHT
;
648 int parse_fieldspec(char* str
) {
649 /* parses the FIELDSPEC (WxHxM); returns 1 on error */
650 int n
= sscanf (str
, "%dx%dx%d", &f
.w
, &f
.h
, &f
.m
);
652 ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &w
);
654 /* clamp field size to terminal size and mouse maximum: */
655 if (COL_OFFSET
+ f
.w
*CW
+ COL_OFFSET
> w
.ws_col
)
656 f
.w
= w
.ws_col
/CW
- (COL_OFFSET
+COL_OFFSET
);
657 if (LINE_OFFSET
+ f
.h
+ LINES_AFTER
> w
.ws_row
)
658 f
.h
= w
.ws_row
- (LINE_OFFSET
+LINES_AFTER
);
659 if (COL_OFFSET
+ f
.w
*CW
> MOUSE_MAX
)
660 f
.w
= MOUSE_MAX
/CW
- COL_OFFSET
;
661 if (LINE_OFFSET
+ f
.h
> MOUSE_MAX
)
662 f
.h
= MOUSE_MAX
- LINE_OFFSET
;
665 return 1; /* error */
667 if (f
.w
< 30) f
.m
= f
.w
*f
.h
*.15625;
668 else f
.m
= f
.w
*f
.h
*.20625;
674 void timer_setup (int enable
) {
675 static struct itimerval tbuf
;
676 tbuf
.it_interval
.tv_sec
= 1;
677 tbuf
.it_interval
.tv_usec
= 0;
681 tbuf
.it_value
.tv_sec
= 1;
682 tbuf
.it_value
.tv_usec
= 0;
683 if (setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1) {
688 tbuf
.it_value
.tv_sec
= 0;
689 tbuf
.it_value
.tv_usec
= 0;
690 if ( setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1 ) {
698 void signal_setup (void) {
699 struct sigaction saction
;
701 saction
.sa_handler
= signal_handler
;
702 sigemptyset(&saction
.sa_mask
);
703 saction
.sa_flags
= 0;
704 if (sigaction(SIGALRM
, &saction
, NULL
) < 0 ) {
709 if (sigaction(SIGINT
, &saction
, NULL
) < 0 ) {
715 void signal_handler (int signum
) {
719 dtime
= difftime (time(NULL
), g
.t
);
720 move_ph (1, f
.w
*CW
-(CW
%2)-3-(dtime
>999));
721 printf ("[%03d]", g
.t
?dtime
:0);
728 /* http://users.csc.calpoly.edu/~phatalsk/357/lectures/code/sigalrm.c */
729 void raw_mode(int mode
) {
730 static struct termios saved_term_mode
;
731 struct termios raw_term_mode
;
734 tcgetattr(STDIN_FILENO
, &saved_term_mode
);
735 raw_term_mode
= saved_term_mode
;
736 raw_term_mode
.c_lflag
&= ~(ICANON
| ECHO
);
737 raw_term_mode
.c_cc
[VMIN
] = 1 ;
738 raw_term_mode
.c_cc
[VTIME
] = 0;
739 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &raw_term_mode
);
741 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &saved_term_mode
);