Hi, Basically, I'm trying to make a small, program using the curses library, in perl. Now, I'm trying to go to a new screen/window after the user selects a menu choice.
Here is some example code i was working on and using:

From here: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ncurses_programs/perl/10.pl

and the code is:

#!/usr/bin/perl # # Copyright (C) 2003 by Virtusa Corporation # http://www.virtusa.com # # Anuradha Ratnaweera # http://www.linux.lk/~anuradha/ # use Curses; $width = 30; $height = 10; $startx = 0; $starty = 0; @choices = ( "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Exit" ); $n_choices = @choices; $highlight = 1; $choice = 0; initscr(); clear(); noecho(); cbreak(); $startx = ($COLS - $width) / 2; $starty = ($LINES - $height) / 2; $menu_win = newwin($height, $width, $starty, $startx); keypad(1); keypad($menu_win, 1); addstr(0, 0, "Use arrow keys to go up and down, Press enter to select +a choice"); refresh(); print_menu($menu_win, $highlight); while (1) { $c = getch($menu_win); if ($c == KEY_UP) { if ($highlight == 1) { $highlight = $n_choices; } else { $highlight--; } } elsif ($c == KEY_DOWN) { if ($highlight == $n_choices) { $highlight = 1; } else { $highlight++; } } elsif ($c == '\n') { $choice = $highlight; } else { addstr($LINES - 2, 0, "Character pressed is $c"); refresh(); } print_menu($menu_win, $highlight); last if ($choice); } addstr($LINES - 2, 0, "You chose choice $choice with choice string $ch +oices[$choice-1]"); clrtoeol(); refresh(); endwin(); sub print_menu { $menu_win = shift; $highlight = shift; $x = 2; $y = 2; box($menu_win, 0, 0); for ($i = 0; $i < $n_choices; $i++) { if ($highlight == $i + 1) { attron($menu_win, A_REVERSE); addstr($menu_win, $y, $x, $choices[$i]); attroff($menu_win, A_REVERSE); } else { addstr($menu_win, $y, $x, $choices[$i]); } $y++; } refresh($menu_win); }

There are two main problems, the first is how to get to the next screen after user gets a choice?, the other problem is whenever they click a letter, it displays a error, i can't figure out how to prevent this. How can i get input only from the up and down arrow keys and the enter button, disregarding all other keys? Thanks for the help monks!


In reply to Using the curses library to build a menu, and go to new windows by The Elite Noob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.