diff --git a/Cargo.lock b/Cargo.lock index 9262b8d..6f441eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,6 +187,10 @@ dependencies = [ "syn", ] +[[package]] +name = "demo" +version = "0.0.0" + [[package]] name = "difference" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index 7e40196..80c97c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,8 @@ temptree = "0.0.0" [workspace] members = [ + # run commands for demo animation + "bin/demo", # generate table of contents and table of supported BEPs in README.md "bin/update-readme", ] diff --git a/README.md b/README.md index 97878df..15e2095 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ At the moment, creation, viewing, and verification of `.torrent` files is suppor For more about the project and its goals, check out [this post](https://rodarmor.com/blog/intermodal). +![demonstration animation](https://raw.githubusercontent.com/casey/intermodal/master/www/demo.gif) + ## Manual - [General](#general) diff --git a/bin/demo/Cargo.toml b/bin/demo/Cargo.toml new file mode 100644 index 0000000..89d0920 --- /dev/null +++ b/bin/demo/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "demo" +version = "0.0.0" +authors = ["Casey Rodarmor "] +edition = "2018" diff --git a/bin/demo/src/main.rs b/bin/demo/src/main.rs new file mode 100644 index 0000000..d48c790 --- /dev/null +++ b/bin/demo/src/main.rs @@ -0,0 +1,78 @@ +use std::{ + error::Error, + io::{stdout, Write}, + path::{Path, PathBuf}, + process::Command, + thread::sleep, + time::Duration, +}; + +type Result> = std::result::Result; + +const SCRIPT: &str = " + ls -l 9front + imdl torrent create --input 9front + imdl torrent show --input 9front.torrent + imdl torrent verify --input 9front.torrent + imdl torrent link --input 9front.torrent +"; + +const PROMPT: &str = "\x1b[0;34m$\x1b[0m "; + +const CPM: u64 = 600; + +fn commands() -> Vec> { + SCRIPT + .lines() + .map(|line| line.trim()) + .filter(|line| !line.is_empty()) + .map(|line| line.split(' ').collect()) + .collect() +} + +fn print(text: &str) -> Result<()> { + stdout().write_all(text.as_bytes())?; + stdout().flush()?; + Ok(()) +} + +fn replace(bin: &str) -> Result { + match bin { + "ls" => Ok("exa".into()), + "imdl" => Ok(Path::new("./target/release/imdl").canonicalize()?), + _ => Ok(bin.into()), + } +} + +fn run(command: &[&str]) -> Result<()> { + Command::new(replace(command[0])?) + .args(&command[1..]) + .current_dir("tmp") + .status()?; + Ok(()) +} + +fn main() -> Result<()> { + let char_delay = Duration::from_millis(1000 * 60 / CPM); + let line_delay = char_delay * 7; + + for (i, command) in commands().iter().enumerate() { + print(PROMPT)?; + + if i > 0 { + sleep(line_delay); + } + + let mut line = command.join(" "); + line.push('\n'); + + for c in line.chars() { + sleep(char_delay); + print(&c.to_string())?; + } + + run(&command)?; + } + + Ok(()) +} diff --git a/justfile b/justfile index 84db022..815b6c9 100644 --- a/justfile +++ b/justfile @@ -58,6 +58,9 @@ dev-deps: brew install grip cargo install mdbook cargo install cargo-watch + npm install --global asciicast2gif + brew install imagemagick + brew install gifsicle # update readme table of contents update-toc: @@ -101,6 +104,19 @@ publish: publish-check git push github {{version}} cargo publish +# record demo animation +record: + #!/usr/bin/env bash + set -euxo pipefail + cargo build --release --all + rm -f tmp/9front.torrent + asciinema rec \ + --command ./target/release/demo \ + --overwrite \ + tmp/demo.json + asciinema upload tmp/demo.json + asciicast2gif tmp/demo.json www/demo.gif + # open site index www: open www/index.html diff --git a/www/demo.gif b/www/demo.gif new file mode 100644 index 0000000..ca51942 Binary files /dev/null and b/www/demo.gif differ