File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030
3131#include <windows.h>
3232#include <unistd.h>
33+ #include <signal.h>
3334
3435HANDLE std_in = NULL ;
3536HANDLE con_out = NULL ;
@@ -66,18 +67,31 @@ void mp_hal_stdio_mode_orig(void) {
6667 SetConsoleMode (std_in , orig_mode );
6768}
6869
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+
6981void mp_hal_set_interrupt_char (char c ) {
7082 assure_stdin_handle ();
7183 if (c == CHAR_CTRL_C ) {
7284 DWORD mode ;
7385 GetConsoleMode (std_in , & mode );
7486 mode |= ENABLE_PROCESSED_INPUT ;
7587 SetConsoleMode (std_in , mode );
88+ signal (SIGINT , sighandler );
7689 } else {
7790 DWORD mode ;
7891 GetConsoleMode (std_in , & mode );
7992 mode &= ~ENABLE_PROCESSED_INPUT ;
8093 SetConsoleMode (std_in , mode );
94+ signal (SIGINT , SIG_DFL );
8195 }
8296}
8397
You can’t perform that action at this time.
0 commit comments