From 0f0279bd3f9e26b17f8eabc7b9450472e4f63020 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Thu, 21 Jan 2021 12:35:13 +0800 Subject: [PATCH] Output newline on stdout with hex print mode This is to fix the issue #104. The timestamp will always be printed at the beginning of line: [10:25:56] Switched to hexadecimal mode 0d 0a 0d [10:25:57] 41 43 52 4e 3a 5c 3e 0d 0a 0d [10:25:58] 41 is changed to: [12:34:56] 45 72 72 6f 72 3a 20 49 6e 76 61 6c 69 64 20 [12:34:56] 41 43 52 4e 3a 5c 3e [12:34:56] 41 43 52 4e 3a 5c 3e [12:34:57] 41 43 52 4e 3a 5c 3e 6c 73 --- src/tty.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tty.c b/src/tty.c index d0569b1..067179a 100644 --- a/src/tty.c +++ b/src/tty.c @@ -70,7 +70,12 @@ static bool map_o_del_bs = false; static void print_hex(char c) { - printf("%02x ", (unsigned char) c); + + if ((c == '\n') || (c == '\r')) + printf("%c", c); + else + printf("%02x ", (unsigned char) c); + fflush(stdout); }