I have a bash script that prints a nice big colorful table, using escape codes for foreground and background generated from tput. My curses application needs to call this bash script and put the output on the screen.
When I try to do that, curses explodes with a stacktrace ending at:
File "./dostuff.py", line 38, in print_art
screen.addstr(y, x_start, line)
TypeError: must be str, not bytes
Where "line" is something like:
'\x1b[44m\x1b[30mcard major minor revision runs updated\x1b(B\x1b[m\x1b(B\x1b[m\n'
Is there any way to make curses interpret these color codes? Any processing I could do to the string with the color codes to make curses display it? Or do I have to basically remove color from the bash script and then reimplement the colorization in python?
EDIT:
The command that gets the bash output is something like:
print_art(subprocess.Popen(["./automount", "backup", "list"], stdout=subprocess.PIPE).communicate()[0])
By calling decode() on the byte string, I can get curses to print the strings, albeit with literal escape sequences. Unless I hear from anyone else, I'm just going to parse these literal escape sequences manually and convert to use curses color methods.