diff --git a/42MapGenerator.sh b/42MapGenerator.sh index 09eb696..a95dbf8 100644 --- a/42MapGenerator.sh +++ b/42MapGenerator.sh @@ -50,10 +50,13 @@ fi GLOBAL_INSTALLDIR=$(mapgen_install_dir) cd "${GLOBAL_INSTALLDIR}" +GLOBAL_VERSION=2 +GLOBAL_DISK_USAGE= +GLOBAL_LOCALBRANCH=$(git branch | awk '$0 ~ /^\*/ {print $2; exit}') MAPGENERATOR_SH=1 RETURNPATH=$(pwd | sed 's/ /\ /g') -CVERSION=$(git log --oneline 2>/dev/null | awk 'END {printf NR}' | sed 's/ //g') -if [ "$CVERSION" == "" ]; then CVERSION="???"; fi +GLOBAL_CVERSION=$(git log --oneline 2>/dev/null | awk 'END {printf NR}' | sed 's/ //g') +if [ -z "${GLOBAL_CVERSION}" ]; then GLOBAL_CVERSION="???"; fi source includes/maps.sh @@ -66,6 +69,7 @@ source includes/display_section.sh source includes/display_error.sh source includes/display_success.sh source includes/display_right.sh +source includes/display_leftandright.sh source includes/display_spinner.sh source includes/generate_map.sh source includes/download_map.sh diff --git a/includes/display_center.sh b/includes/display_center.sh index e90b11f..bd896ec 100644 --- a/includes/display_center.sh +++ b/includes/display_center.sh @@ -13,7 +13,7 @@ then printf "%"${MARGIN}"s" " " printf "$1" (( MARGIN= ${MARGIN} + (${COLUMNS} - ${LEN} - ${MARGIN} * 2) )) - printf "%"${MARGIN}"s" " " + printf "%"${MARGIN}"s\n" " " else printf "\n" fi diff --git a/includes/display_header.sh b/includes/display_header.sh index f432e97..5532413 100644 --- a/includes/display_header.sh +++ b/includes/display_header.sh @@ -5,24 +5,33 @@ then function display_header { - local MARGIN + local MARGIN COLOR + utils_clear utils_set_env - if [ "$1" != "" ] + COLOR=${1} + if [ -z "${COLOR}" ] + then + COLOR="${C_INVERTGREY}" + fi + if [ "${GLOBAL_LOCALBRANCH}" == "master" ] then - printf "$1" + display_leftandright "${COLOR}" "${COLOR}" "${COLOR}" "DEVELOPMENT MODE" "${GLOBAL_LOCALBRANCH}" else - printf ${C_INVERT}"" + if [ "${GLOBAL_DISK_USAGE}" -gt "100" ] + then + display_leftandright "${C_INVERTGREY}" "${COLOR}" "${COLOR}" "DISK USAGE: ${GLOBAL_DISK_USAGE}M" "PRESS ESCAPE TO EXIT - V${GLOBAL_VERSION}.r${GLOBAL_CVERSION}" + else + display_leftandright "${COLOR}" "${COLOR}" "${COLOR}" "DISK USAGE: ${GLOBAL_DISK_USAGE}M" "PRESS ESCAPE TO EXIT - V${GLOBAL_VERSION}.r${GLOBAL_CVERSION}" + fi fi - display_righttitle "PRESS ESCAPE TO EXIT - V2.r${CVERSION}" display_center " _ _ ____ __ __ ____ " display_center " | || ||___ \| \/ | __ _ _ __ / ___| ___ _ __ " display_center " | || |_ __) | |\/| |/ _\ | '_ \| | _ / _ \ '_ \ " display_center " |__ _/ __/| | | | (_| | |_) | |_| | __/ | | | " display_center " |_||_____|_| |_|\__,_| .__/ \____|\___|_| |_| " - display_center " jgigault @ student.42.fr |_| 06 51 15 98 82 " - display_center " " - printf "${C_CLEAR}\n\n" + display_center " |_| " + printf "${C_CLEAR}\n" } fi diff --git a/includes/display_leftandright.sh b/includes/display_leftandright.sh new file mode 100644 index 0000000..23e4592 --- /dev/null +++ b/includes/display_leftandright.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ "${MAPGENERATOR_SH}" == "1" ] +then + + function display_leftandright + { + local COLORLEFT="${1}" COLORCENTER="${2}" COLORRIGHT="${3}" TEXTLEFT="${4}" TEXTRIGHT="${5}" LEN + + LEN="$(( ${COLUMNS} - ${#TEXTLEFT} - ${#TEXTRIGHT} ))" + if [ "${LEN}" -ge "0" ] + then + printf "${COLORLEFT}%s${COLORCENTER}% ${LEN}s${COLORRIGHT}%s${C_CLEAR}\n" "${TEXTLEFT}" " " "${TEXTRIGHT}" + else + printf "${COLORLEFT}%- ${COLUMNS}s\n${COLORRIGHT}% ${COLUMNS}s${C_CLEAR}\n" "${TEXTLEFT}" "${TEXTRIGHT}" + fi + } + +fi diff --git a/includes/formats.sh b/includes/formats.sh deleted file mode 100644 index e69de29..0000000 diff --git a/includes/utils.sh b/includes/utils.sh index 11123fb..38e931d 100644 --- a/includes/utils.sh +++ b/includes/utils.sh @@ -12,6 +12,7 @@ then then COLUMNS=80 fi + GLOBAL_DISK_USAGE="$(du -ms | awk '$2 == "." {print $1}')" export LC_NUMERIC=C LC_COLLATE=C LANG=C }