summaryrefslogtreecommitdiff
path: root/epan/print_stream.h
diff options
context:
space:
mode:
authorDave Goodell <dave@goodell.io>2017-04-24 22:14:42 -0700
committerMichael Mann <mmann78@netscape.net>2017-06-11 13:36:06 +0000
commitaffa6f18c87eaf430cc0bf260c54fbfe32976a5f (patch)
treeabd05ecd22df083be93b00183e919ade9ceb5626 /epan/print_stream.h
parent5617527ee3831a8012f076b67e2532eeb8b1da2d (diff)
downloadwireshark-affa6f18c87eaf430cc0bf260c54fbfe32976a5f.tar.gz
print_stream: add a new print_line_color() method
This new interface allows printing a line with specified foreground and background colors. The implementation avoids printing escape sequences if the output stream is not a TTY and note that escape sequences are ignored on Windows. This initial implementation relies on relatively modern 24-bit color support which is present in many terminal emulators but may not always display properly on older or simpler emulators. Windows coloring is handled with SetConsoleTextAttribute, which offers a "1-bit" color experience (but it's better than nothing) This commit is a precursor to adding additional coloring to tshark. Bug: 5158 Change-Id: Ib2b9d800095a065a4bb60abe0550862cda5539ec Reviewed-on: https://code.wireshark.org/review/21324 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/print_stream.h')
-rw-r--r--epan/print_stream.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/epan/print_stream.h b/epan/print_stream.h
index 7afeffa155..2447061453 100644
--- a/epan/print_stream.h
+++ b/epan/print_stream.h
@@ -27,6 +27,8 @@
#include "ws_symbol_export.h"
+#include <wsutil/color.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -46,6 +48,7 @@ typedef struct print_stream_ops {
gboolean (*new_page)(struct print_stream *self);
gboolean (*print_finale)(struct print_stream *self);
gboolean (*destroy)(struct print_stream *self);
+ gboolean (*print_line_color)(struct print_stream *self, int indent, const char *line, const color_t *fg, const color_t *bg);
} print_stream_ops_t;
typedef struct print_stream {
@@ -68,6 +71,15 @@ WS_DLL_PUBLIC gboolean new_page(print_stream_t *self);
WS_DLL_PUBLIC gboolean print_finale(print_stream_t *self);
WS_DLL_PUBLIC gboolean destroy_print_stream(print_stream_t *self);
+/*
+ * equivalent to print_line(), but if the stream supports text coloring then
+ * the output text will also be colored with the given foreground and
+ * background
+ *
+ * returns TRUE if the print was successful, FALSE otherwise
+ */
+WS_DLL_PUBLIC gboolean print_line_color(print_stream_t *self, int indent, const char *line, const color_t *fg, const color_t *bg);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */