I'm trying to write a program that gets text containing ansi color codes and displays it to the user using curses. But I just can't figure out how to make curses handle the ansi codes correctly.
Here is an example of my problem. This program prints the text with curses and waits for the user to hit a key. Then exits curses and prints the text normally. The colors doesn't work in curses but do work when printed normally.
Code:
#!/usr/bin/env python
import curses
def colortest(main_window):
main_window.addstr(colorsample)
main_window.getch()
if __name__ == "__main__":
colorsample = """[32mThis is colored text.[37m
This is normal text.
[32mThis is colored text.[37m
This is normal text.
[32mThis is colored text.[37m
This is normal text.
"""
curses.wrapper(colortest)
print colorsample
Bookmarks