From 2843de9ca70c41180b23d9d203fa870aa7279a02 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jul 15 2011 13:07:10 +0000 Subject: Update cli_printMessage.sh: - Start using MESSAGE_WIDTH variable. - Start using space character in its octal form (040) to represent the separation needed after colons (:) in request-lines and questions. We can not use mere space here, because this function might be called from itself more than once and trailing and leading spaces passed as MESSAGE will be lost. --- diff --git a/Scripts/Functions/cli_printMessage.sh b/Scripts/Functions/cli_printMessage.sh index fe5ba0b..d52ae63 100755 --- a/Scripts/Functions/cli_printMessage.sh +++ b/Scripts/Functions/cli_printMessage.sh @@ -38,6 +38,11 @@ function cli_printMessage { cli_printMessage "`gettext "The message cannot be empty."`" --as-error-line fi + # Define message horizontal width. This is the max number of + # horizontal characters the message will use to be displayed on + # the screen. + local MESSAGE_WIDTH=70 + # Reverse the codification performed on characters that may affect # parsing options and non-option arguments. This codification is # realized before building the ARGUMENTS variable, at @@ -54,19 +59,16 @@ function cli_printMessage { --as-separator-line ) - # Define width of separator line. - local MAX=70 - - # Build the separator line. - MESSAGE=$(\ - until [[ $MAX -eq 0 ]];do - echo -n "$MESSAGE" - MAX=$(($MAX - 1)) - done) + # Build the separator line. + MESSAGE=$(\ + until [[ $MESSAGE_WIDTH -eq 0 ]];do + echo -n "$MESSAGE" + MESSAGE_WIDTH=$(($MESSAGE_WIDTH - 1)) + done) - # Draw the separator line. - echo "$MESSAGE" > /dev/stderr - ;; + # Draw the separator line. + echo "$MESSAGE" > /dev/stderr + ;; --as-banner-line ) cli_printMessage '-' --as-separator-line @@ -139,7 +141,7 @@ function cli_printMessage { ;; --as-request-line ) - cli_printMessage "${MESSAGE}: " --as-notrailingnew-line + cli_printMessage "${MESSAGE}:\040" --as-notrailingnew-line ;; --as-error-line ) @@ -180,7 +182,7 @@ function cli_printMessage { else # Print the question. - cli_printMessage "$MESSAGE [${Y}/${N}]: " --as-notrailingnew-line + cli_printMessage "$MESSAGE [${Y}/${N}]:\040" --as-notrailingnew-line # Redefine default answer based on user's input. read ANSWER @@ -197,7 +199,7 @@ function cli_printMessage { ;; --as-notrailingnew-line ) - echo -n "$MESSAGE" > /dev/stderr + echo -e -n "$MESSAGE" > /dev/stderr ;; --as-stdout-line )