release 1.11.2
[descalc.git] / 15_menu.pm
index c75f442deb7e4098665eaaab111e423108425527..7af32dbb8cdf8f01ed4f71f064dc448e84630b4b 100644 (file)
@@ -1,11 +1,13 @@
 # menu for DCT, by Shiar
 
-# 1.06.1 200409152332 - moved @menus from 1.6 main
-# 1.09.1 200410112150 - everything related to menus moved here
+# 1.11.0 200410282200 - display-specific code in evals
+# 1.10.4 200410151900 - remove explicit call to redraw on error
+# 1.10.3 200410150030 - add quit at F10 in main menu (after running other modules)
+#                     - don't show undefined menu entries (skippable)
+# 1.10.2 200410122345 - addmenu() function to add submenus
 # 1.10.1 200410122210 - @menus global; unit+math items added in those modules
-#     .2 200410122345 - addmenu() function to add submenus
-#     .3 200410150030 - don't show undefined menu entries (skippable)
-#     .4 200410150030 - add quit at F10 in main menu (after running other modules)
+# 1.09.1 200410112150 - everything related to menus moved here
+# 1.06.1 200409152332 - moved @menus from 1.6 main
 
 use strict;
 use warnings;
@@ -67,8 +69,8 @@ sub addmenu {
 } # addmenu
 
 #my @menu = [];
-my @menu;
-my $menumin = 0;
+our @menu;
+our $menumin = 0;
 
 push @{$hook{init}}, sub {
        $menus[0][10] = "quit";
@@ -78,19 +80,36 @@ push @{$hook{init}}, sub {
                unless defined $set{menushow};
 }; # init
 
+my %show = (
+       curses => q{
+               clrtoeol($set{height}+2, 1);
+               my $nr = -1;
+               for (grep exists $menu[$_], $menumin+1..$menumin+$set{menushow}) {
+                       $nr++;
+                       next unless defined $menu[$_];
+                       my $sub = (my $s = $menu[$_]) =~ s/>\d+$//;
+                       addstr($set{height}+2, $set{width}/$set{menushow}*$nr, $_);
+                       attron(A_REVERSE);
+                       addstr($s);
+                       attroff(A_REVERSE);
+                       addch('>') if $sub;  # indicate submenu
+               } # display menu txts
+       },
+       stdout => q{
+               my $nr = -1;
+               for (grep exists $menu[$_], $menumin+1..$menumin+$set{menushow}) {
+                       $nr++;
+                       next unless defined $menu[$_];
+                       my $sub = (my $s = $menu[$_]) =~ s/>\d+$//;
+                       print " $_:$s";
+                       print ">" if $sub;  # indicate submenu
+               } # display menu txts
+               print "\n> ";
+       },
+);
+
 sub showmenu() {
-       clrtoeol($set{height}+2, 1);
-       my $nr = -1;
-       for (grep exists $menu[$_], $menumin+1..$menumin+$set{menushow}) {
-               $nr++;
-               next unless defined $menu[$_];
-               my $sub = (my $s = $menu[$_]) =~ s/>\d+$//;
-               addstr($set{height}+2, $set{width}/$set{menushow}*$nr, $_);
-               attron(A_REVERSE);
-               addstr($s);
-               attroff(A_REVERSE);
-               addch('>') if $sub;  # indicate submenu
-       } # display menu txts
+       eval $_ if local $_ = $show{$::modules{disp}{name}};
 } # showmenu
 
 $action{more} = [-1, sub {
@@ -106,8 +125,8 @@ push @{$hook{refresh}}, sub {
 unshift @{$hook{precmd}}, sub {
        return unless exists $falias{$_};  # not a function key
        return if $_ = $menu[$falias{$_}];  # execute found menu item instead
-       error("* no such menu entry *");
-       goto DRAW;
+       error("no such menu entry");
+       return 1;
 }; # precmd
 
 push @{$hook{precmd}}, sub {
@@ -121,6 +140,6 @@ push @{$hook{precmd}}, sub {
 return {
        author  => "Shiar",
        title   => "menu",
-       version => "1.10.4",
+       version => "1.11",
 };