mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 19:58:03 +01:00
Add -w option to play command
This commit is contained in:
@@ -23,7 +23,7 @@ def rec_command(args, config):
|
||||
return RecordCommand(api, args.filename, args.command, args.title, args.yes, args.quiet, args.max_wait)
|
||||
|
||||
def play_command(args, config):
|
||||
return PlayCommand(args.filename)
|
||||
return PlayCommand(args.filename, args.max_wait)
|
||||
|
||||
def upload_command(args, config):
|
||||
api = Api(config.api_url, os.environ.get("USER"), config.api_token)
|
||||
@@ -66,6 +66,7 @@ For help on a specifc command run:
|
||||
|
||||
# create the parser for the "play" command
|
||||
parser_play = subparsers.add_parser('play', help='Replay terminal session')
|
||||
parser_play.add_argument('-w', '--max-wait', help='limit terminal inactivity to max <sec> seconds (can be fractional)', type=positive_float)
|
||||
parser_play.add_argument('filename')
|
||||
parser_play.set_defaults(func=play_command)
|
||||
|
||||
|
||||
@@ -5,14 +5,15 @@ import asciinema.asciicast as asciicast
|
||||
|
||||
class PlayCommand(Command):
|
||||
|
||||
def __init__(self, filename, player=None):
|
||||
def __init__(self, filename, max_wait, player=None):
|
||||
Command.__init__(self)
|
||||
self.filename = filename
|
||||
self.max_wait = max_wait
|
||||
self.player = player if player is not None else Player()
|
||||
|
||||
def execute(self):
|
||||
try:
|
||||
self.player.play(asciicast.load(self.filename))
|
||||
self.player.play(asciicast.load(self.filename), self.max_wait)
|
||||
|
||||
except FileNotFoundError as e:
|
||||
self.print_warning("Playback failed: %s" % str(e))
|
||||
|
||||
@@ -3,8 +3,10 @@ import time
|
||||
|
||||
class Player:
|
||||
|
||||
def play(self, asciicast):
|
||||
def play(self, asciicast, max_wait=None):
|
||||
for delay, text in asciicast.stdout:
|
||||
if max_wait and delay > max_wait:
|
||||
delay = max_wait
|
||||
time.sleep(delay)
|
||||
sys.stdout.write(text)
|
||||
sys.stdout.flush()
|
||||
|
||||
Reference in New Issue
Block a user