Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Python3, color codes are printed instead of colors #182

Open
bobpaul opened this issue Oct 11, 2022 · 2 comments
Open

On Python3, color codes are printed instead of colors #182

bobpaul opened this issue Oct 11, 2022 · 2 comments

Comments

@bobpaul
Copy link

bobpaul commented Oct 11, 2022

I'm running on Bash 5.1.16 and have the TERM variables set appropriately:

$ env | grep TERM
COLORTERM=truecolor
TERM=xterm-256color

If I run pidcat with python3, I get output like this:

b'\x1b[37m        ActivityManager\x1b[0m \x1b[30;102m I \x1b[0m Process com.samsung.android.app.galaxyfinder:appservice (pid 18912) has died: fg  SVC (127,1420)'
b'\x1b[33matibilityChangeReporter\x1b[0m \x1b[30;104m D \x1b[0m Compat change id reported: 135634846; UID 10300; state: DISABLED'
b'                        \x1b[30;104m D \x1b[0m Compat change id reported: 143937733; UID 10300; state: ENABLED'

but if I run with python2, then I get colorized output as expected.

If I delete the .encode(utf-8) from the final print statement, then it works as expected on both Python2 and Python3, but I suspect this might cause problems on some systems if locale isn't utf-8.

$ git revert -n 6b6034ab67
Auto-merging pidcat.py
$ git reset
Unstaged changes after reset:
M	pidcat.py
$ git diff
diff --git a/pidcat.py b/pidcat.py
index 6a23786..4a2b42f 100755
--- a/pidcat.py
+++ b/pidcat.py
@@ -359,4 +359,4 @@ while adb.poll() is None:
     message = matcher.sub(replace, message)
 
   linebuf += indent_wrap(message)
-  print(linebuf.encode('utf-8'))
+  print(linebuf)
JamesConlan96 added a commit to JamesConlan96/pidcat that referenced this issue Jan 17, 2023
@davidmontemayor
Copy link

davidmontemayor commented Jul 28, 2023

Yup, ran into this as well. I guess not a lot of people use this script anymore? Thanks for pointing out the fix!

@cxzero
Copy link

cxzero commented Mar 17, 2024

Got the same error, thanks for sharing the workaround and the fix, hopefully gets merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants