Rename max-wait to idle-time-limit

This commit is contained in:
Marcin Kulik
2017-10-26 13:21:38 +02:00
parent 6b099cb4f8
commit ac58f27a2e
9 changed files with 53 additions and 47 deletions

View File

@@ -124,7 +124,7 @@ Available options:
* `--stdin` - Enable stdin (keyboard) recording (see below) * `--stdin` - Enable stdin (keyboard) recording (see below)
* `-c, --command=<command>` - Specify command to record, defaults to $SHELL * `-c, --command=<command>` - Specify command to record, defaults to $SHELL
* `-t, --title=<title>` - Specify the title of the asciicast * `-t, --title=<title>` - Specify the title of the asciicast
* `-w, --max-wait=<sec>` - Reduce recorded terminal inactivity to max `<sec>` seconds * `-i, --idle-time-limit=<sec>` - Limit recorded terminal inactivity to max `<sec>` seconds
* `-y, --yes` - Answer "yes" to all prompts (e.g. upload confirmation) * `-y, --yes` - Answer "yes" to all prompts (e.g. upload confirmation)
* `-q, --quiet` - Be quiet, suppress all notices/warnings (implies -y) * `-q, --quiet` - Be quiet, suppress all notices/warnings (implies -y)
@@ -169,7 +169,7 @@ Playing from IPFS:
Available options: Available options:
* `-w, --max-wait=<sec>` - Reduce replayed terminal inactivity to max `<sec>` seconds * `-i, --idle-time-limit=<sec>` - Limit replayed terminal inactivity to max `<sec>` seconds
* `-s, --speed=<factor>` - Playback speedup (can be fractional) * `-s, --speed=<factor>` - Playback speedup (can be fractional)
NOTE: it is recommended to run `asciinema play` in a terminal of dimensions not NOTE: it is recommended to run `asciinema play` in a terminal of dimensions not
@@ -239,12 +239,12 @@ available options set:
command = /bin/bash -l command = /bin/bash -l
stdin = no stdin = no
env = SHELL,TERM,USER env = SHELL,TERM,USER
maxwait = 2 idle_time_limit = 2
yes = true yes = true
quiet = true quiet = true
[play] [play]
maxwait = 1 idle_time_limit = 1
The options in `[api]` section are related to API location and authentication. The options in `[api]` section are related to API location and authentication.
To tell asciinema recorder to use your own asciinema site instance rather than To tell asciinema recorder to use your own asciinema site instance rather than

View File

@@ -22,11 +22,11 @@ def positive_float(value):
def rec_command(args, config): def rec_command(args, config):
api = Api(config.api_url, os.environ.get("USER"), config.api_token) api = Api(config.api_url, os.environ.get("USER"), config.api_token)
return RecordCommand(api, args.filename, args.stdin, args.command, args.env, args.title, args.yes, args.quiet, args.max_wait) return RecordCommand(api, args.filename, args.stdin, args.command, args.env, args.title, args.yes, args.quiet, args.idle_time_limit)
def play_command(args, config): def play_command(args, config):
return PlayCommand(args.filename, args.max_wait, args.speed) return PlayCommand(args.filename, args.idle_time_limit, args.speed)
def upload_command(args, config): def upload_command(args, config):
@@ -60,8 +60,8 @@ def main():
\x1b[1masciinema rec demo.cast\x1b[0m \x1b[1masciinema rec demo.cast\x1b[0m
Record terminal and upload it to asciinema.org, specifying title: Record terminal and upload it to asciinema.org, specifying title:
\x1b[1masciinema rec -t "My git tutorial"\x1b[0m \x1b[1masciinema rec -t "My git tutorial"\x1b[0m
Record terminal to local file, "trimming" longer pauses to max 2.5 sec: Record terminal to local file, limiting idle time to max 2.5 sec:
\x1b[1masciinema rec -w 2.5 demo.cast\x1b[0m \x1b[1masciinema rec -i 2.5 demo.cast\x1b[0m
Replay terminal recording from local file: Replay terminal recording from local file:
\x1b[1masciinema play demo.cast\x1b[0m \x1b[1masciinema play demo.cast\x1b[0m
Replay terminal recording hosted on asciinema.org: Replay terminal recording hosted on asciinema.org:
@@ -81,7 +81,7 @@ For help on a specific command run:
parser_rec.add_argument('-c', '--command', help='command to record, defaults to $SHELL', default=cfg.record_command) parser_rec.add_argument('-c', '--command', help='command to record, defaults to $SHELL', default=cfg.record_command)
parser_rec.add_argument('-e', '--env', help='list of environment variables to capture, defaults to ' + config.DEFAULT_RECORD_ENV, default=cfg.record_env) parser_rec.add_argument('-e', '--env', help='list of environment variables to capture, defaults to ' + config.DEFAULT_RECORD_ENV, default=cfg.record_env)
parser_rec.add_argument('-t', '--title', help='title of the asciicast') parser_rec.add_argument('-t', '--title', help='title of the asciicast')
parser_rec.add_argument('-w', '--max-wait', help='limit recorded terminal inactivity to max <sec> seconds (can be fractional)', type=positive_float, default=maybe_str(cfg.record_max_wait)) parser_rec.add_argument('-i', '--idle-time-limit', help='limit recorded idle time to given number of seconds', type=positive_float, default=maybe_str(cfg.record_idle_time_limit))
parser_rec.add_argument('-y', '--yes', help='answer "yes" to all prompts (e.g. upload confirmation)', action='store_true', default=cfg.record_yes) parser_rec.add_argument('-y', '--yes', help='answer "yes" to all prompts (e.g. upload confirmation)', action='store_true', default=cfg.record_yes)
parser_rec.add_argument('-q', '--quiet', help='be quiet, suppress all notices/warnings (implies -y)', action='store_true', default=cfg.record_quiet) parser_rec.add_argument('-q', '--quiet', help='be quiet, suppress all notices/warnings (implies -y)', action='store_true', default=cfg.record_quiet)
parser_rec.add_argument('filename', nargs='?', default='', help='filename/path to save the recording to') parser_rec.add_argument('filename', nargs='?', default='', help='filename/path to save the recording to')
@@ -89,7 +89,7 @@ For help on a specific command run:
# create the parser for the "play" command # create the parser for the "play" command
parser_play = subparsers.add_parser('play', help='Replay terminal session') 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, default=maybe_str(cfg.play_max_wait)) parser_play.add_argument('-i', '--idle-time-limit', help='limit idle time during playback to given number of seconds', type=positive_float, default=maybe_str(cfg.play_idle_time_limit))
parser_play.add_argument('-s', '--speed', help='playback speedup (can be fractional)', type=positive_float, default=cfg.play_speed) parser_play.add_argument('-s', '--speed', help='playback speedup (can be fractional)', type=positive_float, default=cfg.play_speed)
parser_play.add_argument('filename', help='local path, http/ipfs URL or "-" (read from stdin)') parser_play.add_argument('filename', help='local path, http/ipfs URL or "-" (read from stdin)')
parser_play.set_defaults(func=play_command) parser_play.set_defaults(func=play_command)

View File

@@ -3,7 +3,7 @@ class Asciicast:
def __init__(self, stdout): def __init__(self, stdout):
self.version = 1 self.version = 1
self.__stdout = stdout self.__stdout = stdout
self.max_wait = None # v1 doesn't store it self.idle_time_limit = None # v1 doesn't store it
def stdout(self): def stdout(self):
return self.__stdout return self.__stdout

View File

@@ -10,10 +10,10 @@ from asciinema.pty_recorder import PtyRecorder
class Asciicast: class Asciicast:
def __init__(self, f, max_wait): def __init__(self, f, idle_time_limit):
self.version = 2 self.version = 2
self.__file = f self.__file = f
self.max_wait = max_wait self.idle_time_limit = idle_time_limit
def stdout(self): def stdout(self):
prev_ts = 0 prev_ts = 0
@@ -29,8 +29,8 @@ class Asciicast:
def load_from_file(f): def load_from_file(f):
header = json.loads(f.readline()) header = json.loads(f.readline())
max_wait = header.get('max_wait') idle_time_limit = header.get('idle_time_limit')
return Asciicast(f, max_wait) return Asciicast(f, idle_time_limit)
def write_json_lines_from_queue(path, queue): def write_json_lines_from_queue(path, queue):
@@ -88,7 +88,7 @@ class Recorder:
self.pty_recorder = pty_recorder if pty_recorder is not None else PtyRecorder() self.pty_recorder = pty_recorder if pty_recorder is not None else PtyRecorder()
self.env = env if env is not None else os.environ self.env = env if env is not None else os.environ
def record(self, path, rec_stdin, user_command, env_whitelist, title, max_wait): def record(self, path, rec_stdin, user_command, env_whitelist, title, idle_time_limit):
cols = int(subprocess.check_output(['tput', 'cols'])) cols = int(subprocess.check_output(['tput', 'cols']))
lines = int(subprocess.check_output(['tput', 'lines'])) lines = int(subprocess.check_output(['tput', 'lines']))

View File

@@ -5,17 +5,17 @@ import asciinema.asciicast as asciicast
class PlayCommand(Command): class PlayCommand(Command):
def __init__(self, filename, max_wait, speed, player=None): def __init__(self, filename, idle_time_limit, speed, player=None):
Command.__init__(self) Command.__init__(self)
self.filename = filename self.filename = filename
self.max_wait = max_wait self.idle_time_limit = idle_time_limit
self.speed = speed self.speed = speed
self.player = player if player is not None else Player() self.player = player if player is not None else Player()
def execute(self): def execute(self):
try: try:
with asciicast.open_from_url(self.filename) as a: with asciicast.open_from_url(self.filename) as a:
self.player.play(a, self.max_wait, self.speed) self.player.play(a, self.idle_time_limit, self.speed)
except asciicast.LoadError as e: except asciicast.LoadError as e:
self.print_warning("Playback failed: %s" % str(e)) self.print_warning("Playback failed: %s" % str(e))

View File

@@ -9,7 +9,7 @@ from asciinema.api import APIError
class RecordCommand(Command): class RecordCommand(Command):
def __init__(self, api, filename, rec_stdin, command, env_whitelist, title, assume_yes, quiet, max_wait, recorder=None): def __init__(self, api, filename, rec_stdin, command, env_whitelist, title, assume_yes, quiet, idle_time_limit, recorder=None):
Command.__init__(self, quiet) Command.__init__(self, quiet)
self.api = api self.api = api
self.filename = filename self.filename = filename
@@ -18,7 +18,7 @@ class RecordCommand(Command):
self.env_whitelist = env_whitelist self.env_whitelist = env_whitelist
self.title = title self.title = title
self.assume_yes = assume_yes or quiet self.assume_yes = assume_yes or quiet
self.max_wait = max_wait self.idle_time_limit = idle_time_limit
self.recorder = recorder if recorder is not None else Recorder() self.recorder = recorder if recorder is not None else Recorder()
def execute(self): def execute(self):
@@ -44,7 +44,7 @@ class RecordCommand(Command):
self.command, self.command,
self.env_whitelist, self.env_whitelist,
self.title, self.title,
self.max_wait self.idle_time_limit
) )
self.print_info("Asciicast recording finished.") self.print_info("Asciicast recording finished.")

View File

@@ -49,8 +49,9 @@ class Config:
return self.config.get('record', 'env', fallback=DEFAULT_RECORD_ENV) return self.config.get('record', 'env', fallback=DEFAULT_RECORD_ENV)
@property @property
def record_max_wait(self): def record_idle_time_limit(self):
return self.config.getfloat('record', 'maxwait', fallback=None) fallback = self.config.getfloat('record', 'maxwait', fallback=None) # pre 2.0
return self.config.getfloat('record', 'idle_time_limit', fallback=fallback)
@property @property
def record_yes(self): def record_yes(self):
@@ -61,8 +62,9 @@ class Config:
return self.config.getboolean('record', 'quiet', fallback=False) return self.config.getboolean('record', 'quiet', fallback=False)
@property @property
def play_max_wait(self): def play_idle_time_limit(self):
return self.config.getfloat('play', 'maxwait', fallback=None) fallback = self.config.getfloat('play', 'maxwait', fallback=None) # pre 2.0
return self.config.getfloat('play', 'idle_time_limit', fallback=fallback)
@property @property
def play_speed(self): def play_speed(self):

View File

@@ -5,9 +5,9 @@ import time
from asciinema.term import raw, read_non_blocking from asciinema.term import raw, read_non_blocking
def compress_time(stdout, max_wait): def compress_time(stdout, idle_time_limit):
if max_wait: if idle_time_limit:
return ([min(delay, max_wait), text] for delay, text in stdout) return ([min(delay, idle_time_limit), text] for delay, text in stdout)
else: else:
return stdout return stdout
@@ -18,18 +18,18 @@ def adjust_speed(stdout, speed):
class Player: class Player:
def play(self, asciicast, max_wait=None, speed=1.0): def play(self, asciicast, idle_time_limit=None, speed=1.0):
if os.isatty(sys.stdin.fileno()): if os.isatty(sys.stdin.fileno()):
with raw(sys.stdin.fileno()): with raw(sys.stdin.fileno()):
self._play(asciicast, max_wait, speed, True) self._play(asciicast, idle_time_limit, speed, True)
else: else:
self._play(asciicast, max_wait, speed, False) self._play(asciicast, idle_time_limit, speed, False)
def _play(self, asciicast, max_wait, speed, raw): def _play(self, asciicast, idle_time_limit, speed, raw):
max_wait = max_wait or asciicast.max_wait idle_time_limit = idle_time_limit or asciicast.idle_time_limit
stdout = asciicast.stdout() stdout = asciicast.stdout()
stdout = compress_time(stdout, max_wait) stdout = compress_time(stdout, idle_time_limit)
stdout = adjust_speed(stdout, speed) stdout = adjust_speed(stdout, speed)
for delay, text in stdout: for delay, text in stdout:

View File

@@ -50,9 +50,9 @@ def test_default_record_env():
assert_equal('SHELL,TERM', config.record_env) assert_equal('SHELL,TERM', config.record_env)
def test_default_record_max_wait(): def test_default_record_idle_time_limit():
config = create_config('') config = create_config('')
assert_equal(None, config.record_max_wait) assert_equal(None, config.record_idle_time_limit)
def test_default_record_yes(): def test_default_record_yes():
@@ -65,9 +65,9 @@ def test_default_record_quiet():
assert_equal(False, config.record_quiet) assert_equal(False, config.record_quiet)
def test_default_play_max_wait(): def test_default_play_idle_time_limit():
config = create_config('') config = create_config('')
assert_equal(None, config.play_max_wait) assert_equal(None, config.play_idle_time_limit)
def test_api_url(): def test_api_url():
@@ -122,10 +122,12 @@ def test_record_env():
assert_equal('FOO,BAR', config.record_env) assert_equal('FOO,BAR', config.record_env)
def test_record_max_wait(): def test_record_idle_time_limit():
max_wait = '2.35' config = create_config("[record]\nidle_time_limit = 2.35")
config = create_config("[record]\nmaxwait = %s" % max_wait) assert_equal(2.35, config.record_idle_time_limit)
assert_equal(2.35, config.record_max_wait)
config = create_config("[record]\nmaxwait = 2.35")
assert_equal(2.35, config.record_idle_time_limit)
def test_record_yes(): def test_record_yes():
@@ -140,7 +142,9 @@ def test_record_quiet():
assert_equal(True, config.record_quiet) assert_equal(True, config.record_quiet)
def test_play_max_wait(): def test_play_idle_time_limit():
max_wait = '2.35' config = create_config("[play]\nidle_time_limit = 2.35")
config = create_config("[play]\nmaxwait = %s" % max_wait) assert_equal(2.35, config.play_idle_time_limit)
assert_equal(2.35, config.play_max_wait)
config = create_config("[play]\nmaxwait = 2.35")
assert_equal(2.35, config.play_idle_time_limit)