Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add --auto-type and --auto-waypoint options to the player.

  • Loading branch information...
commit 8e89563cd6fc9ae3e728db1b9f7456f8dfae3119 1 parent d698826
@rfk authored
Showing with 102 additions and 12 deletions.
  1. +30 −3 README.rst
  2. +38 −4 playitagainsam/__init__.py
  3. +34 −5 playitagainsam/player.py
View
33 README.rst
@@ -39,6 +39,13 @@ to type, and hit "enter" when you reach the end of a line.
Extra Features
--------------
+Playitagainsam has some extra features that distinguish it from similar
+solutions.
+
+
+Multiple Terminals
+~~~~~~~~~~~~~~~~~~
+
It's possible to record activity in several terminals simultaneously as part
of a single session, which can be useful for e.g. demonstrating a server
process in one terminal and a client process in another. Join a new terminal
@@ -47,9 +54,29 @@ to an existing recording session like this::
$ pias --join record <output-file>
-There is also a javascript-based player that can be used to embed a recorded
-session into a HTML document. This is useful for websites and HTML-based
-presentations. The code is here:
+Choice of Manual or Automated Typing
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+While the default playback mode assumes interactive typing, it is also possible
+to have pias type automatically for you. You can have it enter individual
+commands but wait for you to manually trigger each newline like this::
+
+ $ pias play <input-file> --auto-type
+
+Or you can have it automatically type all input like this::
+
+ $ pias play <input-file> --auto-type --auto-waypoint
+
+These options both accept an integer millisecond value which will control the
+speed of the automated typing.
+
+
+JavaScript Player
+~~~~~~~~~~~~~~~~~
+
+There is a javascript-based player that can be used to embed a recorded session
+into a HTML document. This is useful for websites or HTML-based presentations.
+The code is here:
https://github.com/rfk/playitagainsam-js/
View
42 playitagainsam/__init__.py
@@ -43,6 +43,13 @@
Extra Features
--------------
+Playitagainsam has some extra features that distinguish it from similar
+solutions.
+
+
+Multiple Terminals
+~~~~~~~~~~~~~~~~~~
+
It's possible to record activity in several terminals simultaneously as part
of a single session, which can be useful for e.g. demonstrating a server
process in one terminal and a client process in another. Join a new terminal
@@ -51,9 +58,29 @@
$ pias --join record <output-file>
-There is also a javascript-based player that can be used to embed a recorded
-session into a HTML document. This is useful for websites and HTML-based
-presentations. The code is here:
+Choice of Manual or Automated Typing
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+While the default playback mode assumes interactive typing, it is also possible
+to have pias type automatically for you. You can have it enter individual
+commands but wait for you to manually trigger each newline like this::
+
+ $ pias play <input-file> --auto-type
+
+Or you can have it automatically type all input like this::
+
+ $ pias play <input-file> --auto-type --auto-waypoint
+
+These options both accept an integer millisecond value which will control the
+speed of the automated typing.
+
+
+JavaScript Player
+~~~~~~~~~~~~~~~~~
+
+There is a javascript-based player that can be used to embed a recorded session
+into a HTML document. This is useful for websites or HTML-based presentations.
+The code is here:
https://github.com/rfk/playitagainsam-js/
@@ -139,6 +166,12 @@ def main(argv, env=None):
parser_play.add_argument("--terminal",
help="the terminal program to execute",
default=util.get_default_terminal())
+ parser_play.add_argument("--auto-type", type=int, nargs="?", const=100,
+ help="automatically type at this speed in ms",
+ default=False)
+ parser_play.add_argument("--auto-waypoint", type=int, nargs="?", const=600,
+ help="auto type newlines at this speed in ms",
+ default=False)
# The "replay" alias for the "play" command.
# Python2.7 argparse doesn't seem to have proper support for aliases.
@@ -199,7 +232,8 @@ def err(msg, *args):
elif args.subcommand in ("play", "replay"):
if not args.join:
eventlog = EventLog(args.datafile, "r")
- player = Player(sock_path, eventlog, args.terminal)
+ player = Player(sock_path, eventlog, args.terminal,
+ args.auto_type, args.auto_waypoint)
player.start()
join_player(sock_path)
View
39 playitagainsam/player.py
@@ -22,10 +22,19 @@ class Player(SocketCoordinator):
waypoint_chars = (six.b("\n"), six.b("\r"))
- def __init__(self, sock_path, eventlog, terminal=None):
+ def __init__(self, sock_path, eventlog, terminal=None, auto_type=False,
+ auto_waypoint=False):
super(Player, self).__init__(sock_path)
self.eventlog = eventlog
self.terminal = terminal or get_default_terminal()
+ if not auto_type:
+ self.auto_type = False
+ else:
+ self.auto_type = auto_type / 1000.0
+ if not auto_waypoint:
+ self.auto_waypoint = False
+ else:
+ self.auto_waypoint = auto_waypoint / 1000.0
self.terminals = {}
self.view_fds = {}
@@ -69,17 +78,37 @@ def _do_open_terminal(self, term):
def _do_close_terminal(self, term):
view_sock, = self.terminals[term]
- c = view_sock.recv(1)
- while c not in self.waypoint_chars:
- c = view_sock.recv(1)
+ self._do_read_waypoint(view_sock)
view_sock.close()
def _do_read(self, term, wanted):
if isinstance(wanted, six.text_type):
wanted = wanted.encode("utf8")
view_sock = self.terminals[term][0]
- c = view_sock.recv(1)
if wanted in self.waypoint_chars:
+ self._do_read_waypoint(view_sock)
+ else:
+ self._do_read_nonwaypoint(view_sock)
+
+ def _do_read_nonwaypoint(self, view_sock):
+ # For non-waypoint characters, behaviour depends on auto-typing mode.
+ # we can can either wait for the user to type something, or just
+ # sleep briefly to simulate the typing.
+ if self.auto_type:
+ time.sleep(self.auto_type)
+ else:
+ c = view_sock.recv(1)
+ while c in self.waypoint_chars:
+ c = view_sock.recv(1)
+
+ def _do_read_waypoint(self, view_sock):
+ # For waypoint characters, behaviour depends on auto-waypoint mode.
+ # Either we just proceed automatically, or the user must actually
+ # type one before we proceed.
+ if self.auto_waypoint:
+ time.sleep(self.auto_waypoint)
+ else:
+ c = view_sock.recv(1)
while c not in self.waypoint_chars:
c = view_sock.recv(1)
Please sign in to comment.
Something went wrong with that request. Please try again.