Move terminal dimensions detection to asciinema.term module

This commit is contained in:
Marcin Kulik
2018-11-28 19:46:34 +01:00
parent 20b8565708
commit 7b7f19ea97
2 changed files with 16 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import time
import asciinema.asciicast.v2 as v2
import asciinema.pty as pty
import asciinema.term as term
def record_asciicast(path, command=None, append=False, idle_time_limit=None,
@@ -29,9 +30,11 @@ def record_asciicast(path, command=None, append=False, idle_time_limit=None,
if capture_env is None:
capture_env = ['SHELL', 'TERM']
w, h = term.get_size()
full_metadata = {
'width': int(subprocess.check_output(['tput', 'cols'])),
'height': int(subprocess.check_output(['tput', 'lines'])),
'width': w,
'height': h,
'timestamp': int(time.time())
}

View File

@@ -1,6 +1,7 @@
import tty
import select
import os
import select
import subprocess
import tty
class raw():
@@ -26,3 +27,11 @@ def read_blocking(fd, timeout):
return os.read(fd, 1024)
return b''
def get_size():
# TODO maybe use os.get_terminal_size ?
return (
int(subprocess.check_output(['tput', 'cols'])),
int(subprocess.check_output(['tput', 'lines']))
)