A Rust port of cbonsai โ a beautifully random bonsai tree generator for your terminal.
This is a faithful reimplementation of the C/ncurses original, built on
crossterm instead of ncurses (so it
runs on macOS, Linux, and Windows with no system curses dependency). The binary
is named rustbonsai and accepts the same flags as upstream cbonsai.
The RNG is a reimplementation of glibc's random()/rand() (the TYPE_3
additive-feedback generator). This means a given --seed produces the same
tree as the original cbonsai built against glibc:
rustbonsai -p -s 42 # identical layout to upstream `cbonsai -p -s 42` on glibcThe tree starts at the centre of the terminal and grows into the available
space, so an exact match also requires the same terminal dimensions as the
upstream run. The RNG match is verified by a unit test against glibc's known
srand(1) output sequence (cargo test).
cargo build --release
./target/release/rustbonsaicargo install --path . # builds release and installs `rustbonsai` to ~/.cargo/binAs long as ~/.cargo/bin is on your PATH, you can then run rustbonsai from
anywhere. To remove it later: cargo uninstall rustbonsai.
Usage: rustbonsai [OPTION]...
-l, --live live mode: show each step of growth
-t, --time=TIME in live mode, seconds between growth steps [default: 0.03]
-i, --infinite infinite mode: keep growing trees
-w, --wait=TIME in infinite mode, seconds between trees [default: 4.00]
-S, --screensaver screensaver mode (-li, quit on any keypress)
-m, --message=STR attach a message next to the tree
-b, --base=INT ascii-art base to use (0 = none) [default: 1]
-c, --leaf=LIST comma-delimited strings chosen at random for leaves [default: &]
-k, --color=LIST 4 comma-delimited color indices (0-255):
dark leaves, dark wood, light leaves, light wood [default: 2,3,10,11]
-M, --multiplier=INT branch multiplier; higher -> more branching (0-20) [default: 5]
-L, --life=INT life; higher -> more growth (0-200) [default: 32]
-p, --print print the finished tree to the terminal and exit
-s, --seed=INT seed the random number generator
-W, --save=FILE save progress (seed + branch count) to FILE
-C, --load=FILE load progress from FILE
-v, --verbose increase output verbosity
-h, --help show help
Press q to quit. In interactive (non-print) mode, press any key once the tree
has finished growing.
rustbonsai # grow a tree, wait for a keypress
rustbonsai -l # watch it grow live
rustbonsai -li # live + infinite (a gentle screensaver)
rustbonsai -p -s 42 # print a reproducible tree and exit
rustbonsai -m "stay grounded" # add a message
rustbonsai -c "๐,๐ธ" -M 8 # custom leaves, denser branchingsrc/rng.rsโ glibc-compatiblerand().src/config.rsโ CLI parsing and defaults.src/render.rsโ cell-grid screen buffer (diff-based draw + ANSI export).src/main.rsโ the recursive branch-growth algorithm and main loop.
rustbonsai is licensed under the GNU General Public License v3.0 or later
(see LICENSE).
It is a derivative work of cbonsai by
John Allbritten, reusing its tree-growth algorithm, ASCII-art bases, help
text, and command-line interface. cbonsai is also GPL-3.0-or-later; as a
derivative, this port carries the same license. See NOTICE for full
attribution.