python - How to display pre-colored string with curses? -
i'm writing curses program in python. i'm beginner of curses i've used terminal control sequences colored output.
now there's code snippets print inside window, i'd them syntax highlighted, , it's better done libraries pygments, outputs highlighted code control sequences.
initially feed pygments output directly window.addstr()
, turned out control sequences escaped , whole highlighted string printed on screen (just this: https://too-young.me/web/repos/curses-highlight.png). how can display directly curses, cat
?
this has been asked several times, same answer: write parser this. related discussion:
- how use ansi escape codes inside mvwprintw in ncurses?
- comment on parsing ansi color escape sequences
- handle escape sequences ncurses? printf handle escape sequences?
it not suitable extension ncurses example because:
- curses produces escape sequences, wide variety of devices (which may not "ansi color escapes").
- ncurses (see faq why aren't bugs being fixed?) not provide extension because parser of type not rely upon of ncurses' internals.
Comments
Post a Comment