Skip to content

Commit 0fe3b0d

Browse files
alimpfardawesomekling
authored andcommitted
functrace: Output colors only when stdout is a tty
1 parent 2714bba commit 0fe3b0d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Userland/functrace.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <unistd.h>
4949

5050
OwnPtr<DebugSession> g_debug_session;
51+
static bool g_should_output_color = false;
5152

5253
static void handle_sigint(int)
5354
{
@@ -70,8 +71,8 @@ void print_syscall(PtraceRegisters& regs, size_t depth)
7071
for (size_t i = 0; i < depth; ++i) {
7172
printf(" ");
7273
}
73-
const char* begin_color = "\033[34;1m";
74-
const char* end_color = "\033[0m";
74+
const char* begin_color = g_should_output_color ? "\033[34;1m" : "";
75+
const char* end_color = g_should_output_color ? "\033[0m" : "";
7576
printf("=> %sSC_%s(0x%x, 0x%x, 0x%x)%s\n",
7677
begin_color,
7778
Syscall::to_string(
@@ -115,6 +116,9 @@ int main(int argc, char** argv)
115116
return 1;
116117
}
117118

119+
if (isatty(STDOUT_FILENO))
120+
g_should_output_color = true;
121+
118122
const char* command = nullptr;
119123
Core::ArgsParser args_parser;
120124
args_parser.add_positional_argument(command,

0 commit comments

Comments
 (0)