1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package rt::ui::cli;
sub question_string{
local ($question,$default)=@_;
local ($response);
if ($default) {
print "$question \[$default\]:";
}
else {
print "$question:";
}
$response=&input_string($default);
return($response);
}
sub question_yes_no{
local ($question,$default)=@_;
local ($response);
if ($default) {
if ($default eq "1") {
$default='Y';
}
else {
$default='N';
}
print "$question \[$default\]:";
}
else {
print "$question [N]:";
} $response=&input_yes_no($default);
return($response);
}
sub question_int{
local ($question,$default)=@_;
local ($response);
if ($default) {
print "$question \[$default\]:";
}
else {
print "$question:";
} $response=&input_int($default);
return($response);
}
sub input_yes_no {
local ($default) =@_;
local ($input);
chop($input=<STDIN>);
if (!$input) {
$input=$default;
}
if ($input =~ /^(y|Y|1|t)/) {
return(1);
}
else {
return(0);
}
}
sub input_string {
local ($default) =@_;
local ($input);
chop($input=<STDIN>);
if (!$input) {
$input=$default;
}
return($input);
}
sub input_int {
local ($default) =@_;
local ($input);
chop($input=<STDIN>);
$input=int($input);
if (!$input) {
$input=int($default);
}
return($input);
}
1;
|