]>
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
;
61 opterr
= 0; /* don't print message on unrecognized option */
62 while ((optget
= getopt (argc
, argv
, "+hnfqcdx")) != -1) {
64 case 'n': op
.mode
= NOFLAG
; break;
65 case 'f': op
.mode
= FLAG
; break; /*default*/
66 case 'q': op
.mode
= QUESM
; break;
67 case 'c': op
.scheme
= &symbols_col1
; break;
68 case 'd': op
.scheme
= &symbols_doublewidth
; break;
71 fprintf (stderr
, SHORTHELP LONGHELP
, argv
[0]);
72 return !(optget
=='h');
74 } if (optind
< argc
) { /* parse Fieldspec */
75 if (parse_fieldspec (argv
[optind
])) {
76 fprintf (stderr
, "FIELDSPEC: WxH[xM]"
77 " (width 'x' height 'x' mines)\n");
82 /* check boundaries */
83 if (f
.m
> (f
.w
-1) * (f
.h
-1)) {
84 f
.m
= (f
.w
-1) * (f
.h
-1);
85 fprintf (stderr
, "too many mines. reduced to %d.\r\n", f
.m
); //TODO: doesn't show up
94 f
.c
= alloc_array (f
.h
, f
.w
);
95 g
= (const struct game
){0}; /* reset all game-specific parameters */
97 struct line_col markers
[26];
98 for (int i
=26; i
; markers
[--i
].l
= -1);
100 show_minefield (NORMAL
);
104 unsigned char mouse
[3];
106 action
= getch(mouse
);
109 if (g
.s
== MODE_OPEN
||
110 f
.c
[g
.p
[0]][g
.p
[1]].o
== OPENED
) {
111 switch (do_uncover(&(g
.n
))) {
112 case GAME_LOST
: goto lose
;
113 case GAME_WON
: goto win
;
115 } else if (g
.s
== MODE_FLAG
) {
116 flag_square (g
.p
[0], g
.p
[1]);
117 } else if (g
.s
== MODE_QUESM
) {
118 quesm_square (g
.p
[0], g
.p
[1]); }
121 g
.s
= (g
.s
+1)%(op
.mode
+1);
122 show_minefield (g
.c
?SHOWMINES
:NORMAL
);
124 case CTRSEQ_MOUSE_LEFT
:
125 if (clicked_emoticon(mouse
)) {
129 if (screen2field_c (mouse
[1]) < 0 ||
130 screen2field_c (mouse
[1]) >= f
.w
||
131 screen2field_l (mouse
[2]) < 0 ||
132 screen2field_l (mouse
[2]) >= f
.h
) break;
133 g
.p
[0] = screen2field_l (mouse
[2]);
134 g
.p
[1] = screen2field_c (mouse
[1]);
137 switch (do_uncover(&(g
.n
))) {
138 case GAME_LOST
: goto lose
;
139 case GAME_WON
: goto win
;
142 case CTRSEQ_MOUSE_RIGHT
:
143 if (screen2field_c (mouse
[1]) < 0 ||
144 screen2field_c (mouse
[1]) >= f
.w
||
145 screen2field_l (mouse
[2]) < 0 ||
146 screen2field_l (mouse
[2]) >= f
.h
) break;
147 g
.p
[0] = screen2field_l (mouse
[2]);
148 g
.p
[1] = screen2field_c (mouse
[1]);
150 case 'i': flag_square (g
.p
[0], g
.p
[1]); break;
151 case '?':quesm_square (g
.p
[0], g
.p
[1]); break;
152 case CTRSEQ_CURSOR_LEFT
:
153 case 'h': move_hi (g
.p
[0], g
.p
[1]-1 ); break;
154 case CTRSEQ_CURSOR_DOWN
:
155 case 'j': move_hi (g
.p
[0]+1, g
.p
[1] ); break;
156 case CTRSEQ_CURSOR_UP
:
157 case 'k': move_hi (g
.p
[0]-1, g
.p
[1] ); break;
158 case CTRSEQ_CURSOR_RIGHT
:
159 case 'l': move_hi (g
.p
[0], g
.p
[1]+1 ); break;
160 case 'w': to_next_boundary (g
.p
[0], g
.p
[1], '>'); break;
161 case 'b': to_next_boundary (g
.p
[0], g
.p
[1], '<'); break;
162 case 'u': to_next_boundary (g
.p
[0], g
.p
[1], '^'); break;
163 case 'd': to_next_boundary (g
.p
[0], g
.p
[1], 'v'); break;
164 case '0': /* fallthrough */
165 case '^': move_hi (g
.p
[0], 0 ); break;
166 case '$': move_hi (g
.p
[0], f
.w
-1 ); break;
167 case 'g': move_hi (0, g
.p
[1] ); break;
168 case 'G': move_hi (f
.h
-1, g
.p
[1] ); break;
169 case 'z': move_hi (f
.h
/2, f
.w
/2); break;
171 action
= tolower(getch(mouse
));
172 if (action
< 'a' || action
> 'z') break;/*out of bound*/
173 markers
[action
-'a'].l
= g
.p
[0];
174 markers
[action
-'a'].c
= g
.p
[1];
176 case'\'': /* fallthrough */
178 action
= tolower(getch(mouse
));
179 if (action
< 'a' || action
> 'z' /* out of bound or */
180 || markers
[action
-'a'].l
== -1) break; /* unset */
181 move_hi (markers
[action
-'a'].l
, markers
[action
-'a'].c
);
183 case 'r': /* start a new game */
188 case '\014': /* Ctrl-L -- redraw */
189 show_minefield (NORMAL
);
192 if (g
.n
== GAME_NEW
) break; /* must open a cell first */
193 show_minefield (g
.c
?NORMAL
:SHOWMINES
);
199 win
: g
.o
= GAME_WON
; goto endgame
;
200 lose
: g
.o
= GAME_LOST
; goto endgame
;
202 timer_setup(0); /* stop timer */
203 show_minefield (SHOWMINES
);
206 unsigned char mouse
[3];
207 gotaction
= getch(mouse
);
208 if (gotaction
==CTRSEQ_MOUSE_LEFT
&& clicked_emoticon(mouse
)) {
211 } else if (gotaction
== 'r') {
214 } else if (gotaction
== 'q') {
228 /* I haven't won as long as a cell exists, that
229 - I haven't opened, and
231 int everything_opened (void) {
232 for (int row
= 0; row
< f
.h
; row
++)
233 for (int col
= 0; col
< f
.w
; col
++)
234 if (f
.c
[row
][col
].o
== CLOSED
&&
235 f
.c
[row
][col
].m
== NO_MINE
) return 0;
239 int wait_mouse_up (int l
, int c
) {
240 unsigned char mouse2
[3];
245 move_ph (1, field2screen_c (f
.w
/2)-1); print (EMOT(OHH
));
247 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
248 /* show a pushed-in button if cursor is on minefield */
249 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
250 fputs (op
.scheme
->mouse_highlight
, stdout
);
254 if (getctrlseq (mouse2
) == CTRSEQ_MOUSE
) {
255 /* ignore mouse wheel events: */
256 if (mouse2
[0] & 0x40) continue;
258 else if (mouse2
[0]&3 == 3) level
--; /* release event */
259 else level
++; /* another button pressed */
263 move_ph (1, field2screen_c (f
.w
/2)-1); print (get_emoticon());
265 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
266 partial_show_minefield (l
, c
, NORMAL
);
268 c2
= screen2field_c(mouse2
[1]);
269 l2
= screen2field_l(mouse2
[2]);
270 return ((l2
== l
) && (c2
== c
));
273 int choord_square (int line
, int col
) {
274 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
275 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
276 if (f
.c
[l
][c
].f
!= FLAG
) {
277 if (uncover_square (l
, c
))
286 int uncover_square (int l
, int c
) {
287 f
.c
[l
][c
].o
= OPENED
;
288 f
.c
[l
][c
].f
= NOFLAG
; /*must not be QUESM, otherwise rendering issues*/
289 partial_show_minefield (l
, c
, NORMAL
);
292 f
.c
[l
][c
].m
= DEATH_MINE
;
296 /* check for chording */
297 if (f
.c
[l
][c
].n
== 0) {
298 for (int choord_l
= -1; choord_l
<= 1; choord_l
++) {
299 for (int choord_c
= -1; choord_c
<= 1; choord_c
++) {
300 int newl
= l
+ choord_l
;
301 int newc
= c
+ choord_c
;
302 if (newl
>= 0 && newl
< f
.h
&&
303 newc
>= 0 && newc
< f
.w
&&
304 f
.c
[newl
][newc
].o
== CLOSED
&&
305 uncover_square (newl
, newc
)) {
315 void flag_square (int l
, int c
) {
316 static char modechar
[] = {'*', '!', '?'};
318 if (f
.c
[l
][c
].o
!= CLOSED
) return;
319 /* cycle through flag/quesm/noflag: */
320 f
.c
[l
][c
].f
= (f
.c
[l
][c
].f
+ 1) % (op
.mode
+ 1);
321 if (f
.c
[l
][c
].f
==FLAG
) g
.f
++;
322 else if ((op
.mode
==FLAG
&& f
.c
[l
][c
].f
==NOFLAG
) ||
323 (op
.mode
==QUESM
&& f
.c
[l
][c
].f
==QUESM
)) g
.f
--;
324 partial_show_minefield (l
, c
, NORMAL
);
325 move_ph (1, op
.scheme
->cell_width
);
326 printf ("[%03d%c]", f
.m
- g
.f
, modechar
[g
.s
]);
329 void quesm_square (int l
, int c
) {
330 /* toggle question mark / none. won't turn flags into question marks.
331 unlike flag_square, this function doesn't respect `-q'. */
332 if (f
.c
[l
][c
].o
!= CLOSED
) return;
333 else if (f
.c
[l
][c
].f
== NOFLAG
) f
.c
[l
][c
].f
= QUESM
;
334 else if (f
.c
[l
][c
].f
== QUESM
) f
.c
[l
][c
].f
= NOFLAG
;
335 partial_show_minefield (l
, c
, NORMAL
);
338 int do_uncover (int* is_newgame
) {
339 if (*is_newgame
== GAME_NEW
) {
340 *is_newgame
= GAME_INPROGRESS
;
341 fill_minefield (g
.p
[0], g
.p
[1]);
345 if (f
.c
[g
.p
[0]][g
.p
[1]].f
== FLAG
) return GAME_INPROGRESS
;
346 if (f
.c
[g
.p
[0]][g
.p
[1]].o
== CLOSED
) {
347 if (uncover_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
348 } else if (get_neighbours (g
.p
[0], g
.p
[1], 1) == 0) {
349 if (choord_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
351 if (everything_opened()) return GAME_WON
;
353 return GAME_INPROGRESS
;
356 void fill_minefield (int l
, int c
) {
360 int line
= rand() % f
.h
;
361 int col
= rand() % f
.w
;
363 if (f
.c
[line
][col
].m
) {
364 /* skip if field already has a mine */
366 } else if ((line
== l
) && (col
== c
)) {
367 /* don't put a mine on the already opened (first click) field */
371 f
.c
[line
][col
].m
= STD_MINE
;
375 /* precalculate neighbours */
376 for (int l
=0; l
< f
.h
; l
++)
377 for (int c
=0; c
< f
.w
; c
++)
378 f
.c
[l
][c
].n
= get_neighbours (l
, c
, NORMAL
);
381 void move_ph (int line
, int col
) {
382 /* move printhead to zero-indexed position */
383 printf ("\033[%d;%dH", line
+1, col
+1);
386 void move_hi (int l
, int c
) {
387 /* move cursor and highlight to absolute coordinates */
389 partial_show_minefield (g
.p
[0], g
.p
[1], NORMAL
);
391 g
.p
[0] = CLAMP(l
, 0, f
.h
-1);
392 g
.p
[1] = CLAMP(c
, 0, f
.w
-1);
393 move_ph (g
.p
[0]+LINE_OFFSET
, field2screen_c(g
.p
[1]));
395 print("\033[7m"); /* reverse video */
396 partial_show_minefield (g
.p
[0], g
.p
[1], HIGHLIGHT
);
397 print("\033[0m"); /* un-invert */
400 /* to_next_boundary(): move into the supplied direction until a change in open-
401 state or flag-state is found and move there. falls back to BIG_MOVE. */
402 #define FIND_NEXT(X, L, C, L1, C1, MAX, OP) do {\
403 new_ ## X OP ## = BIG_MOVE;\
404 for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\
405 if (((f.c[L ][C ].o<<2) + f.c[L ][C ].f) \
406 != ((f.c[L1][C1].o<<2) + f.c[L1][C1].f)) {\
411 void to_next_boundary (int l
, int c
, char direction
) {
415 case '>': FIND_NEXT(c
, l
, i
, l
, i
+1, w
, +); break;
416 case '<': FIND_NEXT(c
, l
, i
, l
, i
-1, w
, -); break;
417 case '^': FIND_NEXT(l
, i
, c
, i
-1, c
, h
, -); break;
418 case 'v': FIND_NEXT(l
, i
, c
, i
+1, c
, h
, +); break;
421 move_hi (new_l
, new_c
);
425 char* cell2schema (int l
, int c
, int mode
) {
426 struct minecell cell
= f
.c
[l
][c
];
428 if (mode
== SHOWMINES
) return (
429 cell
.f
== FLAG
&& cell
.m
? op
.scheme
->field_flagged
:
430 cell
.f
== FLAG
&& !cell
.m
? op
.scheme
->mine_wrongf
:
431 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
432 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
433 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
434 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
436 cell
.f
== FLAG
? op
.scheme
->field_flagged
:
437 cell
.f
== QUESM
? op
.scheme
->field_question
:
438 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
439 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
440 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
441 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
444 void partial_show_minefield (int l
, int c
, int mode
) {
445 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
447 print (cell2schema(l
, c
, mode
));
450 char* get_emoticon(void) {
451 return g
.o
==GAME_WON
? EMOT(WON
):
452 g
.o
==GAME_LOST
? EMOT(DEAD
):
456 /* https://zserge.com/blog/c-for-loop-tricks.html */
457 #define print_line(which) \
458 for (int _break = (printf("%s", BORDER(which,LEFT)), 1); _break; \
459 _break = 0, printf("%s\r\n", BORDER(which,RIGHT)))
460 #define print_border(which, width) \
461 print_line(which) printm (width, BORDER(which,MIDDLE))
462 void show_minefield (int mode
) {
463 int dtime
= difftime (time(NULL
), g
.t
)*!!g
.t
;
464 int half_spaces
= f
.w
*op
.scheme
->cell_width
/2;
465 int left_spaces
= MAX(0,half_spaces
-7-(f
.m
-g
.f
>999));
466 int right_spaces
= MAX(0,half_spaces
-6-(dtime
>999));
467 static char modechar
[] = {'*', '!', '?'};
471 print_border(TOP
, f
.w
);
473 printf("[%03d%c]%*s%s%*s[%03d]",
474 /* [ */ f
.m
- g
.f
, modechar
[g
.s
], /* ] */
475 left_spaces
,"", get_emoticon(), right_spaces
,"",
476 /* [ */ dtime
/* ] */);
478 print_border(DIVIDER
, f
.w
);
480 for (int l
= 0; l
< f
.h
; l
++) print_line(FIELD
)
481 printm (f
.w
, cell2schema(l
, _loop
, mode
));
482 print_border(BOTTOM
, f
.w
);
485 int get_neighbours (int line
, int col
, int reduced_mode
) {
486 /* counts mines surrounding a square
487 modes: 0=normal; 1=reduced */
491 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
492 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
493 if (!l
&& !c
) continue;
495 count
+= !!f
.c
[l
][c
].m
;
496 count
-= reduced_mode
* f
.c
[l
][c
].f
==FLAG
;
502 struct minecell
** alloc_array (int lines
, int cols
) {
503 struct minecell
** a
= malloc (lines
* sizeof(struct minecell
*));
504 if (a
== NULL
) return NULL
;
505 for (int l
= 0; l
< lines
; l
++) {
506 a
[l
] = calloc (cols
, sizeof(struct minecell
));
507 if (a
[l
] == NULL
) goto unalloc
;
512 for (int l
= 0; l
< lines
; l
++)
517 void free_field (void) {
518 if (f
.c
== NULL
) return;
519 for (int l
= 0; l
< f
.h
; l
++) {
527 int screen2field_l (int l
) {
528 return (l
-LINE_OFFSET
) - 1;
530 int screen2field_c (int c
) {
531 /* this depends on the cell width and only works when it is 1 or 2. */
532 return (c
-COL_OFFSET
+1 - 2*(CW
%2))/2 - CW
/2;
534 int field2screen_c (int c
) {
535 return (CW
*c
+COL_OFFSET
- (CW
%2));
537 int clicked_emoticon (unsigned char* mouse
) {
538 return (mouse
[2] == LINE_OFFSET
-1 && (
539 mouse
[1] == f
.w
+COL_OFFSET
||
540 mouse
[1] == f
.w
+COL_OFFSET
+1));
549 int getctrlseq (unsigned char* buf
) {
552 int offset
= 0x20; /* never sends control chars as data */
553 while ((c
= getchar()) != EOF
) {
557 case '\033': state
=ESC_SENT
; break;
563 case '[': state
=CSI_SENT
; break;
564 default: return CTRSEQ_INVALID
;
569 case 'A': return CTRSEQ_CURSOR_UP
;
570 case 'B': return CTRSEQ_CURSOR_DOWN
;
571 case 'C': return CTRSEQ_CURSOR_RIGHT
;
572 case 'D': return CTRSEQ_CURSOR_LEFT
;
573 case 'M': state
=MOUSE_EVENT
; break;
574 default: return CTRSEQ_INVALID
;
579 buf
[1] = getchar() - offset
;
580 buf
[2] = getchar() - offset
;
583 return CTRSEQ_INVALID
;
589 int getch(unsigned char* buf
) {
590 /* returns a character, EOF, or constant for an escape/control sequence - NOT
591 compatible with the ncurses implementation of same name */
592 int action
= getctrlseq(buf
);
596 l
= screen2field_l (buf
[2]);
597 c
= screen2field_c (buf
[1]);
599 if (buf
[0] > 3) break; /* ignore all but left/middle/right/up */
600 int success
= wait_mouse_up(l
, c
);
602 /* mouse moved while pressed: */
603 if (!success
) return CTRSEQ_INVALID
;
606 case 0: return CTRSEQ_MOUSE_LEFT
;
607 case 1: return CTRSEQ_MOUSE_MIDDLE
;
608 case 2: return CTRSEQ_MOUSE_RIGHT
;
615 int parse_fieldspec(char* str
) {
616 /* parses the FIELDSPEC (WxHxM); returns 1 on error */
617 int n
= sscanf (str
, "%dx%dx%d", &f
.w
, &f
.h
, &f
.m
);
619 ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &w
);
621 /* clamp field size to terminal size and mouse maximum: */
622 if (COL_OFFSET
+ f
.w
*CW
+ COL_OFFSET
> w
.ws_col
)
623 f
.w
= w
.ws_col
/CW
- (COL_OFFSET
+COL_OFFSET
);
624 if (LINE_OFFSET
+ f
.h
+ LINES_AFTER
> w
.ws_row
)
625 f
.h
= w
.ws_row
- (LINE_OFFSET
+LINES_AFTER
);
626 if (COL_OFFSET
+ f
.w
*CW
> MOUSE_MAX
)
627 f
.w
= MOUSE_MAX
/CW
- COL_OFFSET
;
628 if (LINE_OFFSET
+ f
.h
> MOUSE_MAX
)
629 f
.h
= MOUSE_MAX
- LINE_OFFSET
;
632 return 1; /* error */
634 if (f
.w
< 30) f
.m
= f
.w
*f
.h
*.15625;
635 else f
.m
= f
.w
*f
.h
*.20625;
641 void timer_setup (int enable
) {
642 static struct itimerval tbuf
;
643 tbuf
.it_interval
.tv_sec
= 1;
644 tbuf
.it_interval
.tv_usec
= 0;
648 tbuf
.it_value
.tv_sec
= 1;
649 tbuf
.it_value
.tv_usec
= 0;
650 if (setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1) {
655 tbuf
.it_value
.tv_sec
= 0;
656 tbuf
.it_value
.tv_usec
= 0;
657 if ( setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1 ) {
665 void signal_setup (void) {
666 struct sigaction saction
;
668 saction
.sa_handler
= signal_handler
;
669 sigemptyset(&saction
.sa_mask
);
670 saction
.sa_flags
= 0;
671 if (sigaction(SIGALRM
, &saction
, NULL
) < 0 ) {
676 if (sigaction(SIGINT
, &saction
, NULL
) < 0 ) {
682 void signal_handler (int signum
) {
686 dtime
= difftime (time(NULL
), g
.t
);
687 move_ph (1, f
.w
*CW
-(CW
%2)-3-(dtime
>999));
688 printf ("[%03d]", g
.t
?dtime
:0);
695 void screen_setup (int enable
) {
698 printf ("\033[s\033[?47h"); /* save cursor, alternate screen */
699 printf ("\033[H\033[J"); /* reset cursor, clear screen */
700 printf ("\033[?1000h\033[?25l"); /* enable mouse, hide cursor */
701 print (op
.scheme
->init_seq
); /* swich charset, if necessary */
703 print (op
.scheme
->reset_seq
); /* reset charset, if necessary */
704 printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */
705 printf ("\033[?47l\033[u"); /* primary screen, restore cursor */
710 /* http://users.csc.calpoly.edu/~phatalsk/357/lectures/code/sigalrm.c */
711 void raw_mode(int enable
) {
712 static struct termios saved_term_mode
;
713 struct termios raw_term_mode
;
716 tcgetattr(STDIN_FILENO
, &saved_term_mode
);
717 raw_term_mode
= saved_term_mode
;
718 raw_term_mode
.c_lflag
&= ~(ICANON
| ECHO
);
719 raw_term_mode
.c_cc
[VMIN
] = 1 ;
720 raw_term_mode
.c_cc
[VTIME
] = 0;
721 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &raw_term_mode
);
723 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &saved_term_mode
);