diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 42b6191e..c60f16da 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1062,6 +1062,7 @@ sub _set_paths alert_emails => "/var/spool/anvil", anvil => "/etc/anvil", backups => "/root/anvil-backups", + bonds => "/proc/net/bonding", 'cgi-bin' => "/var/www/cgi-bin", drbd_resources => "/etc/drbd.d/", fence_agents => "/usr/sbin", diff --git a/Anvil/Tools/Convert.pm b/Anvil/Tools/Convert.pm index b1589a36..0423f89f 100644 --- a/Anvil/Tools/Convert.pm +++ b/Anvil/Tools/Convert.pm @@ -137,7 +137,7 @@ sub add_commas $whole = $_; # Put it together - $number = $decimal ? "$whole.$decimal" : $whole; + $number = $decimal ? $whole.".".$decimal : $whole; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { number => $number }}); return ($number); diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index adc38e2d..672ebd15 100644 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -18,6 +18,7 @@ my $THIS_FILE = "Words.pm"; # $ENV{'PERL_UNICODE'} = 1; ### Methods; +# center_text # clean_spaces # key # language @@ -93,6 +94,92 @@ sub parent # Public methods # ############################################################################################################# + +=head2 center_text + +This takes a string and an integer and pads the string with spaces on either side until the length is that of the integer. For uneven splits, the smaller number of spaces will be on the left. + +Paramters; + +=head3 string + +This is the string being centered. If not given, and empty string is returned. + +B<< Note >>: This can be C<< #!string!x!# >>. If this is passed, the string will be translated before being centered. + +=head3 width + +This is an integer of how width the centered string should be. + +=cut +sub center_text +{ + my $self = shift; + my $parameter = shift; + my $anvil = $self->parent; + my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Words->center_text()" }}); + + # Pick up the parameters. + my $string = defined $parameter->{string} ? $parameter->{string} : ""; + my $width = defined $parameter->{width} ? $parameter->{width} : 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + string => $string, + width => $width, + }}); + + return($string) if $width eq ""; + return("") if $parameter->{string} eq ""; + + ### NOTE: If a '#!string!x!#' is passed, the Log->entry method will translate it in the log itself, + ### so you won't see that string. + if ($string =~ /#!string!(.*?)!#/) + { + $string = $anvil->Words->string({key => $1}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }}); + } + + my $current_length = length($string); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { current_length => $current_length }}); + if ($current_length < $width) + { + my $difference = $width - $current_length; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { difference => $difference }}); + if ($difference == 1) + { + $string .= " "; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }}); + } + else + { + my $remainder = $difference % 2; + $difference -= $remainder; + my $spaces = $difference / 2; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + remainder => $remainder, + spaces => $spaces, + }}); + for (1..$spaces) + { + $string = " ".$string." "; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }}); + } + if ($remainder) + { + $string .= " "; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }}); + } + } + } + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + string => $string, + 'length' => length($string), + }}); + return($string); +} + + =head2 clean_spaces This methid takes a string via a 'C<< line >>' parameter and strips leading and trailing spaces, plus compresses multiple spaces into single spaces. It is designed primarily for use by code parsing text coming in from a shell command. diff --git a/share/words.xml b/share/words.xml index 3673aa94..9c8de6e1 100644 --- a/share/words.xml +++ b/share/words.xml @@ -710,6 +710,14 @@ sys::manage::firewall = 1 Synced Remove #!string!brand_0006!# Name + Active Interface + Bond Mode + Active Interface + Link State + Duplex + Link Drops + + Configure Network @@ -2574,6 +2582,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st Fahrenheit % Amps + Going Back