Add html output mode when showing rules (-H)
This commit is contained in:
parent
8ccbdc902c
commit
f0dce13580
69
aircon.sh
69
aircon.sh
|
@ -878,6 +878,8 @@ function processtimeconditions() {
|
||||||
local this_human
|
local this_human
|
||||||
local keepgoing=0
|
local keepgoing=0
|
||||||
local ok=0
|
local ok=0
|
||||||
|
local nonmatches=0
|
||||||
|
local rv
|
||||||
if [[ $1 == "-c" ]]; then
|
if [[ $1 == "-c" ]]; then
|
||||||
keepgoing=1
|
keepgoing=1
|
||||||
shift 1
|
shift 1
|
||||||
|
@ -960,6 +962,7 @@ function processtimeconditions() {
|
||||||
ok=1
|
ok=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
[[ $ok -eq 0 ]] && nonmatches=$((nonmatches + 1))
|
||||||
[[ $db -eq 1 && $ok -eq 0 ]] && info " $nowh isn't in range $cond"
|
[[ $db -eq 1 && $ok -eq 0 ]] && info " $nowh isn't in range $cond"
|
||||||
[[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond"
|
[[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond"
|
||||||
fi
|
fi
|
||||||
|
@ -968,10 +971,33 @@ function processtimeconditions() {
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return $((1 - $ok))
|
|
||||||
|
if [[ $ok -eq 0 || $nonmatches -gt 0 ]]; then
|
||||||
|
rv=1
|
||||||
|
else
|
||||||
|
rv=0
|
||||||
|
fi
|
||||||
|
return $rv
|
||||||
}
|
}
|
||||||
|
|
||||||
function active_cols() {
|
function active_cols() {
|
||||||
|
if [[ $RULEFORMAT == "html" ]]; then
|
||||||
|
plainc="<font color=#000000></strong></s>" # black
|
||||||
|
inactc="<font color=#ff0000>" # red
|
||||||
|
linec="<font color=#000000></strong></s>" # black
|
||||||
|
devc="<font color=#00aa00>" # green+bold
|
||||||
|
devbc="<strong><font color=#00aa00>" # green
|
||||||
|
statec="<strong><font color=#bbbb00>" # yellow+bold
|
||||||
|
roomc="<font color=#ffa500>" # orange
|
||||||
|
timec="<font color=#ff97c6>" # pink
|
||||||
|
timebc="<strong><font color=#ff97c6>" # pink+bold
|
||||||
|
minc="<strong><font color=#0000dd>" # blue+bold
|
||||||
|
maxc="<strong><font color=#dd0000>" # red+bold
|
||||||
|
coolc="<strong><font color=#00dddd>" # cyan+bold
|
||||||
|
heatc="<strong><font color=#dd0000>" # red+bold
|
||||||
|
nl="<br></s></strong><font color=#000000>\n"
|
||||||
|
else
|
||||||
|
plainc=${PLAIN}
|
||||||
inactc="$RED"
|
inactc="$RED"
|
||||||
linec=${PLAIN}
|
linec=${PLAIN}
|
||||||
devc="$GREEN"
|
devc="$GREEN"
|
||||||
|
@ -982,9 +1008,28 @@ function active_cols() {
|
||||||
timebc="$BOLD$timec"
|
timebc="$BOLD$timec"
|
||||||
minc="$BOLD$BLUE"
|
minc="$BOLD$BLUE"
|
||||||
maxc="$BOLD$RED"
|
maxc="$BOLD$RED"
|
||||||
|
coolc="$BOLD$CYAN"
|
||||||
|
heatc="$RED"
|
||||||
|
nl="\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function inactive_cols() {
|
function inactive_cols() {
|
||||||
|
if [[ $RULEFORMAT == "html" ]]; then
|
||||||
|
plainc="<font color=#000000></strong></s>" # black
|
||||||
|
inactc="<s><font color=#aaaaaa>" # lightgrey
|
||||||
|
linec=""
|
||||||
|
devc=""
|
||||||
|
devbc=""
|
||||||
|
statec=""
|
||||||
|
roomc=""
|
||||||
|
timec=""
|
||||||
|
timebc=""
|
||||||
|
minc=""
|
||||||
|
maxc=""
|
||||||
|
nl="</s><br>\n"
|
||||||
|
else
|
||||||
|
plainc=${PLAIN}
|
||||||
inactc="$DARKGREY"
|
inactc="$DARKGREY"
|
||||||
linec="${inactc}"
|
linec="${inactc}"
|
||||||
devc="$inactc"
|
devc="$inactc"
|
||||||
|
@ -995,6 +1040,8 @@ function inactive_cols() {
|
||||||
timebc="$inactc"
|
timebc="$inactc"
|
||||||
minc="$inactc"
|
minc="$inactc"
|
||||||
maxc="$inactc"
|
maxc="$inactc"
|
||||||
|
nl="\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_config() {
|
function parse_config() {
|
||||||
|
@ -1054,7 +1101,7 @@ function parse_config() {
|
||||||
[[ $adj != "open" ]] && adj="${adj}d"
|
[[ $adj != "open" ]] && adj="${adj}d"
|
||||||
line_human="${line_human}Force the vent in ${roomc}${tok[1]}${linec} to be ${statec}${adj}${linec}"
|
line_human="${line_human}Force the vent in ${roomc}${tok[1]}${linec} to be ${statec}${adj}${linec}"
|
||||||
else
|
else
|
||||||
errstr="${errstr}${linenum}:Invalid zone state '${tok[2]}'. Valid options are: $VALID_ZONE_STATES\n"
|
errstr="${errstr}${linenum}:Invalid zone state '${tok[2]}'. Valid options are: $VALID_ZONE_STATES$nl"
|
||||||
fileok=0
|
fileok=0
|
||||||
fi
|
fi
|
||||||
elif [[ ${tok[0]} == "owner" ]]; then
|
elif [[ ${tok[0]} == "owner" ]]; then
|
||||||
|
@ -1071,24 +1118,24 @@ function parse_config() {
|
||||||
if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then
|
if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then
|
||||||
local col
|
local col
|
||||||
modelock="${tok[1]}"
|
modelock="${tok[1]}"
|
||||||
[[ $modelock == "cool" ]] && col="$BOLD$CYAN" || col="$RED"
|
[[ $modelock == "cool" ]] && col="$coolc" || col="$heatc"
|
||||||
line_human="${line_human}Only operate the aircon in ${col}${tok[1]}${linec} mode"
|
line_human="${line_human}Only operate the aircon in ${col}${tok[1]}${linec} mode"
|
||||||
else
|
else
|
||||||
errstr="${errstr}${linenum}:Invalid modelock '${tok[1]}'. Valid options are: $VALID_MODES\n"
|
errstr="${errstr}${linenum}:Invalid modelock '${tok[1]}'. Valid options are: $VALID_MODES$nl"
|
||||||
fileok=0
|
fileok=0
|
||||||
fi
|
fi
|
||||||
elif [[ ${tok[0]} == "test" ]]; then
|
elif [[ ${tok[0]} == "test" ]]; then
|
||||||
line_human="${line_human}Got test option '${roomc}${tok[1]}${linec}'"
|
line_human="${line_human}Got test option '${roomc}${tok[1]}${linec}'"
|
||||||
elif [[ -n $line ]]; then
|
elif [[ -n $line ]]; then
|
||||||
errstr="${errstr}${linenum}:Syntax error: ${line}\n"
|
errstr="${errstr}${linenum}:Syntax error: ${line}$nl"
|
||||||
fileok=0
|
fileok=0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -n $line_human ]]; then
|
if [[ -n $line_human ]]; then
|
||||||
if [[ $ok -eq 0 ]]; then
|
if [[ $ok -eq 0 ]]; then
|
||||||
line_human="${PLAIN}${inactc}<INACTIVE> ${linec}${line_human}"
|
line_human="${plainc}${inactc}<INACTIVE> ${linec}${line_human}"
|
||||||
fi
|
fi
|
||||||
config_human="${config_human}- ${linec}${line_human}${PLAIN}\n"
|
config_human="${config_human}- ${linec}${line_human}${plainc}$nl"
|
||||||
fi
|
fi
|
||||||
linenum=$((linenum + 1))
|
linenum=$((linenum + 1))
|
||||||
done < "$CONFIGFILE"
|
done < "$CONFIGFILE"
|
||||||
|
@ -1102,7 +1149,7 @@ function parse_config() {
|
||||||
rv=0
|
rv=0
|
||||||
else
|
else
|
||||||
error "Configuration file is invalid:"
|
error "Configuration file is invalid:"
|
||||||
echo -e "${RED}$errstr${PLAIN}" | sed -e 's/^/ /'
|
echo -e "${RED}$errstr${plainc}" | sed -e 's/^/ /'
|
||||||
rv=1
|
rv=1
|
||||||
fi
|
fi
|
||||||
return $rv
|
return $rv
|
||||||
|
@ -1505,6 +1552,7 @@ limit=$DEFAULTLIMIT
|
||||||
profiler=0
|
profiler=0
|
||||||
csvfile="$DEFAULT_CSVFILE"
|
csvfile="$DEFAULT_CSVFILE"
|
||||||
sanitycheck=0
|
sanitycheck=0
|
||||||
|
RULEFORMAT=ansi
|
||||||
|
|
||||||
|
|
||||||
# check for config file option first
|
# check for config file option first
|
||||||
|
@ -1523,13 +1571,16 @@ fi
|
||||||
|
|
||||||
ALLARGS="$ALLARGS $*"
|
ALLARGS="$ALLARGS $*"
|
||||||
|
|
||||||
optstring="A:cf:hi:I:k:l:Lo:pmsSt:T:wx:y"
|
optstring="A:cf:hHi:I:k:l:Lo:pmsSt:T:wx:y"
|
||||||
while getopts "$optstring" i $ALLARGS; do
|
while getopts "$optstring" i $ALLARGS; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
h)
|
h)
|
||||||
usage;
|
usage;
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
|
H)
|
||||||
|
RULEFORMAT=html
|
||||||
|
;;
|
||||||
f)
|
f)
|
||||||
CONFIGFILE=${OPTARG}
|
CONFIGFILE=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in New Issue