comparison sh-replay @ 11:82176b2a61da

Various tweaks to sh-replay
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sat, 08 Mar 2014 21:31:00 -0500
parents 39800c8f0532
children
comparison
equal deleted inserted replaced
10:80b765f69c5f 11:82176b2a61da
49 else: 49 else:
50 cwd = os.path.split(cwd)[-1] 50 cwd = os.path.split(cwd)[-1]
51 51
52 hg_id = get_hg_id() 52 hg_id = get_hg_id()
53 53
54 sys.stdout.write(yellow("jordi@REVSETS", style="bold") + ":" 54 sys.stdout.write(yellow("jordi@evolve", style="bold") + ":"
55 + blue(cwd, style="bold") + " " 55 + blue(cwd, style="bold") + " "
56 + magenta(hg_id, style="bold") + "$ ") 56 + magenta(hg_id, style="bold") + "\n$ ")
57
58 def waitforenter():
59 while True:
60 key = getch()
61 if ord(key) == 13:
62 sys.stdout.write("\n")
63 sys.stdout.flush()
64 break
65
66 def backtoslides():
67 print
68 print " <---- Back to slides "
69 print
70 waitforenter()
57 71
58 def main(): 72 def main():
59 subprocess.call("reset") 73 subprocess.call("reset")
60 with open(sys.argv[1]) as f: 74 with open(sys.argv[1]) as f:
61 cmds = [cmd.strip() for cmd in f.readlines() 75 cmds = [cmd.strip() for cmd in f.readlines()
62 if cmd.strip() and not cmd.strip().startswith("#")] 76 if cmd.strip() and not cmd.strip().startswith("#")]
63 77
64 global curr_cmd 78 global curr_cmd
65 for cmd in cmds: 79 for cmd in cmds:
66 print_prompt() 80 print_prompt()
81
82 # Control commands...
83 if cmd[0] == "!":
84 cmd = cmd[1:]
85 if cmd == "RET":
86 backtoslides()
87 continue
88
67 curr_cmd = "" 89 curr_cmd = ""
68 for c in cmd: 90 for c in cmd:
69 key = getch() 91 key = getch()
70 sys.stdout.write(c) 92 sys.stdout.write(c)
71 sys.stdout.flush() 93 sys.stdout.flush()
72 curr_cmd += c 94 curr_cmd += c
73 95
74 while True: 96 waitforenter()
75 key = getch()
76 if ord(key) == 13:
77 sys.stdout.write("\n")
78 sys.stdout.flush()
79 break
80 97
81 if cmd.startswith("cd "): 98 if cmd.startswith("cd "):
82 cd(cmd[3:]) 99 cd(cmd[3:])
83 else: 100 else:
84 with open("/tmp/cmd", "w") as f: 101 with open("/tmp/cmd", "w") as f:
86 f.write(cmd + "\n") 103 f.write(cmd + "\n")
87 f.flush() 104 f.flush()
88 105
89 subprocess.call(["/bin/bash", "-l", "/tmp/cmd"]) 106 subprocess.call(["/bin/bash", "-l", "/tmp/cmd"])
90 107
91 while True:
92 key = getch()
93 if ord(key) == 13:
94 sys.stdout.write("\n")
95 sys.stdout.flush()
96 break
97
98 print
99 print
100 print
101 print
102 print
103 print
104 print
105 print
106 print yellow(" TTTTTT HH HH A NN NN KK KK SSS ", style="bold")
107 print yellow(" TT HH HH A A NNNN NN KK KK SS ", style="bold")
108 print yellow(" TT HHHHH AAAAA NN NNNN KKKKK SS ", style="bold")
109 print yellow(" TT HH HH AA AA NN NNN KK KK SS ", style="bold")
110 print yellow(" TT HH HH AA AA NN NN KK KK SSS ", style="bold")
111 print
112 print
113 print
114 print
115 print
116 print
117 print
118 print
119
120 108
121 if __name__ == "__main__": 109 if __name__ == "__main__":
122 main() 110 main()
123