]>
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
92 f
.c
= alloc_array (f
.h
, f
.w
);
102 //memset (&g, 0, sizeof (struct game));
103 //static const struct game reset_game; g = reset_game;
104 g
= (const struct game
){0};
106 struct line_col markers
[26];
107 for (int i
=26; i
; markers
[--i
].l
= -1);
109 /* setup the screen: */
112 /* save cursor and switch to alternate screen */
113 printf ("\033[s\033[?47h");
114 /* reset cursor, clear screen */
115 printf ("\033[H\033[J");
117 /* swich charset, if necessary */
118 if (op
.scheme
->init_seq
!= NULL
) print (op
.scheme
->init_seq
);
120 show_minefield (NORMAL
);
122 /* enable mouse, hide cursor */
123 printf ("\033[?1000h\033[?25l");
127 unsigned char mouse
[3];
129 action
= getch(mouse
);
132 if (g
.s
== MODE_OPEN
||
133 f
.c
[g
.p
[0]][g
.p
[1]].o
== OPENED
) {
134 switch (do_uncover(&(g
.n
))) {
135 case GAME_LOST
: goto lose
;
136 case GAME_WON
: goto win
;
138 } else if (g
.s
== MODE_FLAG
) {
139 flag_square (g
.p
[0], g
.p
[1]);
140 } else if (g
.s
== MODE_QUESM
) {
141 quesm_square (g
.p
[0], g
.p
[1]);
145 g
.s
= (g
.s
+1)%(op
.mode
+1);
146 show_minefield (g
.c
?SHOWMINES
:NORMAL
);
148 case CTRSEQ_MOUSE_LEFT
:
149 if (clicked_emoticon(mouse
)) {
153 if (screen2field_c (mouse
[1]) < 0 ||
154 screen2field_c (mouse
[1]) >= f
.w
||
155 screen2field_l (mouse
[2]) < 0 ||
156 screen2field_l (mouse
[2]) >= f
.h
) break;
157 g
.p
[0] = screen2field_l (mouse
[2]);
158 g
.p
[1] = screen2field_c (mouse
[1]);
161 switch (do_uncover(&(g
.n
))) {
162 case GAME_LOST
: goto lose
;
163 case GAME_WON
: goto win
;
166 case CTRSEQ_MOUSE_RIGHT
:
167 if (screen2field_c (mouse
[1]) < 0 ||
168 screen2field_c (mouse
[1]) >= f
.w
||
169 screen2field_l (mouse
[2]) < 0 ||
170 screen2field_l (mouse
[2]) >= f
.h
) break;
171 g
.p
[0] = screen2field_l (mouse
[2]);
172 g
.p
[1] = screen2field_c (mouse
[1]);
174 case 'i': flag_square (g
.p
[0], g
.p
[1]); break;
175 case '?':quesm_square (g
.p
[0], g
.p
[1]); break;
176 case CTRSEQ_CURSOR_LEFT
:
177 case 'h': move_hi (g
.p
[0], g
.p
[1]-1 ); break;
178 case CTRSEQ_CURSOR_DOWN
:
179 case 'j': move_hi (g
.p
[0]+1, g
.p
[1] ); break;
180 case CTRSEQ_CURSOR_UP
:
181 case 'k': move_hi (g
.p
[0]-1, g
.p
[1] ); break;
182 case CTRSEQ_CURSOR_RIGHT
:
183 case 'l': move_hi (g
.p
[0], g
.p
[1]+1 ); break;
184 case 'w': to_next_boundary (g
.p
[0], g
.p
[1], '>'); break;
185 case 'b': to_next_boundary (g
.p
[0], g
.p
[1], '<'); break;
186 case 'u': to_next_boundary (g
.p
[0], g
.p
[1], '^'); break;
187 case 'd': to_next_boundary (g
.p
[0], g
.p
[1], 'v'); break;
188 case '0': /* fallthrough */
189 case '^': move_hi (g
.p
[0], 0 ); break;
190 case '$': move_hi (g
.p
[0], f
.w
-1 ); break;
191 case 'g': move_hi (0, g
.p
[1] ); break;
192 case 'G': move_hi (f
.h
-1, g
.p
[1] ); break;
193 case 'z': move_hi (f
.h
/2, f
.w
/2); break;
195 action
= tolower(getch(mouse
));
196 if (action
< 'a' || action
> 'z') break;/*out of bound*/
197 markers
[action
-'a'].l
= g
.p
[0];
198 markers
[action
-'a'].c
= g
.p
[1];
200 case'\'': /* fallthrough */
202 action
= tolower(getch(mouse
));
203 if (action
< 'a' || action
> 'z' /* out of bound or */
204 || markers
[action
-'a'].l
== -1) break; /* unset */
205 move_hi (markers
[action
-'a'].l
, markers
[action
-'a'].c
);
207 case 'r': /* start a new game */
212 case '\014': /* Ctrl-L -- redraw */
213 show_minefield (NORMAL
);
218 fill_minefield (-1, -1);
221 show_minefield (g
.c
?NORMAL
:SHOWMINES
);
227 win
: g
.o
= GAME_WON
; goto endgame
;
228 lose
: g
.o
= GAME_LOST
; goto endgame
;
230 timer_setup(0); /* stop timer */
231 show_minefield (SHOWMINES
);
234 unsigned char mouse
[3];
235 gotaction
= getch(mouse
);
236 if (gotaction
==CTRSEQ_MOUSE_LEFT
&& clicked_emoticon(mouse
)) {
239 } else if (gotaction
== 'r') {
242 } else if (gotaction
== 'q') {
252 printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */
253 print (op
.scheme
->reset_seq
); /* reset charset, if necessary */
254 printf ("\033[?47l\033[u"); /*revert to primary screen, restore cursor*/
259 /* I haven't won as long as a cell exists, that
260 - I haven't opened, and
262 int everything_opened (void) {
263 for (int row
= 0; row
< f
.h
; row
++)
264 for (int col
= 0; col
< f
.w
; col
++)
265 if (f
.c
[row
][col
].o
== CLOSED
&&
266 f
.c
[row
][col
].m
== NO_MINE
) return 0;
270 int wait_mouse_up (int l
, int c
) {
271 unsigned char mouse2
[3];
276 move_ph (1, field2screen_c (f
.w
/2)-1); print (EMOT(OHH
));
278 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
279 /* show a pushed-in button if cursor is on minefield */
280 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
281 fputs (op
.scheme
->mouse_highlight
, stdout
);
285 if (getctrlseq (mouse2
) == CTRSEQ_MOUSE
) {
286 /* ignore mouse wheel events: */
287 if (mouse2
[0] & 0x40) continue;
289 else if (mouse2
[0]&3 == 3) level
--; /* release event */
290 else level
++; /* another button pressed */
294 move_ph (1, field2screen_c (f
.w
/2)-1); print (get_emoticon());
296 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
297 partial_show_minefield (l
, c
, NORMAL
);
299 c2
= screen2field_c(mouse2
[1]);
300 l2
= screen2field_l(mouse2
[2]);
301 return ((l2
== l
) && (c2
== c
));
304 int choord_square (int line
, int col
) {
305 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
306 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
307 if (f
.c
[l
][c
].f
!= FLAG
) {
308 if (uncover_square (l
, c
))
317 int uncover_square (int l
, int c
) {
318 f
.c
[l
][c
].o
= OPENED
;
319 f
.c
[l
][c
].f
= NOFLAG
; /*must not be QUESM, otherwise rendering issues*/
320 partial_show_minefield (l
, c
, NORMAL
);
323 f
.c
[l
][c
].m
= DEATH_MINE
;
327 /* check for chording */
328 if (f
.c
[l
][c
].n
== 0) {
329 for (int choord_l
= -1; choord_l
<= 1; choord_l
++) {
330 for (int choord_c
= -1; choord_c
<= 1; choord_c
++) {
331 int newl
= l
+ choord_l
;
332 int newc
= c
+ choord_c
;
333 if (newl
>= 0 && newl
< f
.h
&&
334 newc
>= 0 && newc
< f
.w
&&
335 f
.c
[newl
][newc
].o
== CLOSED
&&
336 uncover_square (newl
, newc
)) {
346 void flag_square (int l
, int c
) {
347 static char modechar
[] = {'*', '!', '?'};
349 if (f
.c
[l
][c
].o
!= CLOSED
) return;
350 /* cycle through flag/quesm/noflag: */
351 f
.c
[l
][c
].f
= (f
.c
[l
][c
].f
+ 1) % (op
.mode
+ 1);
352 if (f
.c
[l
][c
].f
==FLAG
) g
.f
++;
353 else if ((op
.mode
==FLAG
&& f
.c
[l
][c
].f
==NOFLAG
) ||
354 (op
.mode
==QUESM
&& f
.c
[l
][c
].f
==QUESM
)) g
.f
--;
355 partial_show_minefield (l
, c
, NORMAL
);
356 move_ph (1, op
.scheme
->cell_width
);
357 printf ("[%03d%c]", f
.m
- g
.f
, modechar
[g
.s
]);
360 void quesm_square (int l
, int c
) {
361 /* toggle question mark / none. won't turn flags into question marks.
362 unlike flag_square, this function doesn't respect `-q'. */
363 if (f
.c
[l
][c
].o
!= CLOSED
) return;
364 else if (f
.c
[l
][c
].f
== NOFLAG
) f
.c
[l
][c
].f
= QUESM
;
365 else if (f
.c
[l
][c
].f
== QUESM
) f
.c
[l
][c
].f
= NOFLAG
;
366 partial_show_minefield (l
, c
, NORMAL
);
369 int do_uncover (int* is_newgame
) {
372 fill_minefield (g
.p
[0], g
.p
[1]);
376 if (f
.c
[g
.p
[0]][g
.p
[1]].f
== FLAG
) return GAME_INPROGRESS
;
377 if (f
.c
[g
.p
[0]][g
.p
[1]].o
== CLOSED
) {
378 if (uncover_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
379 } else if (get_neighbours (g
.p
[0], g
.p
[1], 1) == 0) {
380 if (choord_square (g
.p
[0], g
.p
[1])) return GAME_LOST
;
382 if (everything_opened()) return GAME_WON
;
384 return GAME_INPROGRESS
;
387 void fill_minefield (int l
, int c
) {
391 int line
= rand() % f
.h
;
392 int col
= rand() % f
.w
;
394 if (f
.c
[line
][col
].m
) {
395 /* skip if field already has a mine */
397 } else if ((line
== l
) && (col
== c
)) {
398 /* don't put a mine on the already opened (first click) field */
402 f
.c
[line
][col
].m
= STD_MINE
;
406 /* precalculate neighbours */
407 for (int l
=0; l
< f
.h
; l
++)
408 for (int c
=0; c
< f
.w
; c
++)
409 f
.c
[l
][c
].n
= get_neighbours (l
, c
, NORMAL
);
412 void move_ph (int line
, int col
) {
413 /* move printhead to zero-indexed position */
414 printf ("\033[%d;%dH", line
+1, col
+1);
417 void move_hi (int l
, int c
) {
418 /* move cursor and highlight to absolute coordinates */
420 partial_show_minefield (g
.p
[0], g
.p
[1], NORMAL
);
422 g
.p
[0] = CLAMP(l
, 0, f
.h
-1);
423 g
.p
[1] = CLAMP(c
, 0, f
.w
-1);
424 move_ph (g
.p
[0]+LINE_OFFSET
, field2screen_c(g
.p
[1]));
426 print("\033[7m"); /* reverse video */
427 partial_show_minefield (g
.p
[0], g
.p
[1], HIGHLIGHT
);
428 print("\033[0m"); /* un-invert */
431 /* to_next_boundary(): move into the supplied direction until a change in open-
432 state or flag-state is found and move there. falls back to BIG_MOVE. */
433 #define FIND_NEXT(X, L, C, L1, C1, MAX, OP) do {\
434 new_ ## X OP ## = BIG_MOVE;\
435 for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\
436 if (((f.c[L ][C ].o<<2) + f.c[L ][C ].f) \
437 != ((f.c[L1][C1].o<<2) + f.c[L1][C1].f)) {\
442 void to_next_boundary (int l
, int c
, char direction
) {
446 case '>': FIND_NEXT(c
, l
, i
, l
, i
+1, w
, +); break;
447 case '<': FIND_NEXT(c
, l
, i
, l
, i
-1, w
, -); break;
448 case '^': FIND_NEXT(l
, i
, c
, i
-1, c
, h
, -); break;
449 case 'v': FIND_NEXT(l
, i
, c
, i
+1, c
, h
, +); break;
452 move_hi (new_l
, new_c
);
456 char* cell2schema (int l
, int c
, int mode
) {
457 struct minecell cell
= f
.c
[l
][c
];
459 if (mode
== SHOWMINES
) return (
460 cell
.f
== FLAG
&& cell
.m
? op
.scheme
->field_flagged
:
461 cell
.f
== FLAG
&& !cell
.m
? op
.scheme
->mine_wrongf
:
462 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
463 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
464 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
465 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
467 cell
.f
== FLAG
? op
.scheme
->field_flagged
:
468 cell
.f
== QUESM
? op
.scheme
->field_question
:
469 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
470 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
471 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
472 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
475 void partial_show_minefield (int l
, int c
, int mode
) {
476 move_ph (l
+LINE_OFFSET
, field2screen_c(c
));
478 print (cell2schema(l
, c
, mode
));
481 char* get_emoticon(void) {
482 return g
.o
==GAME_WON
? EMOT(WON
):
483 g
.o
==GAME_LOST
? EMOT(DEAD
):
487 /* https://zserge.com/blog/c-for-loop-tricks.html */
488 #define print_line(which) \
489 for (int _break = (printf("%s", BORDER(which,LEFT)), 1); _break; \
490 _break = 0, printf("%s\r\n", BORDER(which,RIGHT)))
491 #define print_border(which, width) \
492 print_line(which) printm (width, BORDER(which,MIDDLE))
493 void show_minefield (int mode
) {
494 int dtime
= difftime (time(NULL
), g
.t
)*!!g
.t
;
495 int half_spaces
= f
.w
*op
.scheme
->cell_width
/2;
496 int left_spaces
= MAX(0,half_spaces
-7-(f
.m
-g
.f
>999));
497 int right_spaces
= MAX(0,half_spaces
-6-(dtime
>999));
498 static char modechar
[] = {'*', '!', '?'};
502 print_border(TOP
, f
.w
);
504 printf("[%03d%c]%*s%s%*s[%03d]",
505 /* [ */ f
.m
- g
.f
, modechar
[g
.s
], /* ] */
506 left_spaces
,"", get_emoticon(), right_spaces
,"",
507 /* [ */ dtime
/* ] */);
509 print_border(DIVIDER
, f
.w
);
511 for (int l
= 0; l
< f
.h
; l
++) print_line(FIELD
)
512 printm (f
.w
, cell2schema(l
, _loop
, mode
));
513 print_border(BOTTOM
, f
.w
);
516 int get_neighbours (int line
, int col
, int reduced_mode
) {
517 /* counts mines surrounding a square
518 modes: 0=normal; 1=reduced */
522 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
523 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
524 if (!l
&& !c
) continue;
526 count
+= !!f
.c
[l
][c
].m
;
527 count
-= reduced_mode
* f
.c
[l
][c
].f
==FLAG
;
533 struct minecell
** alloc_array (int lines
, int cols
) {
534 struct minecell
** a
= malloc (lines
* sizeof(struct minecell
*));
535 if (a
== NULL
) return NULL
;
536 for (int l
= 0; l
< lines
; l
++) {
537 a
[l
] = calloc (cols
, sizeof(struct minecell
));
538 if (a
[l
] == NULL
) goto unalloc
;
543 for (int l
= 0; l
< lines
; l
++)
548 void free_field (void) {
549 if (f
.c
== NULL
) return;
550 for (int l
= 0; l
< f
.h
; l
++) {
558 int screen2field_l (int l
) {
559 return (l
-LINE_OFFSET
) - 1;
561 int screen2field_c (int c
) {
562 /* this depends on the cell width and only works when it is 1 or 2. */
563 return (c
-COL_OFFSET
+1 - 2*(CW
%2))/2 - CW
/2;
565 int field2screen_c (int c
) {
566 return (CW
*c
+COL_OFFSET
- (CW
%2));
568 int clicked_emoticon (unsigned char* mouse
) {
569 return (mouse
[2] == LINE_OFFSET
-1 && (
570 mouse
[1] == f
.w
+COL_OFFSET
||
571 mouse
[1] == f
.w
+COL_OFFSET
+1));
580 int getctrlseq (unsigned char* buf
) {
583 int offset
= 0x20; /* never sends control chars as data */
584 while ((c
= getchar()) != EOF
) {
588 case '\033': state
=ESC_SENT
; break;
594 case '[': state
=CSI_SENT
; break;
595 default: return CTRSEQ_INVALID
;
600 case 'A': return CTRSEQ_CURSOR_UP
;
601 case 'B': return CTRSEQ_CURSOR_DOWN
;
602 case 'C': return CTRSEQ_CURSOR_RIGHT
;
603 case 'D': return CTRSEQ_CURSOR_LEFT
;
604 case 'M': state
=MOUSE_EVENT
; break;
605 default: return CTRSEQ_INVALID
;
610 buf
[1] = getchar() - offset
;
611 buf
[2] = getchar() - offset
;
614 return CTRSEQ_INVALID
;
620 int getch(unsigned char* buf
) {
621 /* returns a character, EOF, or constant for an escape/control sequence - NOT
622 compatible with the ncurses implementation of same name */
623 int action
= getctrlseq(buf
);
627 l
= screen2field_l (buf
[2]);
628 c
= screen2field_c (buf
[1]);
630 if (buf
[0] > 3) break; /* ignore all but left/middle/right/up */
631 int success
= wait_mouse_up(l
, c
);
633 /* mouse moved while pressed: */
634 if (!success
) return CTRSEQ_INVALID
;
637 case 0: return CTRSEQ_MOUSE_LEFT
;
638 case 1: return CTRSEQ_MOUSE_MIDDLE
;
639 case 2: return CTRSEQ_MOUSE_RIGHT
;
646 int parse_fieldspec(char* str
) {
647 /* parses the FIELDSPEC (WxHxM); returns 1 on error */
648 int n
= sscanf (str
, "%dx%dx%d", &f
.w
, &f
.h
, &f
.m
);
650 ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &w
);
652 /* clamp field size to terminal size and mouse maximum: */
653 if (COL_OFFSET
+ f
.w
*CW
+ COL_OFFSET
> w
.ws_col
)
654 f
.w
= w
.ws_col
/CW
- (COL_OFFSET
+COL_OFFSET
);
655 if (LINE_OFFSET
+ f
.h
+ LINES_AFTER
> w
.ws_row
)
656 f
.h
= w
.ws_row
- (LINE_OFFSET
+LINES_AFTER
);
657 if (COL_OFFSET
+ f
.w
*CW
> MOUSE_MAX
)
658 f
.w
= MOUSE_MAX
/CW
- COL_OFFSET
;
659 if (LINE_OFFSET
+ f
.h
> MOUSE_MAX
)
660 f
.h
= MOUSE_MAX
- LINE_OFFSET
;
663 return 1; /* error */
665 if (f
.w
< 30) f
.m
= f
.w
*f
.h
*.15625;
666 else f
.m
= f
.w
*f
.h
*.20625;
672 void timer_setup (int enable
) {
673 static struct itimerval tbuf
;
674 tbuf
.it_interval
.tv_sec
= 1;
675 tbuf
.it_interval
.tv_usec
= 0;
679 tbuf
.it_value
.tv_sec
= 1;
680 tbuf
.it_value
.tv_usec
= 0;
681 if (setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1) {
686 tbuf
.it_value
.tv_sec
= 0;
687 tbuf
.it_value
.tv_usec
= 0;
688 if ( setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1 ) {
696 void signal_setup (void) {
697 struct sigaction saction
;
699 saction
.sa_handler
= signal_handler
;
700 sigemptyset(&saction
.sa_mask
);
701 saction
.sa_flags
= 0;
702 if (sigaction(SIGALRM
, &saction
, NULL
) < 0 ) {
707 if (sigaction(SIGINT
, &saction
, NULL
) < 0 ) {
713 void signal_handler (int signum
) {
717 dtime
= difftime (time(NULL
), g
.t
);
718 move_ph (1, f
.w
*CW
-(CW
%2)-3-(dtime
>999));
719 printf ("[%03d]", g
.t
?dtime
:0);
726 /* http://users.csc.calpoly.edu/~phatalsk/357/lectures/code/sigalrm.c */
727 void raw_mode(int mode
) {
728 static struct termios saved_term_mode
;
729 struct termios raw_term_mode
;
732 tcgetattr(STDIN_FILENO
, &saved_term_mode
);
733 raw_term_mode
= saved_term_mode
;
734 raw_term_mode
.c_lflag
&= ~(ICANON
| ECHO
);
735 raw_term_mode
.c_cc
[VMIN
] = 1 ;
736 raw_term_mode
.c_cc
[VTIME
] = 0;
737 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &raw_term_mode
);
739 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &saved_term_mode
);