]>
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 */
53 int main (int argc
, char** argv
) {
58 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');
75 } if (optind
< argc
) { /* parse Fieldspec */
76 if (parse_fieldspec (argv
[optind
])) {
77 fprintf (stderr
, "FIELDSPEC: WxH[xM]"
78 " (width 'x' height 'x' mines)\n");
87 /* check boundaries */
88 if (f
.m
> (f
.w
-1) * (f
.h
-1)) {
89 move_ph (LINE_OFFSET
+f
.h
+LINES_AFTER
-1,0);
90 f
.m
= (f
.w
-1) * (f
.h
-1);
91 fprintf (stdout
, "too many mines. reduced to %d.\r\n", f
.m
); //TODO: doesn't show up
96 switch (minesviiper()) {
97 case GAME_NEW
: goto newgame
;
98 case GAME_WON
: g
.o
= GAME_WON
; break;
99 case GAME_LOST
:g
.o
= GAME_LOST
;break;
102 timer_setup(0); /* stop timer */
103 show_minefield (SHOWMINES
);
105 switch(getch_wrapper()) {
106 case WRAPPER_EMOTICON
:
118 int minesviiper(void) {
119 f
.c
= alloc_array (f
.h
, f
.w
); /* TODO: just memset it */
120 g
= (const struct game
){0}; /* reset all game-specific parameters */
122 show_minefield (NORMAL
);
125 switch (getch_wrapper()) {
127 if (g
.s
== MODE_OPEN
|| f
.c
[g
.p
[0]][g
.p
[1]].o
== OPENED
)
129 if (g
.s
== MODE_FLAG
)
131 if (g
.s
== MODE_QUESM
)
135 g
.s
= (g
.s
+1)%(op
.mode
+1);
136 show_minefield (g
.c
?SHOWMINES
:NORMAL
);
139 case CTRSEQ_MOUSE_LEFT
:
141 switch (do_uncover(&(g
.n
))) {
142 case GAME_LOST
: return GAME_LOST
;
143 case GAME_WON
: return GAME_WON
;
147 case CTRSEQ_MOUSE_RIGHT
:
148 case 'i': flag_square (g
.p
[0], g
.p
[1]); break;
150 case '?':quesm_square (g
.p
[0], g
.p
[1]); break;
151 case CTRSEQ_CURSOR_LEFT
:
152 case 'h': move_hi (g
.p
[0], g
.p
[1]-1); break;
153 case CTRSEQ_CURSOR_DOWN
:
154 case 'j': move_hi (g
.p
[0]+1, g
.p
[1] ); break;
155 case CTRSEQ_CURSOR_UP
:
156 case 'k': move_hi (g
.p
[0]-1, g
.p
[1] ); break;
157 case CTRSEQ_CURSOR_RIGHT
:
158 case 'l': move_hi (g
.p
[0], g
.p
[1]+1); break;
159 case 'w': to_next_boundary (g
.p
[0], g
.p
[1], '>'); break;
160 case 'b': to_next_boundary (g
.p
[0], g
.p
[1], '<'); break;
161 case 'u': to_next_boundary (g
.p
[0], g
.p
[1], '^'); break;
162 case 'd': to_next_boundary (g
.p
[0], g
.p
[1], 'v'); break;
163 case '0': /* fallthrough */
164 case '^': move_hi (g
.p
[0], 0 ); break;
165 case '$': move_hi (g
.p
[0], f
.w
-1 ); break;
166 case 'g': move_hi (0, g
.p
[1] ); break;
167 case 'G': move_hi (f
.h
-1, g
.p
[1] ); break;
168 case 'z': move_hi (f
.h
/2, f
.w
/2); break;
169 case 'm': set_mark(); break;
170 case'\'': /* fallthrough */
171 case '`': jump_mark(); break;
172 case WRAPPER_EMOTICON
:
173 case 'r': return GAME_NEW
;
174 case 'q': return GAME_QUIT
;
175 case CTRL_
'L': show_minefield (NORMAL
); break;
177 if (g
.n
== GAME_NEW
) break; /* must open a cell first */
178 show_minefield (g
.c
?NORMAL
:SHOWMINES
);
191 /* I haven't won as long as a cell exists, that
192 - I haven't opened, and
194 int everything_opened (void) {
195 for (int row
= 0; row
< f
.h
; row
++)
196 for (int col
= 0; col
< f
.w
; col
++)
197 if (f
.c
[row
][col
].o
== CLOSED
&&
198 f
.c
[row
][col
].m
== NO_MINE
) return 0;
202 int wait_mouse_up (int l
, int c
) { /* TODO: should not take minefield-coords but absolute ones */
203 unsigned char mouse2
[3];
208 move_ph (1, field2screen_c (f
.w
/2)-1); print (EMOT(OHH
));
210 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
211 /* show a pushed-in button if cursor is on minefield */
212 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
213 fputs (op
.scheme
->mouse_highlight
, stdout
);
217 if (getctrlseq (mouse2
) == CTRSEQ_MOUSE
) {
218 /* ignore mouse wheel events: */
219 if (mouse2
[0] & 0x40) continue;
221 else if (mouse2
[0]&3 == 3) level
--; /* release event */
222 else level
++; /* another button pressed */
226 move_ph (1, field2screen_c (f
.w
/2)-1); print (get_emoticon());
228 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
229 partial_show_minefield (l
, c
, NORMAL
);
231 c2
= screen2field_c(mouse2
[1]);
232 l2
= screen2field_l(mouse2
[2]);
233 return ((l2
== l
) && (c2
== c
));
236 int choord_square (int line
, int col
) {
237 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
238 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
239 if (f
.c
[l
][c
].f
!= FLAG
) {
240 if (uncover_square (l
, c
))
249 int uncover_square (int l
, int c
) {
250 f
.c
[l
][c
].o
= OPENED
;
251 f
.c
[l
][c
].f
= NOFLAG
; /*must not be QUESM, otherwise rendering issues*/
252 partial_show_minefield (l
, c
, NORMAL
);
255 f
.c
[l
][c
].m
= DEATH_MINE
;
259 /* check for chording */
260 if (f
.c
[l
][c
].n
== 0) {
261 for (int choord_l
= -1; choord_l
<= 1; choord_l
++) {
262 for (int choord_c
= -1; choord_c
<= 1; choord_c
++) {
263 int newl
= l
+ choord_l
;
264 int newc
= c
+ choord_c
;
265 if (newl
>= 0 && newl
< f
.h
&&
266 newc
>= 0 && newc
< f
.w
&&
267 f
.c
[newl
][newc
].o
== CLOSED
&&
268 uncover_square (newl
, newc
)) {
278 void flag_square (int l
, int c
) {
279 static char modechar
[] = {'*', '!', '?'};
281 if (f
.c
[l
][c
].o
!= CLOSED
) return;
282 /* cycle through flag/quesm/noflag: */
283 f
.c
[l
][c
].f
= (f
.c
[l
][c
].f
+ 1) % (op
.mode
+ 1);
284 if (f
.c
[l
][c
].f
==FLAG
) g
.f
++;
285 else if ((op
.mode
==FLAG
&& f
.c
[l
][c
].f
==NOFLAG
) ||
286 (op
.mode
==QUESM
&& f
.c
[l
][c
].f
==QUESM
)) g
.f
--;
287 partial_show_minefield (l
, c
, NORMAL
);
288 move_ph (1, op
.scheme
->cell_width
);
289 printf ("[%03d%c]", f
.m
- g
.f
, modechar
[g
.s
]);
292 void quesm_square (int l
, int c
) {
293 /* toggle question mark / none. won't turn flags into question marks.
294 unlike flag_square, this function doesn't respect `-q'. */
295 if (f
.c
[l
][c
].o
!= CLOSED
) return;
296 else if (f
.c
[l
][c
].f
== NOFLAG
) f
.c
[l
][c
].f
= QUESM
;
297 else if (f
.c
[l
][c
].f
== QUESM
) f
.c
[l
][c
].f
= NOFLAG
;
298 partial_show_minefield (l
, c
, NORMAL
);
301 int do_uncover (int* is_newgame
) {
302 if (*is_newgame
== GAME_NEW
) {
303 *is_newgame
= GAME_INPROGRESS
;
304 fill_minefield (g
.p
[0], g
.p
[1]);
308 if (f
.c
[g
.p
[0]][g
.p
[1]].f
== FLAG
) return GAME_INPROGRESS
;
309 if (f
.c
[g
.p
[0]][g
.p
[1]].o
== CLOSED
) {
310 if (uncover_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
311 } else if (get_neighbours (g
.p
[0], g
.p
[1], 1) == 0) {
312 if (choord_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
314 if (everything_opened()) return GAME_WON
;
316 return GAME_INPROGRESS
;
319 void set_mark(void) {
320 int mark
= tolower(getch_wrapper());
321 if (mark
< 'a' || mark
> 'z') return; /*out of bound*/
323 g
.m
[mark
-'a'].l
= g
.p
[0];
324 g
.m
[mark
-'a'].c
= g
.p
[1];
328 void jump_mark(void) {
329 int mark
= tolower(getch_wrapper());
330 /* check bounds and if set: */
331 if (mark
< 'a' || mark
> 'z' || !g
.m
[mark
-'a'].s
) return;
332 move_hi (g
.m
[mark
-'a'].l
, g
.m
[mark
-'a'].c
);
335 void fill_minefield (int l
, int c
) {
339 int line
= rand() % f
.h
;
340 int col
= rand() % f
.w
;
342 if (f
.c
[line
][col
].m
) {
343 /* skip if field already has a mine */
345 } else if ((line
== l
) && (col
== c
)) {
346 /* don't put a mine on the already opened (first click) field */
350 f
.c
[line
][col
].m
= STD_MINE
;
354 /* precalculate neighbours */
355 for (int l
=0; l
< f
.h
; l
++)
356 for (int c
=0; c
< f
.w
; c
++)
357 f
.c
[l
][c
].n
= get_neighbours (l
, c
, NORMAL
);
360 void move_ph (int line
, int col
) {
361 /* move printhead to zero-indexed position */
362 printf ("\033[%d;%dH", line
+1, col
+1);
365 void move_hi (int l
, int c
) {
366 /* move cursor and highlight to absolute coordinates */
368 partial_show_minefield (g
.p
[0], g
.p
[1], NORMAL
);
370 g
.p
[0] = CLAMP(l
, 0, f
.h
-1);
371 g
.p
[1] = CLAMP(c
, 0, f
.w
-1);
372 move_ph (g
.p
[0]+LINE_OFFSET
, field2screen_c(g
.p
[1]));
374 print("\033[7m"); /* reverse video */
375 partial_show_minefield (g
.p
[0], g
.p
[1], HIGHLIGHT
);
376 print("\033[0m"); /* un-invert */
379 /* to_next_boundary(): move into the supplied direction until a change in open-
380 state or flag-state is found and move there. falls back to BIG_MOVE. */
381 #define FIND_NEXT(X, L, C, L1, C1, MAX, OP) do {\
382 new_ ## X OP ## = BIG_MOVE;\
383 for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\
384 if (((f.c[L ][C ].o<<2) + f.c[L ][C ].f) \
385 != ((f.c[L1][C1].o<<2) + f.c[L1][C1].f)) {\
390 void to_next_boundary (int l
, int c
, char direction
) {
394 case '>': FIND_NEXT(c
, l
, i
, l
, i
+1, w
, +); break;
395 case '<': FIND_NEXT(c
, l
, i
, l
, i
-1, w
, -); break;
396 case '^': FIND_NEXT(l
, i
, c
, i
-1, c
, h
, -); break;
397 case 'v': FIND_NEXT(l
, i
, c
, i
+1, c
, h
, +); break;
400 move_hi (new_l
, new_c
);
404 char* cell2schema (int l
, int c
, int mode
) {
405 struct minecell cell
= f
.c
[l
][c
];
407 if (mode
== SHOWMINES
) return (
408 cell
.f
== FLAG
&& cell
.m
? op
.scheme
->field_flagged
:
409 cell
.f
== FLAG
&& !cell
.m
? op
.scheme
->mine_wrongf
:
410 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
411 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
412 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
413 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
415 cell
.f
== FLAG
? op
.scheme
->field_flagged
:
416 cell
.f
== QUESM
? op
.scheme
->field_question
:
417 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
418 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
419 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
420 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
423 void partial_show_minefield (int l
, int c
, int mode
) {
424 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
426 print (cell2schema(l
, c
, mode
));
429 char* get_emoticon(void) {
430 return g
.o
==GAME_WON
? EMOT(WON
):
431 g
.o
==GAME_LOST
? EMOT(DEAD
):
435 /* https://zserge.com/blog/c-for-loop-tricks.html */
436 #define print_line(which) \
437 for (int _break = (printf("%s", BORDER(which,LEFT)), 1); _break; \
438 _break = 0, printf("%s\r\n", BORDER(which,RIGHT)))
439 #define print_border(which, width) \
440 print_line(which) printm (width, BORDER(which,MIDDLE))
441 void show_minefield (int mode
) {
442 int dtime
= difftime (time(NULL
), g
.t
)*!!g
.t
;
443 int half_spaces
= f
.w
*op
.scheme
->cell_width
/2;
444 int left_spaces
= MAX(0,half_spaces
-7-(f
.m
-g
.f
>999));
445 int right_spaces
= MAX(0,half_spaces
-6-(dtime
>999));
446 static char modechar
[] = {'*', '!', '?'};
450 print_border(TOP
, f
.w
);
452 printf("[%03d%c]%*s%s%*s[%03d]",
453 /* [ */ f
.m
- g
.f
, modechar
[g
.s
], /* ] */
454 left_spaces
,"", get_emoticon(), right_spaces
,"",
455 /* [ */ dtime
/* ] */);
457 print_border(DIVIDER
, f
.w
);
459 for (int l
= 0; l
< f
.h
; l
++) print_line(FIELD
)
460 printm (f
.w
, cell2schema(l
, _loop
, mode
));
461 print_border(BOTTOM
, f
.w
);
464 int get_neighbours (int line
, int col
, int reduced_mode
) {
465 /* counts mines surrounding a square
466 modes: 0=normal; 1=reduced */
470 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
471 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
472 if (!l
&& !c
) continue;
474 count
+= !!f
.c
[l
][c
].m
;
475 count
-= reduced_mode
* f
.c
[l
][c
].f
==FLAG
;
481 struct minecell
** alloc_array (int lines
, int cols
) {
482 free_field (); /* TODO: just memset */
483 struct minecell
** a
= malloc (lines
* sizeof(struct minecell
*));
484 if (a
== NULL
) return NULL
;
485 for (int l
= 0; l
< lines
; l
++) {
486 a
[l
] = calloc (cols
, sizeof(struct minecell
));
487 if (a
[l
] == NULL
) goto unalloc
;
492 for (int l
= 0; l
< lines
; l
++)
497 void free_field (void) {
498 if (f
.c
== NULL
) return;
499 for (int l
= 0; l
< f
.h
; l
++) {
507 int screen2field_l (int l
) {
508 return (l
-LINE_OFFSET
) - 1;
510 int screen2field_c (int c
) {
511 /* this depends on the cell width and only works when it is 1 or 2. */
512 return (c
-COL_OFFSET
+1 - 2*(CW
%2))/2 - CW
/2;
514 int field2screen_c (int c
) {
515 return (CW
*c
+COL_OFFSET
- (CW
%2));
517 int clicked_emoticon (unsigned char* mouse
) {
518 return (mouse
[2] == LINE_OFFSET
-1 && (
519 mouse
[1] == f
.w
+COL_OFFSET
||
520 mouse
[1] == f
.w
+COL_OFFSET
+1));
529 int getctrlseq (unsigned char* buf
) {
532 int offset
= 0x20; /* never sends control chars as data */
533 while ((c
= getchar()) != EOF
) {
537 case '\033': state
=ESC_SENT
; break;
543 case '[': state
=CSI_SENT
; break;
544 default: return CTRSEQ_INVALID
;
549 case 'A': return CTRSEQ_CURSOR_UP
;
550 case 'B': return CTRSEQ_CURSOR_DOWN
;
551 case 'C': return CTRSEQ_CURSOR_RIGHT
;
552 case 'D': return CTRSEQ_CURSOR_LEFT
;
553 case 'M': state
=MOUSE_EVENT
; break;
554 default: return CTRSEQ_INVALID
;
559 buf
[1] = getchar() - offset
;
560 buf
[2] = getchar() - offset
;
563 return CTRSEQ_INVALID
;
569 int getch(unsigned char* buf
) {
570 /* returns a character, EOF, or constant for an escape/control sequence - NOT
571 compatible with the ncurses implementation of same name */
572 int action
= getctrlseq(buf
);
576 l
= screen2field_l (buf
[2]);
577 c
= screen2field_c (buf
[1]);
579 if (buf
[0] > 3) break; /* ignore all but left/middle/right/up */
580 int success
= wait_mouse_up(l
, c
);
582 /* mouse moved while pressed: */
583 if (!success
) return CTRSEQ_INVALID
;
586 case 0: return CTRSEQ_MOUSE_LEFT
;
587 case 1: return CTRSEQ_MOUSE_MIDDLE
;
588 case 2: return CTRSEQ_MOUSE_RIGHT
;
595 int getch_wrapper (void) {
596 unsigned char mouse
[3];
597 int c
= getch(mouse
);
599 if (c
== CTRSEQ_MOUSE_LEFT
|| c
== CTRSEQ_MOUSE_RIGHT
) {
600 if (clicked_emoticon(mouse
))
601 return WRAPPER_EMOTICON
;
603 if (screen2field_c (mouse
[1]) < 0
604 || screen2field_c (mouse
[1]) >= f
.w
605 || screen2field_l (mouse
[2]) < 0
606 || screen2field_l (mouse
[2]) >= f
.h
)
607 return CTRSEQ_INVALID
;
609 g
.p
[0] = screen2field_l (mouse
[2]);
610 g
.p
[1] = screen2field_c (mouse
[1]);
612 return c
; /* CTRSEQ_MOUSE_LEFT || CTRSEQ_MOUSE_RIGHT */
618 int parse_fieldspec(char* str
) {
619 /* parses the FIELDSPEC (WxHxM); returns 1 on error */
620 int n
= sscanf (str
, "%dx%dx%d", &f
.w
, &f
.h
, &f
.m
);
622 ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &w
);
624 /* clamp field size to terminal size and mouse maximum: */
625 if (COL_OFFSET
+ f
.w
*CW
+ COL_OFFSET
> w
.ws_col
)
626 f
.w
= w
.ws_col
/CW
- (COL_OFFSET
+COL_OFFSET
);
627 if (LINE_OFFSET
+ f
.h
+ LINES_AFTER
> w
.ws_row
)
628 f
.h
= w
.ws_row
- (LINE_OFFSET
+LINES_AFTER
);
629 if (COL_OFFSET
+ f
.w
*CW
> MOUSE_MAX
)
630 f
.w
= MOUSE_MAX
/CW
- COL_OFFSET
;
631 if (LINE_OFFSET
+ f
.h
> MOUSE_MAX
)
632 f
.h
= MOUSE_MAX
- LINE_OFFSET
;
635 return 1; /* error */
637 if (f
.w
< 30) f
.m
= f
.w
*f
.h
*.15625;
638 else f
.m
= f
.w
*f
.h
*.20625;
644 void timer_setup (int enable
) {
645 static struct itimerval tbuf
;
646 tbuf
.it_interval
.tv_sec
= 1;
647 tbuf
.it_interval
.tv_usec
= 0;
651 tbuf
.it_value
.tv_sec
= 1;
652 tbuf
.it_value
.tv_usec
= 0;
653 if (setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1) {
658 tbuf
.it_value
.tv_sec
= 0;
659 tbuf
.it_value
.tv_usec
= 0;
660 if ( setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1 ) {
668 void signal_setup (void) {
669 struct sigaction saction
;
671 saction
.sa_handler
= signal_handler
;
672 sigemptyset(&saction
.sa_mask
);
673 saction
.sa_flags
= 0;
674 if (sigaction(SIGALRM
, &saction
, NULL
) < 0 ) {
679 if (sigaction(SIGINT
, &saction
, NULL
) < 0 ) {
685 void signal_handler (int signum
) {
689 dtime
= difftime (time(NULL
), g
.t
);
690 move_ph (1, f
.w
*CW
-(CW
%2)-3-(dtime
>999));
691 printf ("[%03d]", g
.t
?dtime
:0);
698 void screen_setup (int enable
) {
701 printf ("\033[s\033[?47h"); /* save cursor, alternate screen */
702 printf ("\033[H\033[J"); /* reset cursor, clear screen */
703 printf ("\033[?1000h\033[?25l"); /* enable mouse, hide cursor */
704 print (op
.scheme
->init_seq
); /* swich charset, if necessary */
706 print (op
.scheme
->reset_seq
); /* reset charset, if necessary */
707 printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */
708 printf ("\033[?47l\033[u"); /* primary screen, restore cursor */
713 /* http://users.csc.calpoly.edu/~phatalsk/357/lectures/code/sigalrm.c */
714 void raw_mode(int enable
) {
715 static struct termios saved_term_mode
;
716 struct termios raw_term_mode
;
719 tcgetattr(STDIN_FILENO
, &saved_term_mode
);
720 raw_term_mode
= saved_term_mode
;
721 raw_term_mode
.c_lflag
&= ~(ICANON
| ECHO
);
722 raw_term_mode
.c_cc
[VMIN
] = 1 ;
723 raw_term_mode
.c_cc
[VTIME
] = 0;
724 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &raw_term_mode
);
726 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &saved_term_mode
);