11
11
#include < string>
12
12
#include < vector>
13
13
14
+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
14
15
#include < signal.h>
15
16
#include < unistd.h>
17
+ #endif
16
18
17
19
#define ANSI_COLOR_RED " \x1b [31m"
18
20
#define ANSI_COLOR_GREEN " \x1b [32m"
@@ -747,6 +749,7 @@ bool llama_eval(
747
749
748
750
static bool is_interacting = false ;
749
751
752
+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
750
753
void sigint_handler (int signo) {
751
754
if (signo == SIGINT) {
752
755
if (!is_interacting) {
@@ -756,6 +759,7 @@ void sigint_handler(int signo) {
756
759
}
757
760
}
758
761
}
762
+ #endif
759
763
760
764
int main (int argc, char ** argv) {
761
765
ggml_time_init ();
@@ -822,11 +826,13 @@ int main(int argc, char ** argv) {
822
826
}
823
827
printf (" \n " );
824
828
if (params.interactive ) {
829
+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
825
830
struct sigaction sigint_action;
826
831
sigint_action.sa_handler = sigint_handler;
827
832
sigemptyset (&sigint_action.sa_mask );
828
833
sigint_action.sa_flags = 0 ;
829
834
sigaction (SIGINT, &sigint_action, NULL );
835
+ #endif
830
836
831
837
printf (" %s: interactive mode on.\n " , __func__);
832
838
@@ -855,7 +861,9 @@ int main(int argc, char ** argv) {
855
861
856
862
if (params.interactive ) {
857
863
printf (" == Running in interactive mode. ==\n "
864
+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
858
865
" - Press Ctrl+C to interject at any time.\n "
866
+ #endif
859
867
" - Press Return to return control to LLaMa.\n "
860
868
" - If you want to submit another line, end your input in '\\ '.\n " );
861
869
}
@@ -957,10 +965,15 @@ int main(int argc, char ** argv) {
957
965
// currently being interactive
958
966
bool another_line=true ;
959
967
while (another_line) {
968
+ fflush (stdout);
960
969
char buf[256 ] = {0 };
961
970
int n_read;
962
971
if (params.use_color ) printf (ANSI_BOLD ANSI_COLOR_GREEN);
963
- scanf (" %255[^\n ]%n%*c" , buf, &n_read);
972
+ if (scanf (" %255[^\n ]%n%*c" , buf, &n_read) <= 0 ) {
973
+ // presumable empty line, consume the newline
974
+ scanf (" %*c" );
975
+ n_read=0 ;
976
+ }
964
977
if (params.use_color ) printf (ANSI_COLOR_RESET);
965
978
966
979
if (n_read > 0 && buf[n_read-1 ]==' \\ ' ) {
0 commit comments