Llew_Llaw_Gyffes has asked for the wisdom of the Perl Monks concerning the following question:

I have a piece of code I'm working on (for those interested, it's a lightweight, extensible Perl ICB client intended to replace CICB) which really needs to be able to use Curses.pm and Term::ANSIColor.

Either one individually works. The interactive mode that uses Curses works fine so long as I don't try to turn on color, and Term::ANSIColor works fine in the non-interactive query-only mode that doesn't use Curses. However, they won't work together. Curses::has_colors() stubbornly returns false in terminals that I know full well not only support color, but support color in curses-based programs. I've updated my system curses library to ncurses-5.3, and updated to the latest release of Curses.pm, to no avail. Last night I updated to perl-5.8 in the hope that this was one of the many bugs fixed, only to find that Curses.pm won't even build under Perl 5.8.

I seek enlightenment as to why Curses.pm does not believe in color-capable terminals. I've heard it said, but have been unable to confirm, that this is because although it ostensibly supports all the functions, Curses.pm does not actually support color. Is this actually the case? And if so, is it possible for me to use ncurses functions directly through the syscall interface to achieve my desired ends of color text in a curses window?

(My copies of the books of the sainted scribes of O'Reilly are, sadly, in storage until I find work again.)

Replies are listed 'Best First'.
Re: Curses.pm with Term::ANSIColor
by Zaxo (Archbishop) on May 05, 2003 at 00:17 UTC

    There is a patch to build Curses with perl 5.8.

    The test suite has color tests, run them to check what Curses will do.

    After Compline,
    Zaxo

      Sadly, this patch does not appear to produce a working Curses.pm on my systems. However, by subtly undefining and defining ERR (present in the ncurses header files, but not apparently picked up correctly) in appropriate cases, I've managed to get it to build, install and work. :)
Re: Curses.pm with Term::ANSIColor
by Improv (Pilgrim) on May 05, 2003 at 13:22 UTC
    I've often found that has_colors() is deficient, and that you can often do better by just looking at $ENV{TERM} and guessing. start_color() doesn't need has_colors() to return true to work -- try writing some test scripts that do initscr(), start_color(), and see what happens, like this:
    #!/usr/bin/perl use Curses; my $cid = 12; # Just an arbitrary slot initscr(); start_color(); init_pair($cid, ::COLOR_BLUE, ::COLOR_BLACK); $blbk = COLOR_PAIR($cid); attron($blbk); addstr(0,0,"Hey"); refresh(); sleep(3); endwin();
      I'll try this right away, having just gotten Curses.pm patched to build with 5.8 and threading.
        has_colors() is indeed lying. However, Term::ANSIColor still does not work in a curses window, when Curses color does. So I guess I get to rewrite all the color code for the interactive portion of the program to do its colors that way.