Skip to content

Commit bc07681

Browse files
author
Nate Morrison
committed
Restores terminal background colour on exit
NOTE: Standard output from Direwolf is not affected.
1 parent fe6cba2 commit bc07681

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+170
-9
lines changed

src/aclients.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ int main (int argc, char *argv[])
221221

222222
if (num_clients < 1 || num_clients > MAX_CLIENTS) {
223223
printf ("Specify up to %d TNCs on the command line.\n", MAX_CLIENTS);
224+
dw_printf ("\e[0m\e\n\e[0J\e");
224225
exit (1);
225226
}
226227

@@ -236,13 +237,15 @@ int main (int argc, char *argv[])
236237
p = strtok (stemp, "=");
237238
if (p == NULL) {
238239
printf ("Internal error 1\n");
240+
dw_printf ("\e[0m\e\n\e[0J\e");
239241
exit (1);
240242
}
241243
strlcpy (hostname[j], "localhost", sizeof(hostname[j]));
242244
strlcpy (port[j], p, sizeof(port[j]));
243245
p = strtok (NULL, "=");
244246
if (p == NULL) {
245247
printf ("Missing description after %s\n", port[j]);
248+
dw_printf ("\e[0m\e\n\e[0J\e");
246249
exit (1);
247250
}
248251
strlcpy (description[j], p, sizeof(description[j]));
@@ -291,6 +294,7 @@ int main (int argc, char *argv[])
291294
}
292295
if (client_th[j] == NULL) {
293296
printf ("Internal error: Could not create client thread %d.\n", j);
297+
dw_printf ("\e[0m\e\n\e[0J\e");
294298
exit (1);
295299
}
296300
#else
@@ -302,6 +306,7 @@ int main (int argc, char *argv[])
302306
}
303307
if (e != 0) {
304308
perror("Internal error: Could not create client thread.");
309+
dw_printf ("\e[0m\e\n\e[0J\e");
305310
exit (1);
306311
}
307312
#endif
@@ -438,6 +443,7 @@ static void * client_thread_net (void *arg)
438443
hostname[my_index], gai_strerror(err));
439444
#endif
440445
freeaddrinfo(ai_head);
446+
dw_printf ("\e[0m\e\n\e[0J\e");
441447
exit (1);
442448
}
443449

@@ -536,6 +542,7 @@ static void * client_thread_net (void *arg)
536542

537543
printf("Client %d unable to connect to %s on %s (%s), port %s\n",
538544
my_index, description[my_index], hostname[my_index], ipaddr_str, port[my_index] );
545+
dw_printf ("\e[0m\e\n\e[0J\e");
539546
exit (1);
540547
}
541548

@@ -563,6 +570,7 @@ static void * client_thread_net (void *arg)
563570

564571
if (n != sizeof(mon_cmd)) {
565572
printf ("Read error, client %d received %d command bytes. Terminating.\n", my_index, n);
573+
dw_printf ("\e[0m\e\n\e[0J\e");
566574
exit (1);
567575
}
568576

@@ -577,6 +585,7 @@ static void * client_thread_net (void *arg)
577585

578586
if (n != mon_cmd.data_len) {
579587
printf ("Read error, client %d received %d data bytes.\n", my_index, n);
588+
dw_printf ("\e[0m\e\n\e[0J\e");
580589
exit (1);
581590
}
582591
}
@@ -682,6 +691,7 @@ static void * client_thread_serial (void *arg)
682691
if (fd == MYFDERROR) {
683692
printf("Client %d unable to connect to %s on %s.\n",
684693
my_index, description[my_index], port[my_index] );
694+
dw_printf ("\e[0m\e\n\e[0J\e");
685695
exit (1);
686696
}
687697

@@ -732,6 +742,7 @@ static void * client_thread_serial (void *arg)
732742
if (fd == MYFDERROR) {
733743
printf("Client %d unable to connect to %s on %s.\n",
734744
my_index, description[my_index], port[my_index] );
745+
dw_printf ("\e[0m\e\n\e[0J\e");
735746
exit (1);
736747
}
737748

@@ -781,6 +792,7 @@ static void * client_thread_serial (void *arg)
781792
if (! ReadFile (fd, &ch, 1, &n, NULL)) {
782793
printf ("Read error on %s.\n", description[my_index]);
783794
CloseHandle (fd);
795+
dw_printf ("\e[0m\e\n\e[0J\e");
784796
exit (1);
785797
}
786798

@@ -790,6 +802,7 @@ static void * client_thread_serial (void *arg)
790802
if ( ( n = read(fd, & ch, 1)) < 0) {
791803
printf ("Read error on %s.\n", description[my_index]);
792804
close (fd);
805+
dw_printf ("\e[0m\e\n\e[0J\e");
793806
exit (1);
794807
}
795808
#endif

src/appserver.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static void usage()
5656
dw_printf (" mycall is required because that is the callsign for \n");
5757
dw_printf (" which the TNC will accept connections. \n");
5858
dw_printf (" \n");
59+
dw_printf ("\e[0m\e\n\e[0J\e");
5960
exit (EXIT_FAILURE);
6061
}
6162

@@ -192,6 +193,7 @@ int main (int argc, char *argv[])
192193
if (agwlib_init (tnc_hostname, tnc_port, agwlib_G_ask_port_information) != 0) {
193194
text_color_set(DW_COLOR_ERROR);
194195
dw_printf ("Could not attach to network TNC %s:%s.\n", tnc_hostname, tnc_port);
196+
dw_printf ("\e[0m\e\n\e[0J\e");
195197
exit (EXIT_FAILURE);
196198
}
197199

src/atest.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ int main (int argc, char *argv[])
314314
if (decimate < 1 || decimate > 8) {
315315
text_color_set(DW_COLOR_ERROR);
316316
dw_printf ("Unreasonable value for -D.\n");
317+
dw_printf ("\e[0m\e\n\e[0J\e");
317318
exit (EXIT_FAILURE);
318319
}
319320
dw_printf ("Divide audio sample rate by %d\n", decimate);
@@ -331,6 +332,7 @@ int main (int argc, char *argv[])
331332
if (upsample < 1 || upsample > 4) {
332333
text_color_set(DW_COLOR_ERROR);
333334
dw_printf ("Unreasonable value for -U.\n");
335+
dw_printf ("\e[0m\e\n\e[0J\e");
334336
exit (EXIT_FAILURE);
335337
}
336338
dw_printf ("Multiply audio sample rate by %d\n", upsample);
@@ -344,6 +346,7 @@ int main (int argc, char *argv[])
344346
if (my_audio_config.achan[0].fix_bits < RETRY_NONE || my_audio_config.achan[0].fix_bits >= RETRY_MAX) {
345347
text_color_set(DW_COLOR_ERROR);
346348
dw_printf ("Invalid Fix Bits level.\n");
349+
dw_printf ("\e[0m\e\n\e[0J\e");
347350
exit (EXIT_FAILURE);
348351
}
349352
break;
@@ -424,6 +427,7 @@ int main (int argc, char *argv[])
424427
if (my_audio_config.achan[0].baud < MIN_BAUD || my_audio_config.achan[0].baud > MAX_BAUD) {
425428
text_color_set(DW_COLOR_ERROR);
426429
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
430+
dw_printf ("\e[0m\e\n\e[0J\e");
427431
exit (EXIT_FAILURE);
428432
}
429433

@@ -547,6 +551,7 @@ int main (int argc, char *argv[])
547551
text_color_set(DW_COLOR_ERROR);
548552
dw_printf ("Couldn't open file for read: %s\n", argv[optind]);
549553
//perror ("more info?");
554+
dw_printf ("\e[0m\e\n\e[0J\e");
550555
exit (EXIT_FAILURE);
551556
}
552557

@@ -561,6 +566,7 @@ int main (int argc, char *argv[])
561566
if (strncmp(header.riff, "RIFF", 4) != 0 || strncmp(header.wave, "WAVE", 4) != 0) {
562567
text_color_set(DW_COLOR_ERROR);
563568
dw_printf ("This is not a .WAV format file.\n");
569+
dw_printf ("\e[0m\e\n\e[0J\e");
564570
exit (EXIT_FAILURE);
565571
}
566572

@@ -574,11 +580,13 @@ int main (int argc, char *argv[])
574580
if (strncmp(chunk.id, "fmt ", 4) != 0) {
575581
text_color_set(DW_COLOR_ERROR);
576582
dw_printf ("WAV file error: Found \"%4.4s\" where \"fmt \" was expected.\n", chunk.id);
583+
dw_printf ("\e[0m\e\n\e[0J\e");
577584
exit(EXIT_FAILURE);
578585
}
579586
if (chunk.datasize != 16 && chunk.datasize != 18) {
580587
text_color_set(DW_COLOR_ERROR);
581588
dw_printf ("WAV file error: Need fmt chunk datasize of 16 or 18. Found %d.\n", chunk.datasize);
589+
dw_printf ("\e[0m\e\n\e[0J\e");
582590
exit(EXIT_FAILURE);
583591
}
584592

@@ -589,24 +597,28 @@ int main (int argc, char *argv[])
589597
if (strncmp(wav_data.data, "data", 4) != 0) {
590598
text_color_set(DW_COLOR_ERROR);
591599
dw_printf ("WAV file error: Found \"%4.4s\" where \"data\" was expected.\n", wav_data.data);
600+
dw_printf ("\e[0m\e\n\e[0J\e");
592601
exit(EXIT_FAILURE);
593602
}
594603

595604
if (format.wformattag != 1) {
596605
text_color_set(DW_COLOR_ERROR);
597606
dw_printf ("Sorry, I only understand audio format 1 (PCM). This file has %d.\n", format.wformattag);
607+
dw_printf ("\e[0m\e\n\e[0J\e");
598608
exit (EXIT_FAILURE);
599609
}
600610

601611
if (format.nchannels != 1 && format.nchannels != 2) {
602612
text_color_set(DW_COLOR_ERROR);
603613
dw_printf ("Sorry, I only understand 1 or 2 channels. This file has %d.\n", format.nchannels);
614+
dw_printf ("\e[0m\e\n\e[0J\e");
604615
exit (EXIT_FAILURE);
605616
}
606617

607618
if (format.wbitspersample != 8 && format.wbitspersample != 16) {
608619
text_color_set(DW_COLOR_ERROR);
609620
dw_printf ("Sorry, I only understand 8 or 16 bits per sample. This file has %d.\n", format.wbitspersample);
621+
dw_printf ("\e[0m\e\n\e[0J\e");
610622
exit (EXIT_FAILURE);
611623
}
612624

@@ -709,14 +721,17 @@ int main (int argc, char *argv[])
709721
if (error_if_less_than != -1 && packets_decoded_total < error_if_less_than) {
710722
text_color_set(DW_COLOR_ERROR);
711723
dw_printf ("\n * * * TEST FAILED: number decoded is less than %d * * * \n", error_if_less_than);
724+
dw_printf ("\e[0m\e\n\e[0J\e");
712725
exit (EXIT_FAILURE);
713726
}
714727
if (error_if_greater_than != -1 && packets_decoded_total > error_if_greater_than) {
715728
text_color_set(DW_COLOR_ERROR);
716729
dw_printf ("\n * * * TEST FAILED: number decoded is greater than %d * * * \n", error_if_greater_than);
730+
dw_printf ("\e[0m\e\n\e[0J\e");
717731
exit (EXIT_FAILURE);
718732
}
719733

734+
dw_printf ("\e[0m\e\n\e[0J\e");
720735
exit (EXIT_SUCCESS);
721736
}
722737

@@ -1008,6 +1023,7 @@ static void usage (void) {
10081023
dw_printf (" Try different combinations of options to compare decoding\n");
10091024
dw_printf (" performance.\n");
10101025

1026+
dw_printf ("\e[0m\e\n\e[0J\e");
10111027
exit (1);
10121028
}
10131029

src/audio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ int audio_get (int a)
10561056
if (res <= 0) {
10571057
text_color_set(DW_COLOR_INFO);
10581058
dw_printf ("\nEnd of file on stdin. Exiting.\n");
1059+
dw_printf ("\e[0m\e\n\e[0J\e");
10591060
exit (0);
10601061
}
10611062

src/audio_portaudio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ int audio_get (int a)
10841084
if (res <= 0) {
10851085
text_color_set(DW_COLOR_INFO);
10861086
dw_printf ("\nEnd of file on stdin. Exiting.\n");
1087+
dw_printf ("\e[0m\e\n\e[0J\e");
10871088
exit (0);
10881089
}
10891090

src/audio_win.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ int audio_get (int a)
890890
if (res <= 0) {
891891
text_color_set(DW_COLOR_INFO);
892892
dw_printf ("\nEnd of file on stdin. Exiting.\n");
893+
dw_printf ("\e[0m\e\n\e[0J\e");
893894
exit (0);
894895
}
895896

src/ax25_pad2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ int main ()
929929
dw_printf ("\n----------\n\n");
930930
dw_printf ("\nSUCCESS!\n");
931931

932+
dw_printf ("\e[0m\e\n\e[0J\e");
932933
exit (EXIT_SUCCESS);
933934

934935
} /* end main */

src/cm108.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ int main (int argc, char *argv[])
685685
if (argc != 2) {
686686
text_color_set(DW_COLOR_ERROR);
687687
dw_printf ("Specify HID path on command line.\n");
688+
dw_printf ("\e[0m\e\n\e[0J\e");
688689
exit (1);
689690
}
690691

src/config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
18331833
#if __WIN32__
18341834
text_color_set(DW_COLOR_ERROR);
18351835
dw_printf ("Config file line %d: Windows version of direwolf does not support HAMLIB.\n", line);
1836+
dw_printf ("\e[0m\e\n\e[0J\e");
18361837
exit (EXIT_FAILURE);
18371838
#else
18381839
text_color_set(DW_COLOR_ERROR);
@@ -1919,6 +1920,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
19191920
dw_printf ("You must rebuild direwolf with CM108 Audio Adapter GPIO PTT support.\n");
19201921
dw_printf ("See User Guide for details.\n");
19211922
#endif
1923+
dw_printf ("\e[0m\e\n\e[0J\e");
19221924
exit (EXIT_FAILURE);
19231925
#endif
19241926
}
@@ -4219,6 +4221,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
42194221
}
42204222
}
42214223
//dw_printf ("DEBUG server=%s port=%d\n", p_igate_config->t2_server_name, p_igate_config->t2_server_port);
4224+
//dw_printf ("\e[0m\e\n\e[0J\e");
42224225
//exit (0);
42234226
}
42244227

src/decode_aprs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,6 +4805,7 @@ int main (int argc, char *argv[])
48054805
if (argc >= 2) {
48064806
if (freopen (argv[1], "r", stdin) == NULL) {
48074807
fprintf(stderr, "Can't open %s for read.\n", argv[1]);
4808+
dw_printf ("\e[0m\e\n\e[0J\e");
48084809
exit(1);
48094810
}
48104811
}

src/demod.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ void demod_process_sample (int chan, int subchan, int sam)
993993
text_color_set(DW_COLOR_ERROR);
994994
dw_printf ("Invalid combination of options. Exiting.\n");
995995
// Would probably work but haven't thought about it or tested yet.
996+
dw_printf ("\e[0m\e\n\e[0J\e");
996997
exit (1);
997998
}
998999
else {

src/demod_afsk.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
267267

268268
text_color_set(DW_COLOR_ERROR);
269269
dw_printf ("Invalid filter profile = %c\n", profile);
270+
dw_printf ("\e[0m\e\n\e[0J\e");
270271
exit (1);
271272
}
272273

@@ -352,6 +353,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
352353
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
353354
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
354355
MAX_FILTER_SIZE);
356+
dw_printf ("\e[0m\e\n\e[0J\e");
355357
exit (1);
356358
}
357359

@@ -362,6 +364,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
362364
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
363365
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
364366
MAX_FILTER_SIZE);
367+
dw_printf ("\e[0m\e\n\e[0J\e");
365368
exit (1);
366369
}
367370

@@ -374,6 +377,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
374377
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
375378
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
376379
MAX_FILTER_SIZE);
380+
dw_printf ("\e[0m\e\n\e[0J\e");
377381
exit (1);
378382
}
379383

src/demod_psk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ void demod_psk_init (enum modem_t modem_type, enum v26_e v26_alt, int samples_pe
446446
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
447447
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
448448
MAX_FILTER_SIZE);
449+
dw_printf ("\e[0m\e\n\e[0J\e");
449450
exit (1);
450451
}
451452

@@ -455,6 +456,7 @@ void demod_psk_init (enum modem_t modem_type, enum v26_e v26_alt, int samples_pe
455456
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
456457
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
457458
MAX_FILTER_SIZE);
459+
dw_printf ("\e[0m\e\n\e[0J\e");
458460
exit (1);
459461
}
460462

@@ -464,6 +466,7 @@ void demod_psk_init (enum modem_t modem_type, enum v26_e v26_alt, int samples_pe
464466
dw_printf ("Decrease the audio sample rate or increase the baud rate or\n");
465467
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n",
466468
MAX_FILTER_SIZE);
469+
dw_printf ("\e[0m\e\n\e[0J\e");
467470
exit (1);
468471
}
469472

src/digipeater.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ int main (int argc, char *argv[])
737737
regerror (e, &alias_re, message, sizeof(message));
738738
text_color_set(DW_COLOR_ERROR);
739739
dw_printf ("\n%s\n\n", message);
740+
dw_printf ("\e[0m\e\n\e[0J\e");
740741
exit (1);
741742
}
742743

@@ -745,6 +746,7 @@ int main (int argc, char *argv[])
745746
regerror (e, &wide_re, message, sizeof(message));
746747
text_color_set(DW_COLOR_ERROR);
747748
dw_printf ("\n%s\n\n", message);
749+
dw_printf ("\e[0m\e\n\e[0J\e");
748750
exit (1);
749751
}
750752

0 commit comments

Comments
 (0)