11
11
static void restore_term_on_signal (int sig )
12
12
{
13
13
restore_term ();
14
- sigchain_pop ( sig );
14
+ /* restore_term calls sigchain_pop_common */
15
15
raise (sig );
16
16
}
17
17
@@ -31,14 +31,20 @@ void restore_term(void)
31
31
tcsetattr (term_fd , TCSAFLUSH , & old_term );
32
32
close (term_fd );
33
33
term_fd = -1 ;
34
+ sigchain_pop_common ();
34
35
}
35
36
36
37
int save_term (int full_duplex )
37
38
{
38
39
if (term_fd < 0 )
39
40
term_fd = open ("/dev/tty" , O_RDWR );
41
+ if (term_fd < 0 )
42
+ return -1 ;
43
+ if (tcgetattr (term_fd , & old_term ) < 0 )
44
+ return -1 ;
45
+ sigchain_push_common (restore_term_on_signal );
40
46
41
- return ( term_fd < 0 ) ? -1 : tcgetattr ( term_fd , & old_term ) ;
47
+ return 0 ;
42
48
}
43
49
44
50
static int disable_bits (tcflag_t bits )
@@ -49,12 +55,16 @@ static int disable_bits(tcflag_t bits)
49
55
goto error ;
50
56
51
57
t = old_term ;
52
- sigchain_push_common (restore_term_on_signal );
53
58
54
59
t .c_lflag &= ~bits ;
60
+ if (bits & ICANON ) {
61
+ t .c_cc [VMIN ] = 1 ;
62
+ t .c_cc [VTIME ] = 0 ;
63
+ }
55
64
if (!tcsetattr (term_fd , TCSAFLUSH , & t ))
56
65
return 0 ;
57
66
67
+ sigchain_pop_common ();
58
68
error :
59
69
close (term_fd );
60
70
term_fd = -1 ;
@@ -100,6 +110,8 @@ void restore_term(void)
100
110
return ;
101
111
}
102
112
113
+ sigchain_pop_common ();
114
+
103
115
if (hconin == INVALID_HANDLE_VALUE )
104
116
return ;
105
117
@@ -134,6 +146,7 @@ int save_term(int full_duplex)
134
146
135
147
GetConsoleMode (hconin , & cmode_in );
136
148
use_stty = 0 ;
149
+ sigchain_push_common (restore_term_on_signal );
137
150
return 0 ;
138
151
error :
139
152
CloseHandle (hconin );
@@ -150,7 +163,11 @@ static int disable_bits(DWORD bits)
150
163
151
164
if (bits & ENABLE_LINE_INPUT ) {
152
165
string_list_append (& stty_restore , "icanon" );
153
- strvec_push (& cp .args , "-icanon" );
166
+ /*
167
+ * POSIX allows VMIN and VTIME to overlap with VEOF and
168
+ * VEOL - let's hope that is not the case on windows.
169
+ */
170
+ strvec_pushl (& cp .args , "-icanon" , "min" , "1" , "time" , "0" , NULL );
154
171
}
155
172
156
173
if (bits & ENABLE_ECHO_INPUT ) {
@@ -177,10 +194,10 @@ static int disable_bits(DWORD bits)
177
194
if (save_term (0 ) < 0 )
178
195
return -1 ;
179
196
180
- sigchain_push_common (restore_term_on_signal );
181
197
if (!SetConsoleMode (hconin , cmode_in & ~bits )) {
182
198
CloseHandle (hconin );
183
199
hconin = INVALID_HANDLE_VALUE ;
200
+ sigchain_pop_common ();
184
201
return -1 ;
185
202
}
186
203
@@ -385,7 +402,7 @@ int read_key_without_echo(struct strbuf *buf)
385
402
386
403
ch = getchar ();
387
404
if (ch == EOF )
388
- return 0 ;
405
+ break ;
389
406
strbuf_addch (buf , ch );
390
407
}
391
408
}
0 commit comments