summaryrefslogtreecommitdiff
path: root/make/utilities.pm
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2014-10-01 19:52:23 +0100
committerPeter Powell <petpow@saberuk.com>2014-12-07 22:36:42 +0000
commit11f4d02e7020cb5775d2b89af0e652e53cd90ed7 (patch)
tree17bc1cc90d178cd470c60a421ef7e947fb94b9c9 /make/utilities.pm
parent48f8f79317a04891e2becd859363add6eb2d6444 (diff)
Add Perl module for console related code.
- Move prompt_* methods to this module. - Add methods for printing errors and warnings easily. - Add colour code helpers and switch all code to use them.
Diffstat (limited to 'make/utilities.pm')
-rw-r--r--make/utilities.pm37
1 files changed, 1 insertions, 36 deletions
diff --git a/make/utilities.pm b/make/utilities.pm
index 7db557d11..4103e38f3 100644
--- a/make/utilities.pm
+++ b/make/utilities.pm
@@ -32,11 +32,10 @@ use warnings FATAL => qw(all);
use Exporter 'import';
use Fcntl;
use File::Path;
-use File::Spec::Functions qw(rel2abs);
use Getopt::Long;
use POSIX;
-our @EXPORT = qw(get_version module_installed prompt_bool prompt_dir prompt_string get_cpu_count make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
+our @EXPORT = qw(get_version module_installed get_cpu_count make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
my %already_added = ();
my %version = ();
@@ -79,40 +78,6 @@ sub module_installed($) {
return !$@;
}
-sub prompt_bool($$$) {
- my ($interactive, $question, $default) = @_;
- my $answer = prompt_string($interactive, $question, $default ? 'y' : 'n');
- return $answer =~ /y/i;
-}
-
-sub prompt_dir($$$) {
- my ($interactive, $question, $default) = @_;
- my ($answer, $create) = (undef, 'y');
- do {
- $answer = rel2abs(prompt_string($interactive, $question, $default));
- $create = prompt_bool($interactive && !-d $answer, "$answer does not exist. Create it?", 'y');
- my $mkpath = eval {
- mkpath($answer, 0, 0750);
- return 1;
- };
- unless (defined $mkpath) {
- print "Error: unable to create $answer!\n\n";
- $create = 0;
- }
- } while (!$create);
- return $answer;
-}
-
-sub prompt_string($$$) {
- my ($interactive, $question, $default) = @_;
- return $default unless $interactive;
- print $question, "\n";
- print "[\e[1;32m$default\e[0m] => ";
- chomp(my $answer = <STDIN>);
- print "\n";
- return $answer ? $answer : $default;
-}
-
sub get_cpu_count {
my $count = 1;
if ($^O =~ /bsd/) {