File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 9
9
#include " graphics.h"
10
10
11
11
#include < getopt.h>
12
+ #include < signal.h>
12
13
#include < stdio.h>
13
14
#include < stdlib.h>
14
15
#include < string.h>
15
- #include < unistd.h>
16
16
#include < time.h>
17
+ #include < unistd.h>
17
18
18
19
using namespace rgb_matrix ;
19
20
21
+ volatile bool interrupt_received = false ;
22
+ static void InterruptHandler (int signo) {
23
+ interrupt_received = true ;
24
+ }
25
+
20
26
static int usage (const char *progname) {
21
27
fprintf (stderr, " usage: %s [options]\n " , progname);
22
28
fprintf (stderr, " Reads text from stdin and displays it. "
@@ -149,7 +155,10 @@ int main(int argc, char *argv[]) {
149
155
next_time.tv_nsec = 0 ;
150
156
struct tm tm ;
151
157
152
- for (;;) {
158
+ signal (SIGTERM, InterruptHandler);
159
+ signal (SIGINT, InterruptHandler);
160
+
161
+ while (!interrupt_received) {
153
162
localtime_r (&next_time.tv_sec , &tm );
154
163
strftime (text_buffer, sizeof (text_buffer), time_format, &tm );
155
164
offscreen->Fill (bg_color.r , bg_color.g , bg_color.b );
@@ -176,5 +185,6 @@ int main(int argc, char *argv[]) {
176
185
matrix->Clear ();
177
186
delete matrix;
178
187
188
+ write (STDOUT_FILENO, " \n " , 1 ); // Create a fresh new line after ^C on screen
179
189
return 0 ;
180
190
}
You can’t perform that action at this time.
0 commit comments