File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 30
30
31
31
#include <windows.h>
32
32
#include <unistd.h>
33
+ #include <signal.h>
33
34
34
35
HANDLE std_in = NULL ;
35
36
HANDLE con_out = NULL ;
@@ -66,18 +67,31 @@ void mp_hal_stdio_mode_orig(void) {
66
67
SetConsoleMode (std_in , orig_mode );
67
68
}
68
69
70
+ STATIC void sighandler (int signum ) {
71
+ if (signum == SIGINT ) {
72
+ if (MP_STATE_VM (mp_pending_exception ) == MP_STATE_VM (keyboard_interrupt_obj )) {
73
+ // this is the second time we are called, so die straight away
74
+ exit (1 );
75
+ }
76
+ mp_obj_exception_clear_traceback (MP_STATE_VM (keyboard_interrupt_obj ));
77
+ MP_STATE_VM (mp_pending_exception ) = MP_STATE_VM (keyboard_interrupt_obj );
78
+ }
79
+ }
80
+
69
81
void mp_hal_set_interrupt_char (char c ) {
70
82
assure_stdin_handle ();
71
83
if (c == CHAR_CTRL_C ) {
72
84
DWORD mode ;
73
85
GetConsoleMode (std_in , & mode );
74
86
mode |= ENABLE_PROCESSED_INPUT ;
75
87
SetConsoleMode (std_in , mode );
88
+ signal (SIGINT , sighandler );
76
89
} else {
77
90
DWORD mode ;
78
91
GetConsoleMode (std_in , & mode );
79
92
mode &= ~ENABLE_PROCESSED_INPUT ;
80
93
SetConsoleMode (std_in , mode );
94
+ signal (SIGINT , SIG_DFL );
81
95
}
82
96
}
83
97
You can’t perform that action at this time.
0 commit comments