mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-15 19:28:00 +01:00
Configurable hotkeys for playback
This commit is contained in:
committed by
Marcin Kulik
parent
c85a4a7acd
commit
0eec28ddb2
@@ -345,6 +345,14 @@ speed = 2
|
||||
; Limit replayed terminal inactivity to max n seconds, default: off
|
||||
idle_time_limit = 1
|
||||
|
||||
; Define hotkey for pausing/resuming playback,
|
||||
; default: space
|
||||
pause_key = p
|
||||
|
||||
; Define hotkey for stepping through playback, a frame at a time,
|
||||
; default: .
|
||||
pause_key = ]
|
||||
|
||||
[notifications]
|
||||
|
||||
; Should desktop notifications be enabled, default: yes
|
||||
|
||||
@@ -11,11 +11,15 @@ class PlayCommand(Command):
|
||||
self.idle_time_limit = args.idle_time_limit
|
||||
self.speed = args.speed
|
||||
self.player = player if player is not None else Player()
|
||||
self.key_bindings = {
|
||||
'pause': config.play_pause_key,
|
||||
'step': config.play_step_key
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
try:
|
||||
with asciicast.open_from_url(self.filename) as a:
|
||||
self.player.play(a, self.idle_time_limit, self.speed)
|
||||
self.player.play(a, self.idle_time_limit, self.speed, self.key_bindings)
|
||||
|
||||
except asciicast.LoadError as e:
|
||||
self.print_error("playback failed: %s" % str(e))
|
||||
|
||||
@@ -126,6 +126,14 @@ class Config:
|
||||
def play_speed(self):
|
||||
return self.config.getfloat('play', 'speed', fallback=1.0)
|
||||
|
||||
@property
|
||||
def play_pause_key(self):
|
||||
return self.__get_key('play', 'pause', ' ')
|
||||
|
||||
@property
|
||||
def play_step_key(self):
|
||||
return self.__get_key('play', 'step', '.')
|
||||
|
||||
@property
|
||||
def notifications_enabled(self):
|
||||
return self.config.getboolean('notifications', 'enabled', fallback=True)
|
||||
|
||||
@@ -8,16 +8,18 @@ from asciinema.term import raw, read_blocking
|
||||
|
||||
class Player:
|
||||
|
||||
def play(self, asciicast, idle_time_limit=None, speed=1.0):
|
||||
def play(self, asciicast, idle_time_limit=None, speed=1.0, key_bindings={}):
|
||||
try:
|
||||
stdin = open('/dev/tty')
|
||||
with raw(stdin.fileno()):
|
||||
self._play(asciicast, idle_time_limit, speed, stdin)
|
||||
self._play(asciicast, idle_time_limit, speed, stdin, key_bindings)
|
||||
except Exception:
|
||||
self._play(asciicast, idle_time_limit, speed, None)
|
||||
self._play(asciicast, idle_time_limit, speed, None, key_bindings)
|
||||
|
||||
def _play(self, asciicast, idle_time_limit, speed, stdin):
|
||||
def _play(self, asciicast, idle_time_limit, speed, stdin, key_bindings):
|
||||
idle_time_limit = idle_time_limit or asciicast.idle_time_limit
|
||||
pause_key = key_bindings.get('pause')
|
||||
step_key = key_bindings.get('step')
|
||||
|
||||
stdout = asciicast.stdout_events()
|
||||
stdout = ev.to_relative_time(stdout)
|
||||
@@ -42,12 +44,12 @@ class Player:
|
||||
ctrl_c = True
|
||||
break
|
||||
|
||||
if 0x20 in data: # space
|
||||
if data == pause_key:
|
||||
paused = False
|
||||
base_time = base_time + (time.time() - pause_time)
|
||||
break
|
||||
|
||||
if 0x2e in data: # period (dot)
|
||||
if data == step_key:
|
||||
delay = 0
|
||||
pause_time = time.time()
|
||||
base_time = pause_time - t
|
||||
@@ -62,7 +64,7 @@ class Player:
|
||||
ctrl_c = True
|
||||
break
|
||||
|
||||
if 0x20 in data: # space
|
||||
if data == pause_key:
|
||||
paused = True
|
||||
pause_time = time.time()
|
||||
slept = t - (pause_time - base_time)
|
||||
|
||||
Reference in New Issue
Block a user