Commit 6f2bc842 authored by John A's avatar John A

Fix -a mode, redefine gray, compatible with -m

A new color mode is added- (-a) mode, for neofetch. It now supports
terminal size without specifying -g, correctly colors output, and is
compatible with a message.
parent 7e477239
......@@ -220,6 +220,7 @@ trap 'quit' SIGINT # respond to CTRL+C
trap 'setGeometry' WINCH # respond to window resize
IFS=$'\n' # delimit by newline
((! artmode)) && tabs 4
# define colors
if ((termColors)); then
......@@ -227,13 +228,20 @@ if ((termColors)); then
DarkBrown='\e[0;33m'
BrownGreen='\e[1;32m'
Green='\e[0;32m'
Gray='\e[1;30m'
elif ((artmode)); then
LightBrown='${c1}'
DarkBrown='${c2}'
BrownGreen='${c3}'
Green='${c4}'
Gray='${c5}'
else
LightBrown='\e[38;5;172m'
DarkBrown='\e[38;5;130m'
BrownGreen='\e[38;5;142m'
Green='\e[38;5;106m'
Gray='\e[38;5;243m'
fi
Grey='\e[1;30m'
R='\e[0m'
# create ascii base in lines
......@@ -241,7 +249,7 @@ case "$baseType" in
1)
width=15
art="\
${Grey}:${Green}___________${DarkBrown}./~~\\.${Green}___________${Grey}:
${Gray}:${Green}___________${DarkBrown}./~~\\.${Green}___________${Gray}:
\\ /
\\________________________/
(_) (_)"
......@@ -250,7 +258,7 @@ ${Grey}:${Green}___________${DarkBrown}./~~\\.${Green}___________${Grey}:
2)
width=7
art="\
${Grey}(${Green}---${DarkBrown}./~~\\.${Green}---${Grey})
${Gray}(${Green}---${DarkBrown}./~~\\.${Green}---${Gray})
( )
(________)"
;;
......@@ -271,8 +279,10 @@ done
charListLen="${#charList[@]}"
setGeometry() {
if ((termSize)); then
geometry="$((COLUMNS - 1)),$LINES" # these vars automatically update
if ((artmode)) && ((termSize)); then
geometry="$(tput cols),$(tput lines)" # geometry must use tput in this mode
elif ((termSize)); then
geometry="$((COLUMNS - 1)),$LINES" # these vars automatically update
fi
cols="$(printf '%s' "$geometry" | cut -d ',' -f1)" # width; X
rows="$(printf '%s' "$geometry" | cut -d ',' -f2)" # height; Y
......@@ -334,12 +344,12 @@ init() {
done
done
# if ((! artmode)); then
if ((! artmode)); then
stty -echo # don't echo stdin
printf '%b' '\e[?25l' # hide cursor
printf '%b' '\e[?7l' # disable line wrapping
printf '%b' '\e[2J' # clear screen, move to 0,0
# fi
fi
}
grow() {
......@@ -530,14 +540,14 @@ branch() {
((verbose)) && printf '%b\n' "$life:\t$x, $y: $char"
grid[$y,$x]="${color}${char}${R}" # put character in grid
grid[$y,$x]="${color}${char}" # put character in grid
# add this line to our list of "edited lines"
found=1
found=0
for item in "${changed[@]}"; do
[ "$item" = "$y" ] && found=0
[ "$item" = "$y" ] && found=1
done
((found)) && changed+=("$y")
((! found)) && changed+=("$y")
# print what we have so far and let the user see it
if ((live)); then
......@@ -565,32 +575,30 @@ display() {
fi
done
# remove trailing whitespace
# if ((flag_m)) || ((artmode)); then
# line=${line%${line##*[^[:space:]]}}
# fi
# remove trailing whitespace and reset color
if ((flag_m)) || ((artmode)); then
line="${line%${line##*[^[:space:]]}}"
fi
# add our message unless line is blank
#((flag_m)) && [ ! "$line" = "" ] && line+=' \t'"${gridMessage[$row]}"
((flag_m)) && [ ! "$line" = "" ] && line+=' \t'"${R}${gridMessage[$row]}"
output+="$line"'\n'
done
output+="$base" # add the ascii-art base we generated earlier
printf '%b' "$output"
#((artmode)) && sed "s/\x1B\[[0-9;]*[a-zA-Z]//g" <(printf '%s' "$output")
#((! artmode)) && printf '%b' "$output"
}
quit() {
# if ((! artmode)); then
if ((! artmode)); then
stty echo # echo stdin
printf '%b' '\e[?25h' # show cursor
printf '%b' '\e[?7h' # enable line wrapping
printf '%b\n' "$R" # reset formatting, put cursor on next line
# fi
else
printf '\n' # reset formatting, put cursor on next line
fi
trap SIGINT # undo traps
trap WINCH
exit 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment