summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2020-05-18 00:27:13 +0200
committerGravatar Nikias Bassen2020-05-18 00:27:13 +0200
commitf62d64492050556b383ec3a5db66830e78f9fd56 (patch)
treed7b212e292a040e9e4e4d703ba7b77298d1d2471 /tools
parent3166d0dfa402dc775298c3a3e0b1c214e5b109b1 (diff)
downloadlibimobiledevice-f62d64492050556b383ec3a5db66830e78f9fd56.tar.gz
libimobiledevice-f62d64492050556b383ec3a5db66830e78f9fd56.tar.bz2
idevicesyslog: [win32] Fix color output
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicesyslog.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 36cf420..8fd91c4 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -73,6 +73,36 @@ static char *line = NULL;
static int line_buffer_size = 0;
static int lp = 0;
+#ifdef WIN32
+static WORD COLOR_RESET = 0;
+static HANDLE h_stdout = INVALID_HANDLE_VALUE;
+
+#define COLOR_NORMAL COLOR_RESET
+#define COLOR_DARK FOREGROUND_INTENSITY
+#define COLOR_RED FOREGROUND_RED |FOREGROUND_INTENSITY
+#define COLOR_DARK_RED FOREGROUND_RED
+#define COLOR_GREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
+#define COLOR_DARK_GREEN FOREGROUND_GREEN
+#define COLOR_YELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
+#define COLOR_DARK_YELLOW FOREGROUND_GREEN | FOREGROUND_RED
+#define COLOR_BLUE FOREGROUND_BLUE | FOREGROUND_INTENSITY
+#define COLOR_DARK_BLUE FOREGROUND_BLUE
+#define COLOR_MAGENTA FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY
+#define COLOR_DARK_MAGENTA FOREGROUND_BLUE | FOREGROUND_RED
+#define COLOR_CYAN FOREGROUND_BLUE | FOREGROUND_GREEN
+#define COLOR_BRIGHT_CYAN FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
+#define COLOR_DARK_CYAN FOREGROUND_BLUE | FOREGROUND_GREEN
+#define COLOR_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
+#define COLOR_DARK_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
+
+static void TEXT_COLOR(WORD attr)
+{
+ if (use_colors) {
+ SetConsoleTextAttribute(h_stdout, attr);
+ }
+}
+#else
+
#define COLOR_RESET "\e[m"
#define COLOR_NORMAL "\e[0m"
#define COLOR_DARK "\e[2m"
@@ -93,6 +123,7 @@ static int lp = 0;
#define COLOR_DARK_WHITE "\e[0;37m"
#define TEXT_COLOR(x) if (use_colors) { fwrite(x, 1, sizeof(x)-1, stdout); }
+#endif
static void add_filter(const char* filterstr)
{
@@ -298,7 +329,11 @@ static void syslog_callback(char c, void *user_data)
/* log level */
char* level_start = p;
char* level_end = p;
+#ifdef WIN32
+ WORD level_color = COLOR_NORMAL;
+#else
const char* level_color = NULL;
+#endif
if (!strncmp(p, "<Notice>:", 9)) {
level_end += 9;
level_color = COLOR_GREEN;
@@ -511,6 +546,13 @@ static void print_usage(int argc, char **argv, int is_error)
int main(int argc, char *argv[])
{
+#ifdef WIN32
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (GetConsoleScreenBufferInfo(h_stdout, &csbi)) {
+ COLOR_RESET = csbi.wAttributes;
+ }
+#endif
int include_filter = 0;
int exclude_filter = 0;
int include_kernel = 0;