summaryrefslogtreecommitdiffstats
path: root/asciinema/commands/cat.py
diff options
context:
space:
mode:
Diffstat (limited to 'asciinema/commands/cat.py')
-rw-r--r--asciinema/commands/cat.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/asciinema/commands/cat.py b/asciinema/commands/cat.py
new file mode 100644
index 0000000..6c9327c
--- /dev/null
+++ b/asciinema/commands/cat.py
@@ -0,0 +1,35 @@
+import sys
+from typing import Any, Dict
+
+from .. import asciicast
+from ..config import Config
+from ..tty_ import raw
+from .command import Command
+
+
+class CatCommand(Command):
+ def __init__(self, args: Any, config: Config, env: Dict[str, str]):
+ Command.__init__(self, args, config, env)
+ self.filenames = args.filename
+
+ def execute(self) -> int:
+ try:
+ with open("/dev/tty", "rt", encoding="utf-8") as stdin:
+ with raw(stdin.fileno()):
+ return self.cat()
+ except OSError:
+ return self.cat()
+
+ def cat(self) -> int:
+ try:
+ for filename in self.filenames:
+ with asciicast.open_from_url(filename) as a:
+ for _, _type, text in a.events("o"):
+ sys.stdout.write(text)
+ sys.stdout.flush()
+
+ except asciicast.LoadError as e:
+ self.print_error(f"printing failed: {str(e)}")
+ return 1
+
+ return 0