Skip to content

Commit

Permalink
add asciinema_automation example and change default delaybeforesend v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
PierreMarchand20 committed Jan 3, 2024
1 parent c150fa8 commit 9875c8b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions asciinema_automation/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class Script:
delay: float
standard_deviation: float
instructions: list[Instruction]
delaybeforesend: float = 50 / 1000.0
delaybeforesend: float | None = None

def execute(self) -> None:
spawn_command = (
"asciinema rec " + str(self.outputfile) + " " + self.asciinema_arguments
)
logger.info(spawn_command)
self.process = pexpect.spawn(spawn_command, logfile=None)
self.process.delaybeforesend = self.delaybeforesend
self.process.delaybeforesend = self.delaybeforesend # type: ignore

self.process.expect("\n")
logger.debug(self.process.before)
Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions examples/asciinema_automation_hello_world.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#$ delay 10

cat ./hello_world.sh
#$ expect \$

asciinema-automation --asciinema-arguments "--overwrite -c 'env -i PS1=\"$ \" bash --noprofile --norc'" ./hello_world.sh ./test.cast
#$ expect \$
# change \$ to your prompt, or remove to just wait

asciinema play ./test.cast
#$ expect exit
#$ expect \$
8 changes: 4 additions & 4 deletions examples/hello_world.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# delay instructions change the time (or mean of gaussian if standard deviation is given) between key strokes
#$ delay 50
# mean of gaussian delay between key strokes, default to 50ms
#$ delay 150

echo "Hello world"
#$ expect \$

# wait instructions change the time between instructions
# wait instructions change the time between instructions, default to 80ms
#$ wait 1000

echo "I have waited 1000ms"
echo "I now wait 1000ms"
#$ expect \$

#$ delay 10
Expand Down
27 changes: 27 additions & 0 deletions tests/reference_output/asciinema_automation_hello_world.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$ cat ./hello_world.sh
# mean of gaussian delay between key strokes, default to 50ms
#$ delay 150

echo "Hello world"
#$ expect \$

# wait instructions change the time between instructions, default to 80ms
#$ wait 1000

echo "I now wait 1000ms"
#$ expect \$

#$ delay 10
echo "I am writing with a 10ms delay"
#$ expect \$
$ asciinema-automation --asciinema-arguments "--overwrite -c 'env -i PS1=\"$ \"
bash --noprofile --norc'" ./hello_world.sh ./test.cast
$ asciinema play ./test.cast
$ echo "Hello world"
Hello world
$ echo "I now wait 1000ms"
I now wait 1000ms
$ echo "I am writing with a 10ms delay"
I am writing with a 10ms delay
$ exit
$ exit
4 changes: 2 additions & 2 deletions tests/reference_output/hello_world.cast
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ echo "Hello world"
Hello world
$ echo "I have waited 1000ms"
I have waited 1000ms
$ echo "I now wait 1000ms"
I now wait 1000ms
$ echo "I am writing with a 10ms delay"
I am writing with a 10ms delay
$ exit
5 changes: 5 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pathlib
import re
import shutil

import pytest
from pytest import FixtureRequest, MonkeyPatch
Expand Down Expand Up @@ -43,6 +44,10 @@ def test_regression(
custom_rc_file = (
request.config.invocation_params.dir / "tests" / "custom_rc_file_xterm_term"
)

if inputfile.name in ["asciinema_automation_hello_world.sh"]:
shutil.copy(example_folder / "hello_world.sh", tmp_path / "tmp")

cli(
[
"--debug",
Expand Down

0 comments on commit 9875c8b

Please sign in to comment.