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

I have scoured the internet and even tried to send an email to the Curses::UI maintainer - but the email in CPAN is a dud. can anyone tell me from this documentation how i can create the color Orange (255,165,0): http://search.cpan.org/~mdxi/Curses-UI-0.9609/lib/Curses/UI/Color.pm I have tried like 50 different ways.

$cui->define_color('orange',255,155,0);



It's not a function, its not a method from the $cui (mainwindow) object, its not a method of the label object or anything like that, so i am confused by the poor documentation. Also Perl applications that use Curses::UI die without any errors or warnings ??? Thanks, return 0;

ADDITIONAL INFO: the author has put the code: -default-colors => BOOLEAN on the CPAN page also, which is broken and I think he/she meant: -default_colors=>BOOLEAN adding a new hyphen will break the code. Also they wrote: "Creates a new Curses::UI::Color object" and used the terms "method" AND "function" for define_color LOL this is very confusing!! I tried this:

#!/usr/bin/perl -w use strict; my $colorobj = new Curses::UI::Color; my @colors = $colorobj->get_colors(); print $_ foreach (@colors); exit;

which also did nothing. ??

UPDATE: Tried to contact author and maintainer of Curses::UI neither of which responded. After hours of testing and research, I have given up. This method define_color() does not work. I can add a color to the colors() array with it, but it ( the RGB value of the added color ) is NULL each time. marking as "unresolved."

Replies are listed 'Best First'.
Re: [Unresolved] Curses::UI define_color
by cxw (Scribe) on Jan 15, 2021 at 19:58 UTC

    Long-overdue, but I have a working version! I had to:

    • Use the latest Curses::UI (v0.9629) with the fix from rt://50142 (here)
    • Use only custom colors --- don't try to combine custom colors with standard colors
    • Set the color on the Curses::UI instance, the window, and every widget

    Et voila, a curses UI with an orange background and white text (tested on Perl 5.26):

    use strict; use warnings; use Curses::UI '0.9609'; my $cui = Curses::UI->new( -color_support => 1, -clear_on_exit => 1 ); $cui->set_binding( sub { $cui->mainloopExit() }, "\cC" ); # Colors my $co = $Curses::UI::color_object; $co->define_color( 'wh', 999, 999, 999 ); # range [1, 999] # For some reason, I don't seem to be able to mix # standard colors with custom colors. $co->define_color( 'orange', 999, 599, 1 ); my $FG = 'wh'; my $BG = 'orange'; my @COLORS = ( ( map { ; $_ => $BG } qw(-bg -tbg -bbg -sbg) ), ( map { ; $_ => $FG } qw(-fg -tfg -bfg -sfg) ) ); $cui->set_color_fg($FG); $cui->set_color_bg($BG); # Widgets my $win = $cui->add( 'main-window', 'Window', -border => 1, -title => "Ce n'est pas une fenetre", -titlefullwidth => 1, @COLORS, ); $win->add( 'help', 'Label', -y => 1, -width => -1, -reverse => 1, -paddingspaces => 1, -text => "Howdy! Press Ctl-C to exit.", @COLORS, ); $cui->mainloop; $cui->leave_curses;
Re: Curses::UI define_color
by kcott (Archbishop) on Apr 16, 2013 at 10:59 UTC

    G'day return0,

    While the Curses::UI::Color documentation is accurate when it says "The RGB values can be between 0 and 1000.", it's misleading as it doesn't indicate that's an exclusive range: the actual range of numbers available to you is 1..999.

    A pragmatic solution would be to use 1 instead of 0: the difference in colour would be imperceptible to the human eye. Alternatively, if the exact colour is important, you could modify the module.

    More as an afterthought, it's possible the RGB values you need for orange are more like 999,599,1 (I think 255,155,0 would be very dark). I'll leave you to experiment.

    -- Ken

      oh thank you! I didn't even look at the source code for this yet;I was really busy yesterday. I see it now:
       return unless $b > 0;
      Okay, I get it, and you're right about not seeing the difference, I remember that from Steganography 101. You guys are the best! thank you! :D
Re: Curses::UI define_color
by Anonymous Monk on Apr 16, 2013 at 07:37 UTC
      Unfortunately that doesn't seem to work.
      my $cui = new Curses::UI(-color_support=>1); # create a curses object my $co = $Curses::UI::color_object; $Curses::UI::color_object->define_color('orange',255,140,1);

      Doesn't return an error, but doesn't make any color - it just goes white. :( Is my code wrong? Thanks, ~return0