1 # menu for DCT, by Shiar
3 # 1.06.1 200409152332 - moved @menus from 1.6 main
4 # 1.09.1 200410112150 - everything related to menus moved here
5 # 1.10.1 200410122210 - @menus global; unit+math items added in those modules
6 # .2 200410122345 - addmenu() function to add submenus
7 # .3 200410150030 - don't show undefined menu entries (skippable)
8 # .4 200410150030 - add quit at F10 in main menu (after running other modules)
15 "\033\117\120" => 1, # f1
16 "\033\133\061\061\176" => 1, # f1
17 "\033\133\061\062\176" => 2, # f2
18 "\033\133\061\063\176" => 3, # f3
19 "\033\133\061\064\176" => 4, # f4
20 "\033\117\121" => 2, # f2
21 "\033\117\122" => 3, # f3
22 "\033\117\123" => 4, # f4
23 "\033\133\061\065\176" => 5, # f5
24 "\033\133\061\067\176" => 6, # f6
25 "\033\133\061\070\176" => 7, # f7
26 "\033\133\061\071\176" => 8, # f8
27 "\033\133\062\060\176" => 9, # f9
28 "\033\133\062\061\176" => 10, # f10
29 "\033\133\062\063\176" => 11, # f11/F1
30 "\033\133\062\064\176" => 12, # f12/F2
31 "\033\133\062\065\176" => 13, # F3
32 "\033\133\062\066\176" => 14, # F4
33 "\033\133\062\070\176" => 15, # F5
34 "\033\133\062\071\176" => 16, # F6
35 "\033\133\063\061\176" => 17, # F7
36 "\033\133\063\062\176" => 18, # F8
37 "\033\133\063\063\176" => 19, # F9
38 "\033\133\063\064\176" => 20, # F10
39 "\033\133\062\063\073\062\176" => 21, # F11
40 "\033\133\062\064\073\062\176" => 22, # F12
41 "\033\061" => 1, # alt+1
42 "\033\062" => 2, # alt+2
43 "\033\063" => 3, # alt+3
44 "\033\064" => 4, # alt+4
45 "\033\065" => 5, # alt+5
46 "\033\066" => 6, # alt+6
47 "\033\067" => 7, # alt+7
48 "\033\070" => 8, # alt+8
49 "\033\071" => 9, # alt+9
50 "\033\060" => 10, # alt+0
53 #our @menus = ([qw(refresh quit)]);
55 [qw(refresh prog> mode>1)], # main
56 [qw(main>0 number_format angle_measure coord_system)], #1 mode
61 push @menus, ["$parent->[0]>$parent->[1]"]; # create new menu
62 my $menuthis = $#menus;
63 push @{$menus[$parent->[1]]}, shift(@_).">$menuthis"; # link from parent
64 ref $_ ? addmenu([$_->[0], $menuthis], @$_) # add subsubmenu
65 : push @{$menus[$menuthis]}, $_ for @_; # add menu items
73 push @{$hook{init}}, sub {
74 $menus[0][10] = "quit";
76 $set{height}--; # make space for menubar
77 $set{menushow} = int($set{width}/(4+$set{width}/20))+1 # menu items to show simultaneously
78 unless defined $set{menushow};
82 clrtoeol($set{height}+2, 1);
84 for (grep exists $menu[$_], $menumin+1..$menumin+$set{menushow}) {
86 next unless defined $menu[$_];
87 my $sub = (my $s = $menu[$_]) =~ s/>\d+$//;
88 addstr($set{height}+2, $set{width}/$set{menushow}*$nr, $_);
92 addch('>') if $sub; # indicate submenu
96 $action{more} = [-1, sub {
97 $menumin += $set{menushow};
98 $menumin = 0 if $menumin>=$#menu;
102 push @{$hook{refresh}}, sub {
106 unshift @{$hook{precmd}}, sub {
107 return unless exists $falias{$_}; # not a function key
108 return if $_ = $menu[$falias{$_}]; # execute found menu item instead
109 error("* no such menu entry *");
113 push @{$hook{precmd}}, sub {
114 return unless />(\d+)$/;
115 @menu = @{$menus[$1]}; # go to submenu
116 $menumin = 0; # reset to first item