mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 03:38:03 +01:00
Add --loop option to play command
This commit is contained in:
@@ -293,6 +293,7 @@ Available options:
|
||||
|
||||
- `-i, --idle-time-limit=<sec>` - Limit replayed terminal inactivity to max `<sec>` seconds
|
||||
- `-s, --speed=<factor>` - Playback speed (can be fractional)
|
||||
- `-l, --loop` - Play in a loop
|
||||
- `--stream=<stream>` - Select stream to play (see below)
|
||||
- `--out-fmt=<format>` - Select output format (see below)
|
||||
|
||||
|
||||
@@ -178,6 +178,13 @@ For help on a specific command run:
|
||||
type=positive_float,
|
||||
default=cfg.play_speed,
|
||||
)
|
||||
parser_play.add_argument(
|
||||
"-l",
|
||||
"--loop",
|
||||
help="loop loop loop loop",
|
||||
action="store_true",
|
||||
default=False,
|
||||
)
|
||||
parser_play.add_argument(
|
||||
"--out-fmt",
|
||||
help="select output format",
|
||||
|
||||
@@ -18,6 +18,7 @@ class PlayCommand(Command):
|
||||
self.filename = args.filename
|
||||
self.idle_time_limit = args.idle_time_limit
|
||||
self.speed = args.speed
|
||||
self.loop = args.loop
|
||||
self.out_fmt = args.out_fmt
|
||||
self.stream = args.stream
|
||||
self.player = player if player is not None else Player()
|
||||
@@ -27,6 +28,15 @@ class PlayCommand(Command):
|
||||
}
|
||||
|
||||
def execute(self) -> int:
|
||||
code = self.play()
|
||||
|
||||
if self.loop:
|
||||
while code == 0:
|
||||
code = self.play()
|
||||
|
||||
return code
|
||||
|
||||
def play(self) -> int:
|
||||
try:
|
||||
with asciicast.open_from_url(self.filename) as a:
|
||||
self.player.play(
|
||||
|
||||
@@ -154,6 +154,6 @@ class Player: # pylint: disable=too-few-public-methods
|
||||
delay = delay - slept
|
||||
|
||||
if ctrl_c:
|
||||
break
|
||||
raise KeyboardInterrupt()
|
||||
|
||||
output.write(t, event_type, text)
|
||||
|
||||
Reference in New Issue
Block a user