Add --loop option to play command

This commit is contained in:
Marcin Kulik
2022-05-15 19:00:29 +02:00
parent 4393374281
commit 5e39546e79
4 changed files with 19 additions and 1 deletions

View File

@@ -293,6 +293,7 @@ Available options:
- `-i, --idle-time-limit=<sec>` - Limit replayed terminal inactivity to max `<sec>` seconds - `-i, --idle-time-limit=<sec>` - Limit replayed terminal inactivity to max `<sec>` seconds
- `-s, --speed=<factor>` - Playback speed (can be fractional) - `-s, --speed=<factor>` - Playback speed (can be fractional)
- `-l, --loop` - Play in a loop
- `--stream=<stream>` - Select stream to play (see below) - `--stream=<stream>` - Select stream to play (see below)
- `--out-fmt=<format>` - Select output format (see below) - `--out-fmt=<format>` - Select output format (see below)

View File

@@ -178,6 +178,13 @@ For help on a specific command run:
type=positive_float, type=positive_float,
default=cfg.play_speed, default=cfg.play_speed,
) )
parser_play.add_argument(
"-l",
"--loop",
help="loop loop loop loop",
action="store_true",
default=False,
)
parser_play.add_argument( parser_play.add_argument(
"--out-fmt", "--out-fmt",
help="select output format", help="select output format",

View File

@@ -18,6 +18,7 @@ class PlayCommand(Command):
self.filename = args.filename self.filename = args.filename
self.idle_time_limit = args.idle_time_limit self.idle_time_limit = args.idle_time_limit
self.speed = args.speed self.speed = args.speed
self.loop = args.loop
self.out_fmt = args.out_fmt self.out_fmt = args.out_fmt
self.stream = args.stream self.stream = args.stream
self.player = player if player is not None else Player() self.player = player if player is not None else Player()
@@ -27,6 +28,15 @@ class PlayCommand(Command):
} }
def execute(self) -> int: def execute(self) -> int:
code = self.play()
if self.loop:
while code == 0:
code = self.play()
return code
def play(self) -> int:
try: try:
with asciicast.open_from_url(self.filename) as a: with asciicast.open_from_url(self.filename) as a:
self.player.play( self.player.play(

View File

@@ -154,6 +154,6 @@ class Player: # pylint: disable=too-few-public-methods
delay = delay - slept delay = delay - slept
if ctrl_c: if ctrl_c:
break raise KeyboardInterrupt()
output.write(t, event_type, text) output.write(t, event_type, text)