in reply to Menus on the terminal

This is a little something I wipped up when I was having to make menu's on the linux console windows.

Menu.pm. There is no installer, currently I just copy it to Mikes in the perl folder. Once that is done you can call it.

package Mikes::Menu; use strict; use Time::localtime; use Exporter; use strict; use warnings; #use carp qw(croak); # Need to figure out for the die funtions. Die lo +oks bad in a module. <readmore> our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); @ISA=qw(Exporter); @EXPORT=qw(win_clear nix_clear char new_char char_new new_char_new hea +d head_new right right_new left left_new); @EXPORT_OK=qw(logit); %EXPORT_TAGS=( all => [ @EXPORT ] ) ; $VERSION = 0.09; #my $pass = ($char,$width) sub char { print "$_[0]" x "$_[1]"; } sub new_char { newline(); char(@_); } sub char_new { char(@_); newline(); } sub new_char_new { # my $char = shift; # my $width = shift; my ($char,$width) = @_; newline(); char($char,"1"); char($char,$width); newline(); } sub win_clear { #my $cls= system `cls`; #my $cls = system "cls"; # print $cls; system "cls"; #system "cls\n"; #my $clear = system "cls"; #chop $clear; #print $clear; } sub nix_clear { system "clear\n"; } sub newline { print "\n"; } sub head { char($_[0],$_[1]); center(@_); char($_[0],$_[1]); } sub center { my $h1; my $h2; my $test = length ($_[2]); my $space = $_[1] - $test; my $half = $space / "2" - "1"; if($half =~ /^\d\d\.5$/){ # if($half =~ /^\d\d\.5$/){ $h1 = $half + ".5"; $h2 = $half - ".5"; } else { $h2 = $half; $h1 = $half; } char($_[0],"1");char(" ","$h1");print"$_[2]";char(" ","$h2");char( +$_[0],"1"); } sub center_new { my $h1; my $h2; my $test = length ($_[2]); my $space = $_[1] - $test; my $half = $space / "2" - "1"; if($half =~ /^\d\d\.5$/){ $h1 = $half + ".5"; $h2 = $half - ".5"; } else { $h2 = $half; $h1 = $half; } char($_[0],"1");char(" ","$h1");print"$_[2]";char(" ","$h2");char( +$_[0],"1"); newline(); } sub head_new { char_new($_[0],$_[1]); center_new(@_); char_new($_[0],$_[1]); } sub right # think of new name for left justify. { my $test = length ($_[2]); my $space = $_[1] - $test; my $space2 = $space - "2"; char($_[0],"1");char(" ",$space2);print"$_[2]";char($_[0],"1"); # char($_[0],"1");print"$_[2]";char(" ",$space2);char($_[0],"1"); } sub right_new { my $test = length ($_[2]); my $space = $_[1] - $test; my $space2 = $space - "2"; char($_[0],"1");char(" ",$space2);print"$_[2]";char($_[0],"1"); newline(); } sub left { my $test = length ($_[2]); my $space = $_[1] - $test; my $space2 = $space - "2"; char($_[0],"1");print"$_[2]";char(" ",$space2);char($_[0],"1"); } sub left_new { my $test = length ($_[2]); my $space = $_[1] - $test; my $space2 = $space - "2"; char($_[0],"1");print"$_[2]";char(" ",$space2);char($_[0],"1"); newline(); } sub logit { my $user = getlogin() || getpwuid($<) || die print "Cannot Determi +ne Username"; my $str = shift; my $file = shift || "c:/default_log.txt" || "/home/$user/defau +lt_log.txt"; my ($wday, $month, $day, $t, $year)=split(/\s+/, ctime); open (LOGFILE, ">>$file") or print "logit failed to append log +file"; print (LOGFILE "$year $month\-$day $t " . "$str\n"); # return ("$month\-$day $t " . "$str"); close LOGFILE; } 1

And a quick example of how to use. Do let me know if there is questions... It's not the greatest and the module that is posted does have other function that are not required. (my first module play ground)

#!/usr/bin/perl use Mikes::Menu; @_= qw(- 80 Mikes_test_menu); head(@_);
[download]
Quick rundown of function is module:

Any sub with the name of XXX_new adds a newline. This is designed for when you are creating the menu with a width of less than the total width of consol(you want 60 console is 80).

All of the subs in the module expect: 1st item passed chracter you want the menu created out of. 2nd item: how many times you want to print that character(width) The head also expected a third item of text title you want printed... I will do a better doc on this if it is requested... I am at work jsut trying to get this up and see if it will help. Let me know!