diff options
-rw-r--r-- | doc/tshark.pod | 11 | ||||
-rw-r--r-- | docbook/release-notes.asciidoc | 2 | ||||
-rw-r--r-- | epan/print_stream.c | 40 | ||||
-rw-r--r-- | epan/print_stream.h | 17 |
4 files changed, 31 insertions, 39 deletions
diff --git a/doc/tshark.pod b/doc/tshark.pod index 9cccc201f2..dad95b6f3d 100644 --- a/doc/tshark.pod +++ b/doc/tshark.pod @@ -1669,11 +1669,12 @@ Change the interface's timestamp method. =item --color -Enable coloring of packets according to standard Wireshark color filters. This -is currently implemented via 24-bit "true color" terminal escape sequences that -are not supported by all terminal emulators. See -L<https://wiki.wireshark.org/ColoringRules> for more information on configuring -color filters. +Enable coloring of packets according to standard Wireshark color +filters. On Windows colors are limited to the standard console +character attribute colors. Other platforms require a terminal that +handles 24-bit "true color" terminal escape sequences. See +L<https://wiki.wireshark.org/ColoringRules> for more information on +configuring color filters. =item --no-duplicate-keys diff --git a/docbook/release-notes.asciidoc b/docbook/release-notes.asciidoc index 8ce1cc1d59..209eab146d 100644 --- a/docbook/release-notes.asciidoc +++ b/docbook/release-notes.asciidoc @@ -44,7 +44,7 @@ used for troubleshooting, analysis, development and education. The following features are new (or have been significantly updated) since version 2.4.0: -* Add color support for TShark with --color option (non-Windows only). +* Add color support for TShark with --color option. * The "matches" display filter operator is now case-insensitive. * Display expression (button) preferences have been converted to a UAT. This puts the display expressions in their own file. Wireshark still diff --git a/epan/print_stream.c b/epan/print_stream.c index 4a5a6d6fd1..44ed34e0a3 100644 --- a/epan/print_stream.c +++ b/epan/print_stream.c @@ -7,19 +7,7 @@ * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: GPL-2.0+ */ #include "config.h" @@ -42,6 +30,11 @@ #define TERM_SGR_RESET "\x1B[0m" /* SGR - reset */ #define TERM_CSI_EL "\x1B[K" /* EL - Erase in Line (to end of line) */ +typedef struct { + gboolean to_file; + FILE *fh; +} output_text; + static void print_color_escape(FILE *fh, const color_t *fg, const color_t *bg) { @@ -157,8 +150,15 @@ print_color_escape(FILE *fh, const color_t *fg, const color_t *bg) } static void -print_color_eol(FILE *fh) +print_color_eol(print_stream_t *self) { + output_text *output = (output_text *)self->data; + FILE *fh = output->fh; +#ifdef _WIN32 + SetConsoleTextAttribute((HANDLE)_get_osfhandle(_fileno(fh)), self->csb_attrs); + fprintf(fh, "\n"); +#else // UN*X + /* * Emit CSI EL to extend current background color all the way to EOL, * otherwise we get a ragged right edge of color wherever the newline @@ -166,6 +166,7 @@ print_color_eol(FILE *fh) * works. */ fprintf(fh, "%s\n%s", TERM_CSI_EL, TERM_SGR_RESET); +#endif } static FILE * @@ -240,11 +241,6 @@ destroy_print_stream(print_stream_t *self) return (self && self->ops && self->ops->destroy) ? (self->ops->destroy)(self) : TRUE; } -typedef struct { - gboolean to_file; - FILE *fh; -} output_text; - #define MAX_INDENT 160 /* returns TRUE if the print succeeded, FALSE if there was an error */ @@ -297,7 +293,7 @@ print_line_color_text(print_stream_t *self, int indent, const char *line, const } if (emit_color) - print_color_eol(output->fh); + print_color_eol(self); else putc('\n', output->fh); } @@ -367,6 +363,10 @@ print_stream_text_alloc(gboolean to_file, FILE *fh) stream->to_codeset = charset; } #else + CONSOLE_SCREEN_BUFFER_INFO csb_info; + GetConsoleScreenBufferInfo((HANDLE)_get_osfhandle(_fileno(fh)), &csb_info); + stream->csb_attrs = csb_info.wAttributes; + stream->to_codeset = "UTF-16LE"; #endif diff --git a/epan/print_stream.h b/epan/print_stream.h index 2447061453..32adeaa29a 100644 --- a/epan/print_stream.h +++ b/epan/print_stream.h @@ -7,19 +7,7 @@ * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __PRINT_STREAM_H__ @@ -56,6 +44,9 @@ typedef struct print_stream { gboolean isatty; const char *to_codeset; void *data; +#ifdef _WIN32 + unsigned short csb_attrs; // WORD +#endif } print_stream_t; WS_DLL_PUBLIC print_stream_t *print_stream_text_new(gboolean to_file, const char *dest); |