From e3fef752a7f3f9f284aa66663b05156a4a2663d3 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sat, 29 Jan 2022 12:27:30 -0300 Subject: [PATCH] Add calcHeight and calcWidth --- install.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index cd20b91..e4cf86b 100755 --- a/install.sh +++ b/install.sh @@ -337,8 +337,8 @@ calcAndRun() { argc="$#"; i=1 for item in "$@"; do [ $i -eq $((argc-2)) ] && str="$item" - [ "$item" = "WIDTH" ] && { function="calcWidthDialog"; dimName="width"; } - [ "$item" = "HEIGHT" ] && { function="calcHeightDialog"; dimName="height"; } + [ "$item" = "WIDTH" ] && { function="calcWidth"; dimName="width"; } + [ "$item" = "HEIGHT" ] && { function="calcHeight"; dimName="height"; } ((i++)) done dim=$($function "$str") @@ -352,6 +352,30 @@ calcAndRun() { return $exitStatus } +calcWidth() { + str=$1; count=1; found=false; option=1 + for (( i = 0; i < ${#str}; i++ )); do + if [ "${str:$i:1}" = "\\" ] && [ "${str:$((i+1)):1}" = "n" ]; then + [ $count -ge $option ] && option=$count + found=true + count=-1 + fi + ((count++)) + done + [ $option -ge $count ] && count=option + echo $((count+3)) +} + +calcHeight() { + newlines=$(printf "$1" | grep -c $'\n') + chars=$(echo "$1" | wc -c) + height=$(echo "$chars" "$newlines" | awk '{ + x = (($1 - $2 + ($2 * 60)) / 60) + printf "%d", (x == int(x)) ? x : int(x) + 1 + }') + echo $((4+height)) +} + askForPassword() { password=$(calcAndRun dialog --insecure --passwordbox "\"\nNow, enter the password for santioaguit-pc.\"" 10 WIDTH) exitIfCancel "You must enter a password."