aboutsummaryrefslogtreecommitdiffstats
path: root/epan/print_stream.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-04-04 11:01:46 -0700
committerGuy Harris <guy@alum.mit.edu>2019-04-04 18:53:32 +0000
commit436278747e736fd0158cb22ca1eff3f1c0055134 (patch)
tree4915c3ee42ba4a6fec262554f171cdadb9f66705 /epan/print_stream.c
parent7edadf9ce38d3c983d8911200aa46f49ade26f2e (diff)
Reset the terminal color if we're ^C'ed when reading a capture.
Catch signals/ctrl events when we're reading a capture, and stop reading if we get one of those. When we close a print stream, restore the color as appropriate. Change-Id: I3dd936964560fb3902befe0fd2e961f80437ca72 Ping-Bug: 15659 Reviewed-on: https://code.wireshark.org/review/32716 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/print_stream.c')
-rw-r--r--epan/print_stream.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/epan/print_stream.c b/epan/print_stream.c
index 296ef0a19b..73ddfff9b0 100644
--- a/epan/print_stream.c
+++ b/epan/print_stream.c
@@ -400,11 +400,33 @@ destroy_text(print_stream_t *self)
output_text *output = (output_text *)self->data;
gboolean ret;
+ switch (output->color_type) {
+
+ case COLOR_NONE:
+ break;
+
#ifdef _WIN32
- /* Restore the console mode before we changed it. */
- if (output->color_type == COLOR_24BIT_ESCAPE)
+ case COLOR_CONSOLE:
+ /* Restore the default text attribute. */
+ SetConsoleTextAttribute((HANDLE)_get_osfhandle(_fileno(output->fh)), output->csb_attrs);
+ break;
+#endif
+
+ case COLOR_24BIT_ESCAPE:
+ /* Reset the color to the default */
+ fprintf(output->fh, "%s", TERM_SGR_RESET);
+ fflush(output->fh);
+
+#ifdef _WIN32
+ /*
+ * Restore the console mode before we changed it.
+ * We must do that *after* sending escape sequences,
+ * as this may disable escape sequence processing.
+ */
SetConsoleMode((HANDLE)_get_osfhandle(_fileno(output->fh)), output->console_mode);
#endif
+ break;
+ }
ret = close_print_dest(output->to_file, output->fh);
g_free(output);