Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
Created February 22, 2019 08:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeepingCreature/6c67479c99bc0f20544d1e455622ae82 to your computer and use it in GitHub Desktop.
Save FeepingCreature/6c67479c99bc0f20544d1e455622ae82 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
if [ -z ${DMD+x} ]
then
echo "Usage: DMD=<dmd executable> $0 <args>"
exit 1
fi
function process {
COLUMNS=$(tput cols)
declare -a MODULES
declare -A INDICATOR
ESCAPE="\033["
CLEAR="${ESCAPE}0m"
RED="${ESCAPE}0;31m"
YELLOW="${ESCAPE}1;33m"
GREEN="${ESCAPE}0;32m"
LGREEN="${ESCAPE}1;32m"
ED="$(tput ed)"
grep -v ^function | sed -e 's/\t/ /g' -e 's/ */ /g' |while read CMD ARG REST
do
INFO=${ARG%%!*}
INFO=${INFO##*.}
case "$CMD" in
parse ) MODULES+=( "$ARG" );;
semantic ) INDICATOR[$ARG]="$RED.";;
semantic2 ) INDICATOR[$ARG]="$YELLOW-";;
semantic3 ) INDICATOR[$ARG]="$GREEN-";;
code ) INDICATOR[$ARG]="$LGREEN~";;
esac
STATUS=""
PLAIN_STATUS=""
for MOD in "${MODULES[@]}"
do
STATUS+=${INDICATOR[$MOD]:- }
PLAIN_STATUS+=" "
done
if [ "$STATUS" != "" ]
then
STATUS="[${STATUS}${CLEAR}] $INFO"
PLAIN_STATUS="[${PLAIN_STATUS}] $INFO"
fi
if [[ -z "$COLUMNS" ]]
then
echo -en "$ED$STATUS\r"
else
LINES=$(echo -en "${PLAIN_STATUS}" |fold -w "$COLUMNS" |wc -l)
echo -en "$ED$STATUS\r"
if [[ "$LINES" != "0" ]]
then
tput cuu $LINES
fi
fi
done
echo -n "$ED"
}
$DMD -v $@ |process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment