frida / frida-tools

Frida CLI tools
Other
338 stars 95 forks source link

respond to the NO_COLOR environment variable by suppressing color output #148

Closed smcpeak closed 3 months ago

smcpeak commented 7 months ago

The Frida console tools such as frida-trace should, IMO, respond to the NO_COLOR environment variable. Specifically, when this variable is set to a non-empty string, the tools should not emit color-changing escape sequences. See https://no-color.org/ .

I believe the following diff suffices:

--- a/frida_tools/application.py
+++ b/frida_tools/application.py
@@ -147,7 +147,10 @@ class ConsoleApplication:
         if hasattr(signal, "SIGPIPE"):
             signal.signal(signal.SIGPIPE, signal.SIG_DFL)

-        colorama.init(strip=True if plain_terminal else None)
+        # If true, emit text without colors.  https://no-color.org/
+        no_color = plain_terminal or bool(os.environ.get("NO_COLOR"))
+
+        colorama.init(strip=True if no_color else None)

         parser = self._initialize_arguments_parser()
         real_args = compute_real_args(parser, args=args)

Note that the changed code does not set plain_terminal (and hence self._plain_terminal) to True if NO_COLOR is set, because self._plain_terminal is used by ps.py and repl.py for terminal capabilities unrelated to color, and NO_COLOR should not affect those.

I'd be happy to submit a PR if that would be helpful.

s1341 commented 7 months ago

Please submit a PR.