Merge pull request #42 from solgenomics/topic/duplicate_image_warning
[cxgn-corelibs.git] / lib / CXGN / Tools / Terminal.pm
blob1c35d964262236b4a7b8c7a6529812b2bd49be6d
1 package CXGN::Tools::Terminal;
3 use strict;
5 =head1 CXGN::Tools::Terminal
7 Little utilities for terminal-based scripts
9 =cut
11 use base qw/Exporter/;
13 BEGIN {
14 our @EXPORT_OK = qw/ get_userpass
15 progress
16 confirm
21 sub get_userpass {
22 print "\nEnter username: ";
23 my $username = <STDIN>;
24 chomp $username;
25 print "Enter password: ";
26 system "stty -echo";
27 my $password = <STDIN>;
28 system "stty echo";
29 print "\n";
30 chomp $password;
31 return ($username, $password);
35 sub progress {
36 my ($count, $max) = @_;
37 return unless($count && $max); #count=0 returns immediately, count = 1 starts it off
38 if($count==1){ print "\nProgress:||"}
39 my $step_size = int($max / 8) - 1;
40 if($count==$step_size) { print "===12%"; }
41 elsif($count==2*$step_size) { print "===25%";}
42 elsif($count==3*$step_size) { print "===37%";}
43 elsif($count==4*$step_size) { print "===50%";}
44 elsif($count==5*$step_size) { print "===62%";}
45 elsif($count==6*$step_size) { print "===75%";}
46 elsif($count==7*$step_size) { print "===88%";}
47 elsif($count==8*$step_size) { print "===100%\n";}
51 sub confirm {
52 my $message = shift;
53 $message =~ s/\s+$//;
54 $message .= "," unless $message =~ /\.$/;
55 print $message;
56 print " Continue? [y/n]: ";
57 my $r = <STDIN>;
58 return 1 unless $r =~ /^n/i;
59 return 0;