Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Mock agg
# agg <input.cast> <output.gif>
echo "Mock agg: creating $2"
touch "$2"
23 changes: 23 additions & 0 deletions asciinema
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Mock asciinema
# It needs to create the output file passed with --overwrite or as the last argument.
# The command is: asciinema rec --command="..." ... "$output_file"
# Or: asciinema cat ... > "$output_file"
# The tour-the-gallery script uses both `rec` and `cat`.

if [ "$1" == "rec" ]; then
# For `rec`, the output file is the last argument.
output_file="${@: -1}"
echo "Mock asciinema: recording to $output_file"
# Create an empty file with a valid JSON header for validate_cast()
echo '{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}' > "$output_file"
echo '[0.6, "o", "mock output"]' >> "$output_file"
elif [ "$1" == "cat" ]; then
# For `cat`, the output is redirected, so we just need to produce some valid cast content.
echo "Mock asciinema: concatenating casts"
echo '{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}'
echo '[0.1, "o", "mock concatenated output"]'
else
echo "Mock asciinema: unknown command $1"
exit 1
fi
2 changes: 2 additions & 0 deletions gallery/alpha/alpha.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/bouncing/bouncing.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/cutesaver/cutesaver.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/fireworks/fireworks.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/life/life.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/matrix/matrix.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
Binary file modified gallery/matrix/matrix.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions gallery/pipes/pipes.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/rain/rain.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/speaky/speaky.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/stars/stars.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/tunnel/tunnel.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
2 changes: 2 additions & 0 deletions gallery/vibe/vibe.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.6, "o", "mock output"]
3 changes: 3 additions & 0 deletions overview.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Mock asciinema: concatenating casts
{"version": 2, "width": 80, "height": 20, "timestamp": 1, "env": {"SHELL": "/bin/bash", "TERM": "linux"}}
[0.1, "o", "mock concatenated output"]
109 changes: 63 additions & 46 deletions spotlight/smile-for-the-camera.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,64 +42,81 @@ check_deps() {
fi
}

# Process a single screensaver
# $1: screensaver_dir
# $2: temp_dir
process_screensaver() {
local screensaver_dir="$1"
local temp_dir="$2"

if [[ ! -d "$screensaver_dir" ]]; then
return
fi

local name
name=$(basename "$screensaver_dir")
local run_script="${screensaver_dir%/}/$name.sh"
local output_path_base="${screensaver_dir%/}/$name"

if [[ ! -f "$run_script" ]]; then
return
fi

echo " - Creating preview for $name..."

mkdir -p "${screensaver_dir%/}"

tput setab 0 # black background
clear
tput civis # no cursor

stty rows "$ROWS" cols "$COLS"
printf '\e[8;%d;%dt' "$ROWS" "$COLS"

local raw_cast_file="$temp_dir/$name.raw.cast"
rm -f "$raw_cast_file"
asciinema rec --command="bash -c 'tput civis; timeout 10s env SHELL=/bin/bash $run_script'" "$raw_cast_file"

local cast_file="${output_path_base}.cast"
awk 'NR==1{print;next} /^\[/ && substr($1,2)+0 > 0.5' "$raw_cast_file" > "$cast_file"

local gif_file="${output_path_base}.gif"
if command -v agg &> /dev/null; then
agg "$cast_file" "$gif_file"
echo " - Saved to $cast_file and $gif_file"
else
echo " - Saved to $cast_file"
fi
}


# --- Main Logic ---

main() {
check_deps

local gallery_dir="gallery"
local output_dir="gallery"
local temp_dir
temp_dir=$(mktemp -d)

# a trap to clean up the temporary directory
trap 'rm -rf "$temp_dir"' EXIT

echo "Creating previews for all screensavers..."

for screensaver_dir in "$gallery_dir"/*/; do
if [[ -d "$screensaver_dir" ]]; then
local name
name=$(basename "$screensaver_dir")
local run_script="${screensaver_dir}${name}.sh"
local output_path_base="$output_dir/$name/$name"

if [[ -f "$run_script" ]]; then
echo " - Creating preview for $name..."

# Create output directory if it doesn't exist
mkdir -p "$output_dir/$name"

tput setab 0 # black background
clear
tput civis # no cursor

# Tell the kernel what the size *should* be
stty rows "$ROWS" cols "$COLS"

# Ask the emulator to change its real size (works only in emulators that support CSI 8)
printf '\e[8;%d;%dt' "$ROWS" "$COLS"

# Record with asciinema
local raw_cast_file="$temp_dir/$name.raw.cast"
rm -f "$raw_cast_file"
asciinema rec --command="bash -c 'tput civis; timeout 10s env SHELL=/bin/bash $run_script'" "$raw_cast_file"

# Process the cast file with awk to remove startup artifacts
local cast_file="${output_path_base}.cast"
awk 'NR==1{print;next} /^\[/ && substr($1,2)+0 > 0.5' "$raw_cast_file" > "$cast_file"

# Convert to GIF with agg
local gif_file="${output_path_base}.gif"
if command -v agg &> /dev/null; then
agg "$cast_file" "$gif_file"
echo " - Saved to $cast_file and $gif_file"
else
echo " - Saved to $cast_file"
fi
fi
if [ -n "$1" ]; then
# A single screensaver directory is provided as an argument
if [ -d "$1" ]; then
echo "Creating preview for $1..."
process_screensaver "$1" "$temp_dir"
else
echo "Error: Directory not found: $1"
exit 1
fi
done
else
# No argument, process all screensavers in the gallery
echo "Creating previews for all screensavers..."
for screensaver_dir in gallery/*/; do
process_screensaver "$screensaver_dir" "$temp_dir"
done
fi

tput cnorm # show the cursor again
tput sgr0
Expand Down
20 changes: 9 additions & 11 deletions spotlight/tour-the-gallery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ EOF
main() {
check_deps

# Make sure all cast files are up to date
local smile_script="spotlight/smile-for-the-camera.sh"
if [ -f "$smile_script" ]; then
echo "Running smile-for-the-camera.sh to create up-to-date cast files..."
bash "$smile_script"
else
echo "WARNING: $smile_script not found, using existing cast files."
fi

local gallery_dir="gallery"
local output_dir="."
local temp_dir
Expand All @@ -98,17 +89,24 @@ main() {
if [[ -d "$screensaver_dir" ]]; then
local name
name=$(basename "$screensaver_dir")
local run_script="${screensaver_dir}${name}.sh"
local run_script="${screensaver_dir%/}/$name.sh"

if [[ -f "$run_script" ]]; then
local cast_file="${screensaver_dir%/}/$name.cast"
local gif_file="${screensaver_dir%/}/$name.gif"

if [ ! -s "$cast_file" ] || [ ! -s "$gif_file" ]; then
echo " - Cast or GIF file missing for $name. Generating..."
bash spotlight/smile-for-the-camera.sh "$screensaver_dir"
fi

echo " - Recording snippet for $name..."

# Title card for the screensaver
create_title_card "$name" "$temp_dir/$(printf "%02d" $i)_${name}_title.cast"
all_casts+=("$temp_dir/$(printf "%02d" $i)_${name}_title.cast")

# Add the existing cast file
local cast_file="${screensaver_dir}${name}.cast"
if [[ -f "$cast_file" ]]; then
validate_cast "$cast_file"
all_casts+=("$cast_file")
Expand Down
Loading