mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Add asciinema cat command
This commit is contained in:
@@ -178,6 +178,14 @@ NOTE: it is recommended to run `asciinema play` in a terminal of dimensions not
|
||||
smaller than the one used for recording as there's no "transcoding" of control
|
||||
sequences for new terminal size.
|
||||
|
||||
### `cat <filename>`
|
||||
|
||||
__Print full output of recorded asciicast to a terminl.__
|
||||
|
||||
While `asciinema play <filename>` replays the recorded session using timing
|
||||
information saved in the asciicast, `asciinema cat <filename>` dumps the full
|
||||
output (including all escape sequences) to a terminal immediately.
|
||||
|
||||
### `upload <filename>`
|
||||
|
||||
__Upload recorded asciicast to asciinema.org site.__
|
||||
|
||||
@@ -8,6 +8,7 @@ import asciinema.config as config
|
||||
from asciinema.commands.auth import AuthCommand
|
||||
from asciinema.commands.record import RecordCommand
|
||||
from asciinema.commands.play import PlayCommand
|
||||
from asciinema.commands.cat import CatCommand
|
||||
from asciinema.commands.upload import UploadCommand
|
||||
from asciinema.api import Api
|
||||
|
||||
@@ -29,6 +30,10 @@ def play_command(args, config):
|
||||
return PlayCommand(args.filename, args.idle_time_limit, args.speed)
|
||||
|
||||
|
||||
def cat_command(args, config):
|
||||
return CatCommand(args.filename)
|
||||
|
||||
|
||||
def upload_command(args, config):
|
||||
api = Api(config.api_url, os.environ.get("USER"), config.api_token)
|
||||
return UploadCommand(api, args.filename)
|
||||
@@ -67,6 +72,8 @@ def main():
|
||||
\x1b[1masciinema play demo.cast\x1b[0m
|
||||
Replay terminal recording hosted on asciinema.org:
|
||||
\x1b[1masciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8\x1b[0m
|
||||
Print full output of recorded session:
|
||||
\x1b[1masciinema cat demo.cast\x1b[0m
|
||||
|
||||
For help on a specific command run:
|
||||
\x1b[1masciinema <command> -h\x1b[0m""",
|
||||
@@ -97,6 +104,11 @@ For help on a specific command run:
|
||||
parser_play.add_argument('filename', help='local path, http/ipfs URL or "-" (read from stdin)')
|
||||
parser_play.set_defaults(func=play_command)
|
||||
|
||||
# create the parser for the "cat" command
|
||||
parser_cat = subparsers.add_parser('cat', help='Print full output of terminal session')
|
||||
parser_cat.add_argument('filename', help='local path, http/ipfs URL or "-" (read from stdin)')
|
||||
parser_cat.set_defaults(func=cat_command)
|
||||
|
||||
# create the parser for the "upload" command
|
||||
parser_upload = subparsers.add_parser('upload', help='Upload locally saved terminal session to asciinema.org')
|
||||
parser_upload.add_argument('filename', help='filename or path of local recording')
|
||||
|
||||
24
asciinema/commands/cat.py
Normal file
24
asciinema/commands/cat.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import sys
|
||||
|
||||
from asciinema.commands.command import Command
|
||||
import asciinema.asciicast as asciicast
|
||||
|
||||
|
||||
class CatCommand(Command):
|
||||
|
||||
def __init__(self, filename):
|
||||
Command.__init__(self)
|
||||
self.filename = filename
|
||||
|
||||
def execute(self):
|
||||
try:
|
||||
with asciicast.open_from_url(self.filename) as a:
|
||||
for t, text in a.stdout():
|
||||
sys.stdout.write(text)
|
||||
sys.stdout.flush()
|
||||
|
||||
except asciicast.LoadError as e:
|
||||
self.print_error("Printing failed: %s" % str(e))
|
||||
return 1
|
||||
|
||||
return 0
|
||||
@@ -35,6 +35,16 @@ asciinema play -s 5 tests/demo.cast
|
||||
asciinema play -s 5 -i 0.2 tests/demo.cast
|
||||
cat tests/demo.cast | asciinema play -s 5 -
|
||||
|
||||
# test cat command
|
||||
|
||||
# asciicast v1
|
||||
asciinema cat tests/demo.json
|
||||
cat tests/demo.json | asciinema cat -
|
||||
|
||||
# asciicast v2
|
||||
asciinema cat tests/demo.cast
|
||||
cat tests/demo.cast | asciinema cat -
|
||||
|
||||
# test rec command
|
||||
|
||||
asciinema rec -c who "$TMP_DATA_DIR/1.cast"
|
||||
|
||||
Reference in New Issue
Block a user