Skip to content

Commit

Permalink
refactor header (show disk usage and dev mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Michel Gigault committed Nov 19, 2017
1 parent d70e8e9 commit 258ce3b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
8 changes: 6 additions & 2 deletions 42MapGenerator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion includes/display_center.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions includes/display_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions includes/display_leftandright.sh
Original file line number Diff line number Diff line change
@@ -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
Empty file removed includes/formats.sh
Empty file.
1 change: 1 addition & 0 deletions includes/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 258ce3b

Please sign in to comment.