Record demo for readme

Uses a crate in `bin/demo` to output a demo script of commands, with a
per-character and per-line delay, and a dummy prompt. Capture output
and render to a gif.

type: documentation
This commit is contained in:
Casey Rodarmor 2020-03-28 03:56:08 -07:00
parent a5e1273187
commit 57e482f4b3
No known key found for this signature in database
GPG Key ID: 556186B153EC6FE0
7 changed files with 107 additions and 0 deletions

4
Cargo.lock generated
View File

@ -187,6 +187,10 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "demo"
version = "0.0.0"
[[package]] [[package]]
name = "difference" name = "difference"
version = "2.0.0" version = "2.0.0"

View File

@ -62,6 +62,8 @@ temptree = "0.0.0"
[workspace] [workspace]
members = [ members = [
# run commands for demo animation
"bin/demo",
# generate table of contents and table of supported BEPs in README.md # generate table of contents and table of supported BEPs in README.md
"bin/update-readme", "bin/update-readme",
] ]

View File

@ -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). 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 ## Manual
- [General](#general) - [General](#general)

5
bin/demo/Cargo.toml Normal file
View File

@ -0,0 +1,5 @@
[package]
name = "demo"
version = "0.0.0"
authors = ["Casey Rodarmor <casey@rodarmor.com>"]
edition = "2018"

78
bin/demo/src/main.rs Normal file
View File

@ -0,0 +1,78 @@
use std::{
error::Error,
io::{stdout, Write},
path::{Path, PathBuf},
process::Command,
thread::sleep,
time::Duration,
};
type Result<T, E = Box<dyn Error>> = std::result::Result<T, E>;
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<Vec<&'static str>> {
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<PathBuf> {
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(())
}

View File

@ -58,6 +58,9 @@ dev-deps:
brew install grip brew install grip
cargo install mdbook cargo install mdbook
cargo install cargo-watch cargo install cargo-watch
npm install --global asciicast2gif
brew install imagemagick
brew install gifsicle
# update readme table of contents # update readme table of contents
update-toc: update-toc:
@ -101,6 +104,19 @@ publish: publish-check
git push github {{version}} git push github {{version}}
cargo publish 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 # open site index
www: www:
open www/index.html open www/index.html

BIN
www/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB