diff --git a/input.cpp b/input.cpp index 7ef8402a1..1c60b93c2 100644 --- a/input.cpp +++ b/input.cpp @@ -292,7 +292,7 @@ static int interrupt_handler() /* Tell the reader an event occured */ - if (reader_interrupted()) + if (reader_reading_interrupted()) { /* Return 3, i.e. the character read by a Control-C. diff --git a/reader.cpp b/reader.cpp index 49030aded..2e4867b19 100644 --- a/reader.cpp +++ b/reader.cpp @@ -657,11 +657,17 @@ void reader_reset_interrupted() int reader_interrupted() { - int res=interrupted; + int res = interrupted; if (res) { interrupted=0; } + return res; +} + +int reader_reading_interrupted() +{ + int res = reader_interrupted(); if (res && data && data->interruptible) { reader_exit(1, 0); diff --git a/reader.h b/reader.h index f94d8a896..0c10fb695 100644 --- a/reader.h +++ b/reader.h @@ -111,6 +111,12 @@ void reader_set_buffer(const wcstring &b, size_t p); */ size_t reader_get_cursor_pos(); +/** + Return the value of the interrupted flag, which is set by the sigint + handler, and clear it if it was set. +*/ +int reader_interrupted(); + /** Clear the interrupted flag unconditionally without handling anything. The flag could have been set e.g. when an interrupt arrived just as we were @@ -124,7 +130,7 @@ void reader_reset_interrupted(); handler, and clear it if it was set. If the current reader is interruptible, call \c reader_exit(). */ -int reader_interrupted(); +int reader_reading_interrupted(); /** Read one line of input. Before calling this function, reader_push()