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:
parent
a5e1273187
commit
57e482f4b3
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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"
|
||||||
|
|
|
@ -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",
|
||||||
]
|
]
|
||||||
|
|
|
@ -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
5
bin/demo/Cargo.toml
Normal 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
78
bin/demo/src/main.rs
Normal 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(())
|
||||||
|
}
|
16
justfile
16
justfile
|
@ -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
BIN
www/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 KiB |
Loading…
Reference in New Issue
Block a user