use Curses; use Term::ANSIColor; initscr(); addstr(stdscr, "a ".color('yellow')."YELLOW".color('reset')." word"); refresh(); getch(); endwin(); #### use Curses; use Term::ANSIColor; initscr(); start_color(); init_pair(1, COLOR_YELLOW, COLOR_BLACK); formatted_text(stdscr, "a ".color('yellow')."YELLOW".color('reset')." word"); refresh(); getch(); endwin(); sub formatted_text { my ( $win, $text ) = @_; # tokenize text on escape sequences foreach ( split(/(\e\[[^m]+m)/, $text) ) { # token starts with , set attr and dont add text if ( /^\e/ ) { if ( $_ =~ quotemeta(color('yellow')) ) { attron(COLOR_PAIR(1)); } elsif ( $_ =~ quotemeta(color('reset')) ) { attroff(COLOR_PAIR(1)); } next; } addstr($win, $_); } }