Wait for tmux to display a prompt, indicating the command has completed

This commit is contained in:
AJ Bowen
2017-10-29 13:45:42 -07:00
parent 0508d24046
commit f46856ff63

View File

@@ -5,6 +5,7 @@ import os
import re
import subprocess
import sys
import time
logging.basicConfig(level=logging.DEBUG)
@@ -94,7 +95,20 @@ except Exception as e:
keymaps = { "^C": "\x03" }
def wait_for_success():
secs, timeout = 0, 30
while secs <= timeout:
time.sleep(1)
output = [x for x in subprocess.check_output(["tmux", "capture-pane", "-p"]).split("\n") if x]
if output[-1] == "$":
return True
else:
print(".")
secs += 1
while True:
# Send a form feed to clear screen (while preserving scrollback)
print("\033[2J")
with open("nextstep","w") as f:
f.write(str(i))
slide, snippet, method, data = actions[i]
@@ -113,6 +127,11 @@ while True:
if method == "bash":
data += "\n"
subprocess.check_call(["tmux", "send-keys", "{}".format(data)])
while not wait_for_success():
while raw_input("WARNING /!\ Command timed out. Continue anyway? ('n' to wait) ") == 'n':
if wait_for_success():
break
break
else:
print "DO NOT KNOW HOW TO HANDLE {} {!r}".format(method, data)
i += 1