Skip to content

Commit

Permalink
Adds script to run a demo and create an animated SVG of this demo wit…
Browse files Browse the repository at this point in the history
…h svg-term
  • Loading branch information
bvobart committed Aug 12, 2021
1 parent 24c0f41 commit d1f4a5f
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/create-demo-svg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Creates an SVG of a run of mllint.
# Assumes you're using it on one of the mllint-example-projects with poetry and all dependencies already installed.

# Depends on:
# - svg-term: https://github.com/marionebl/svg-term-cli
# - asciinema: https://asciinema.org/
# - bash (don't run it on Windows)
#
# TODO: there are some tiny artefacts in the completed SVG relating to issues with Powerline fonts not being available.
# I tried this: https://gist.github.com/danielfullmer/5e29d1e9534dded5c183
# using this: https://graphicdesign.stackexchange.com/questions/10733/how-do-i-use-a-custom-font-in-an-svg-image-on-my-site
# but I wasn't able to get it fixed. Have any idea to fix it? Feel free to tackle it! :)

# exit on first error
set -e

# File location of this script.
script_dir="$(dirname $0)"

# The folder to run mllint on and filename for the asciicast and finished .svg
folder="$1"
filename="$2"
[[ -z "$folder" ]] && folder="."
[[ -z "$filename" ]] && filename="mllint-run-$(date +%F.%T).cast"

echo "> Recording and creating SVG in '$folder'..."
svg-term --command "bash $script_dir/demo-script.sh $folder" --term konsole --profile "$script_dir/demo-colors.colorscheme" --out "$filename.svg"

echo "> Making final adjustments..."
# svg-term apparently has some trouble selecting the right colour from the color scheme for text with a background colour (i.e. the terminal prompt), so we manually fix that here.
sed -i 's/fill:#71bef2/fill:#df00fe/g' "$filename.svg"
sed -i 's/fill:#dbab79/fill:#e6b822/g' "$filename.svg"

echo "> Done: $filename.svg"
96 changes: 96 additions & 0 deletions docs/demo-colors.colorscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[Background]
Color=22,25,37

[BackgroundFaint]
Color=26,28,35

[BackgroundIntense]
Color=27,31,45

[Color0]
Color=55,43,66

[Color0Faint]
Color=62,53,68

[Color0Intense]
Color=86,67,103

[Color1]
Color=237,34,112

[Color1Faint]
Color=184,27,90

[Color1Intense]
Color=255,37,124

[Color2]
Color=45,250,206

[Color2Faint]
Color=91,216,189

[Color2Intense]
Color=96,255,221

[Color3]
Color=230,184,34

[Color3Faint]
Color=200,161,43

[Color3Intense]
Color=245,188,0

[Color4]
Color=223,0,254

[Color4Faint]
Color=199,12,216

[Color4Intense]
Color=223,0,254

[Color5]
Color=190,0,254

[Color5Faint]
Color=178,69,214

[Color5Intense]
Color=190,0,254

[Color6]
Color=75,231,247

[Color6Faint]
Color=59,186,200

[Color6Intense]
Color=77,237,255

[Color7]
Color=152,199,203

[Color7Faint]
Color=115,151,154

[Color7Intense]
Color=188,244,251

[Foreground]
Color=202,227,230

[ForegroundFaint]
Color=169,190,192

[ForegroundIntense]
Color=221,248,251

[General]
Blur=true
ColorRandomization=true
Description=BvO
Opacity=0.85
Wallpaper=
71 changes: 71 additions & 0 deletions docs/demo-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
# Designed to be used with svg-term in create-demo-svg.sh
# Example Usage: svg-term --command "bash demo-script.sh $folder" --out "filename.svg"
# Inspiration taken from how 'fd' creates its screencast demo: https://github.com/sharkdp/fd/blob/master/doc/screencast.sh

set -e
set -u

# Folder where mllint should be executed
FOLDER="$1"

FG_BLACK_BG_BLUE="\033[30;44m"
FG_BLACK_BG_YELLOW="\033[30;43m"
COLOR_RESET="\033[0m"
# Terminal prompt to show during the demo
PROMPT="$FG_BLACK_BG_BLUE ~/tudelft/thesis/mllint-example-projects ▶$FG_BLACK_BG_YELLOW main ▶$COLOR_RESET"

function prompt {
printf "%b " "$PROMPT"
}

# This function splits its first argument into individual characters and prints each of them with a slight (80 ms) delay, to simulate someone typing.
function type {
arg=$1
for ((i=0;i<${#arg};i++)); do
echo -n "${arg:i:1}"
sleep 0.08
done
}

# This function takes whatever arguments it is given, types them out using the `type` function above, sleeps for a little bit before 'pressing enter', executing the entire command and printing a new terminal prompt.
function enter {
input="$@"
wait_time=0.6

type "$input"
sleep "$wait_time"
echo
eval "$input"
echo
prompt
}

# This function performs the actual demo of mllint
function demo {
cd "$FOLDER"

# silently remove report from previous run
[[ -f report.md ]] && rm report.md

prompt
sleep 0.5

enter tree
sleep 1.5

enter poetry run mllint -o report.md
sleep 1.5

# TODO: release mllint render
enter poetry run mllint render report.md
sleep 3

# TODO: deal with the fact that it only shows the last part of the report, instead of the entire report
# TODO: perhaps we can just mllint render report.md | head -n X to show only the first X lines, then another one of those to show the rest of the lines.

# this final echo is there so that the SVG will respect the previous `sleep`
echo
}

demo

0 comments on commit d1f4a5f

Please sign in to comment.