Python curses color print code escape codes

I have a bash script that prints a beautiful large colorful table using the foreground and background escape codes created with tput . My curses application should call this bash script and put the output on the screen.

When I try to do this, curses explode with a stacktrace ending in:

 File "./dostuff.py", line 38, in print_art screen.addstr(y, x_start, line) TypeError: must be str, not bytes 

Where the "string" looks something like this:

'\x1b[44m\x1b[30mcard major minor revision runs updated\x1b(B\x1b[m\x1b(B\x1b[m\n'

Is there a way to make curses interpret these color codes? Any processing I could do for a color-coded string to make curses? Or do I need to basically remove the color from the bash script and then override the coloring in python?

EDIT:

The command that receives bash output looks something like this:

 print_art(subprocess.Popen(["./automount", "backup", "list"], stdout=subprocess.PIPE).communicate()[0]) 

By calling decode() on a byte string, I can get curses for printing lines, albeit with literal escape sequences. If I don’t hear from anyone else, I will simply analyze these literary evacuation sequences manually and convert to use the curses color methods.

+5
source share

All Articles