snake-pipe-rust
Not just yet another snake game in the terminal 😉.
https://github.com/topheman/snake-pipe-rust/assets/985982/76161595-1c3a-4252-9cbd-25e144bf185c
This one follows the unix philosophy as:
snakepipe gamestate
accepts user inputs, calculates the state of the game and writes it tostdout
snakepipe render
reads the state of the game fromstdin
and renders it on the terminalsnakepipe throttle
reads a pre-recorded game fromstdin
and writes tostdout
each tick so thatsnakepipe render
can pick it up
That way:
- you could write your own version of the
gamestate
orrender
command in any programming language and make it work with mine - it's a great exercise to handle stream serialization/deserialization in rust
Prerequisites
- Rust 1.75.0
Install
Usage
🎮 Play in terminal
# basic usage
|
# change the defaults
|
# call help on any of the commands
📼 You can even record and replay using basic piping
# record a game into a file using the `tee` command utility
||
# replay the game you recorded
||
Manual of commands
Commands: gamestate render throttle help Print this message or the help of the given subcommand(s)
Options: -h, --help Print help -V, --version Print version
Options: --frame-duration <FRAME_DURATION> in ms [default: 120] --width <WIDTH_> default 25 --height <HEIGHT_> default 25 --snakepipe-length <snakepipe_LENGTH> [default: 2] --fit-terminal
Options: --frame-duration <FRAME_DURATION> in ms [default: 120]
Using as a library
This crate is a cli, but it also exports a lib from where you can import a few utilities, such as snakepipe::stream::parse_gamestate
- direct link to docs.rs:
use ;
Next
- Make an implementation of the
render
command that starts a server so that the render happens in a browser - Make an implementation of the actual
render
for the terminal in an other language than rust