Commit 63c6561c authored by John A's avatar John A

improved leafchar option to allow a list of characters. improved help message....

improved leafchar option to allow a list of characters. improved help message. simplified + improved clean function. Updated readme to remove completed goals, update help info and description
parent e89b8c67
......@@ -2,7 +2,7 @@
![](previews/bonsai.png)
`bonsai.sh` is a bonsai tree generator for the terminal, written in `bash`. It supports both live and static generation.
`bonsai.sh` is a bonsai tree generator for the terminal, written in `bash`. It intelligently creates, colors, and positions the created bonsai tree, while also supporting a multitude of options.
# Installation
......@@ -17,25 +17,28 @@ ln -s ~/bin/bonsai.sh/bonsai.sh ~/.local/bin/bonsai
# Usage
```
Usage: bonsai [-l [-t time]] [-m text] [-b int] [-i [-w time]] [-T]
[-g x,y] [-c char] [-M int] [-L int] [-s int] [-h]
bonsai.sh is a static and live bonsai tree generator, written in bash.
Usage: bonsai [OPTIONS]
bonsai.sh is a beautifully random bonsai tree generator.
optional args:
-l, --live enable live mode: watch the tree grow
-t, --time time in live mode, time in secs between each step of growth [default: 0.01]
-m, --message text attach a message to the tree
-b, --basetype int which ascii-art plant base to use (0 for none) [default: 1]
-i, --infinite enable infinite mode: keep generating trees until quit
-w, --wait sec in infinite mode, time in secs between tree generation [default: 2]
-l, --live live mode
-t, --time TIME in live mode, time in secs between
steps of growth [default: 0.01]
-i, --infinite infinite mode
-w, --wait TIME in infinite mode, time in secs between
tree generation [default: 4]
-m, --message STR attach message next to the tree
-T, --termcolors use terminal colors
-g, --geometry x,y set custom geometry [default: fit to terminal]
-c, --leaf char character used for leaves [default: &]
-M, --multiplier 0-20 branch multiplier; higher equals more branching [default: 5]
-L, --life int 1-200 life of tree; higher equals more overall growth [default: 28]
-s, --seed int seed for tree; value (0-32767) is used to set the random number generator
-g, --geometry X,Y set custom geometry
-b, --base INT ascii-art plant base to use, 0 is none
-c, --leaf STR1,STR2,STR3... list of strings randomly chosen for leaves
-M, --multiplier INT branch multiplier; higher -> more
branching (0-20) [default: 5]
-L, --life INT life; higher -> more growth (0-200) [default: 28]
-s, --seed INT seed random number generator (0-32767)
-h, --help show help
```
```
# Examples
......@@ -51,8 +54,6 @@ optional args:
* Add a mode that grows based on percentage throughout minute/hour/day (e.g. in minute mode, when the clock hits 45s, the tree should be 75% done growing and restart when the next minute comes) (credit: u/Esko997)
* Add a mode that outputs friendly ascii-art for neofetch/similar program
* Optimization in live mode
* Add compatibility with Mac
# Inspiration
......
......@@ -27,7 +27,7 @@ infinite=0
termSize=1
termColors=0
leafchar='&'
leafChars='&'
basetype=1
message=""
......@@ -82,7 +82,7 @@ while true; do
;;
-c|--leaf)
leafchar="$2"
leafChars="$2"
shift 2
;;
......@@ -97,7 +97,7 @@ while true; do
shift 2
;;
-b|--basetype)
-b|--base)
basetype="$2"
shift 2
;;
......@@ -152,24 +152,27 @@ if [ "$(printf '%s\n' "$timeWait < 0" | bc -l)" -eq 1 ]; then
exit 1
fi
HELP="Usage: bonsai [-l [-t time]] [-m text] [-b int] [-i [-w time]] [-T]
[-g x,y] [-c char] [-M int] [-L int] [-s int] [-h]
HELP="\
Usage: bonsai [OPTIONS]
bonsai.sh is a static and live bonsai tree generator, written in bash.
bonsai.sh is a beautifully random bonsai tree generator.
optional args:
-l, --live enable live mode: watch the tree grow
-t, --time time in live mode, time in secs between each step of growth [default: 0.01]
-m, --message text attach a message to the tree
-b, --basetype int which ascii-art plant base to use (0 for none) [default: 1]
-i, --infinite enable infinite mode: keep generating trees until quit
-w, --wait sec in infinite mode, time in secs between tree generation [default: 4]
-l, --live live mode
-t, --time TIME in live mode, time in secs between
steps of growth [default: 0.01]
-i, --infinite infinite mode
-w, --wait TIME in infinite mode, time in secs between
tree generation [default: 4]
-m, --message STR attach message next to the tree
-T, --termcolors use terminal colors
-g, --geometry x,y set custom geometry [default: fit to terminal]
-c, --leaf char character used for leaves [default: &]
-M, --multiplier 0-20 branch multiplier; higher equals more branching [default: 5]
-L, --life int 1-200 life of tree; higher equals more overall growth [default: 28]
-s, --seed int seed for tree; value (0-32767) is used to set the random number generator
-g, --geometry X,Y set custom geometry
-b, --base INT ascii-art plant base to use, 0 is none
-c, --leaf STR1,STR2,STR3... list of strings randomly chosen for leaves
-M, --multiplier INT branch multiplier; higher -> more
branching (0-20) [default: 5]
-L, --life INT life; higher -> more growth (0-200) [default: 28]
-s, --seed INT seed random number generator (0-32767)
-h, --help show help"
if ((flag_h)); then
......@@ -177,7 +180,7 @@ if ((flag_h)); then
exit 0
fi
trap 'clean quit' SIGINT # respond to CTRL+C
trap 'quit' SIGINT # respond to CTRL+C
trap 'setGeometry' WINCH # respond to window resize
IFS=$'\n' # delimit by newline
......@@ -200,9 +203,6 @@ R='\e[0m'
# create ascii base in lines
case "$basetype" in
0)
art="" ;;
1)
width=15
art="\
......@@ -219,6 +219,8 @@ ${Grey}(${Green}---${DarkBrown}./~~\\.${Green}---${Grey})
( )
(________)"
;;
*) art="" ;;
esac
# get base height
......@@ -227,6 +229,12 @@ for line in $art; do
baseHeight=$(( baseHeight + 1 ))
done
# create leafchars list
for char in $(echo "$leafChars" | tr , '\n'); do
charList+=("$char")
done
charListLen="${#charList[@]}"
setGeometry() {
if ((termSize)); then
termCols=$(tput cols)
......@@ -492,7 +500,10 @@ branch() {
esac
# set leaf if needed
[ $life -lt 4 ] && char="${leafchar}"
# randomly choose leafchar
if [ $life -lt 4 ]; then
char="${charList[ $((RANDOM % charListLen)) ]}"
fi
# uncomment for help debugging
#echo -e "$life:\t$x, $y: $char"
......@@ -552,24 +563,14 @@ display() {
printf '%b' "$output"
}
clean() {
local action="$1"
# Show cursor and echo stdin
printf '%b' '\e[?25h'
printf '%b' '\e[?7h'
stty echo
printf '%b\n' "$R" # reset formatting and put cursor on next line
case "$action" in
quit)
# undo traps
trap SIGINT
trap WINCH
exit 0
;;
esac
quit() {
printf '%b' '\e[?25h' # show cursor
printf '%b' '\e[?7h' # enable line wrapping
printf '%b\n' "$R" # reset formatting, put cursor on next line
stty echo # echo stdin
trap SIGINT # undo traps
trap WINCH
exit 0
}
bonsai() {
......@@ -577,7 +578,6 @@ bonsai() {
init
grow
display
clean
}
main() {
......@@ -589,3 +589,4 @@ main() {
}
main
quit
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