[Chicago-talk] Help hacking some code.

Richard Reina richard at rushlogistics.com
Fri Oct 2 05:50:53 PDT 2009


For a number of years I have been using Steve Kunz perlmenu.pm as a nice low overhead GUI for a database app.  I am very happy with it.  However, I am try to dig deep into its code to solve a mystery. I have written the author and have not heard back so I was hoping that perhaps someone here might lend some advice. The code below provides a basic menu and I am trying to add color by placing 

use Term::ANSIColor;
print color 'bold blue';

in different parts of the code in order to try an add color. No matter where I seem to place it, no color is displayed. I have even tried placing it in the menu_display subroutine -- which is called in the code -- in perlmenu.pm.  Please find that subroutine further down.  All of the code in perlmenu.pm is posted here http://kobesearch.cpan.org/htdocs/perlmenu/perlmenu.pm.html

For several days I have been searching -- to no avail -- for some kind of system("reset") in the code that would blow away color.  Is this something that Curses is canceling out?  From what I understand perl Curses does support color, so I am confused about what is preventing this from working.  Does anyone have any ideas as to how I can go about achieving this task?

Any help would be greatly appreciated and if there are any MLB fans listening I will gladly donate my 4 seats down the third base line for today's 1:20 game against the Arizona Diamondbacks in exchange for help solving this problem.

BEGIN { $Curses::OldCurses = 1; }
use Curses;
use perlmenu;
...
&menu_init(1,"Select an Animal"); # Init menu

&menu_item("Collie","dog"); # Add item
&menu_item("Shetland","pony"); # Add item
&menu_item("Persian","cat"); # Add last item

$sel = &menu_display("Which animal?"); # Get user selection

if ($sel eq "%UP%") { ... }
if ($sel eq "dog") { ... }



#**********
#  MENU_DISPLAY 
#
#  Function:	Display items in menu_sel_text array, allow selection, and
#		return appropriate selection-string.
#
#  Call format:	$sel = &menu_display("Prompt text",$arrow_line,$top_item);
#
#  Arguments:   - Prompt text (for the bottom line of menu).
#		- Line number offset for the arrow (defaults to zero).
#		- Index of top item on screen (defaults to zero).
#		- Column number offset for the arrow (multiple-column mode
#		  only, defaults to zero).
#
#  Returns:     Selected action string (from second param on &menu_item)
#		%UP%    -- "u"|"U" pressed (or "t"|"T" and looking for top)
#               %EMPTY% -- Nothing in menu to display
#
#  Notes:	1) This routine ALWAYS sets "nocbreak" and "echo" terminal 
#		   modes before returning.
#		2) This routine exits directly (after calling the optional 
#		   "quit" routine) if "q"|"Q" is pressed.
#**********
sub menu_display {
  ($menu_prompt,$arrow_spec_row,$menu_top_item,$arrow_spec_col) = @_;
  local($ret);

# Check for no "menu_item" calls.
  $total_items = $#menu_sel_text + 1;
  if ($total_items <= 0) {
    &nocbreak();		# ALWAYS turn off "cbreak" mode
    &echo();		# ALWAYS turn on "echo"
    return("%EMPTY%");
  }

  &clear(); $xrow = $xcol = 0;
  $last_menu_top_item = -1;	# Force drawing of menu items
  $ret = &menu_display_internal(0,$menu_prompt,0);
  if ($#_ > 0) { $_[1] = $arrow_spec_row; }
  if ($#_ > 1) { $_[2] = $menu_top_item; }
  if ($#_ > 2) { $_[3] = $arrow_spec_col; }
  &menu_return_prep();
  $ret;
}


More information about the Chicago-talk mailing list