Skip to content

Commit 2d15d6c

Browse files
authored
add SIGINT support for _WIN32 environments (#120)
* add SIGINT support for _WIN32 environments * perhaps more consistent
1 parent 2d64715 commit 2d15d6c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

main.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
1515
#include <signal.h>
1616
#include <unistd.h>
17+
#elif defined (_WIN32)
18+
#include <signal.h>
1719
#endif
1820

1921
#define ANSI_COLOR_RED "\x1b[31m"
@@ -755,7 +757,7 @@ bool llama_eval(
755757

756758
static bool is_interacting = false;
757759

758-
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
760+
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
759761
void sigint_handler(int signo) {
760762
printf(ANSI_COLOR_RESET);
761763
if (signo == SIGINT) {
@@ -865,6 +867,8 @@ int main(int argc, char ** argv) {
865867
sigemptyset (&sigint_action.sa_mask);
866868
sigint_action.sa_flags = 0;
867869
sigaction(SIGINT, &sigint_action, NULL);
870+
#elif defined (_WIN32)
871+
signal(SIGINT, sigint_handler);
868872
#endif
869873

870874
fprintf(stderr, "%s: interactive mode on.\n", __func__);
@@ -894,7 +898,7 @@ int main(int argc, char ** argv) {
894898

895899
if (params.interactive) {
896900
fprintf(stderr, "== Running in interactive mode. ==\n"
897-
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
901+
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
898902
" - Press Ctrl+C to interject at any time.\n"
899903
#endif
900904
" - Press Return to return control to LLaMa.\n"
@@ -1039,6 +1043,9 @@ int main(int argc, char ** argv) {
10391043
}
10401044
}
10411045

1046+
#if defined (_WIN32)
1047+
signal(SIGINT, SIG_DFL);
1048+
#endif
10421049

10431050
// report timing
10441051
{

0 commit comments

Comments
 (0)