-
Notifications
You must be signed in to change notification settings - Fork 10
/
playback.py
executable file
·96 lines (73 loc) · 1.68 KB
/
playback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import keyboard
import ast
import time, sys
filename=sys.argv[1]
# stop after this many commits
stopearly=9999
def vimcmd(x):
keyboard.write(x)
keyboard.press_and_release('enter')
def window(lr):
keyboard.press_and_release('ctrl+w, '+lr)
time.sleep(3)
vimcmd("vim")
time.sleep(0.3)
# probably should have grabbed this from the repo
vimcmd(":set syntax=html")
vimcmd(":set timeoutlen=1000 ttimeoutlen=0") #not sure if this helps
lines_added=0
lines_removed=0
current_line=0
msgwindow=0
def navigate(to):
global current_line
jump=abs(current_line-to)
vimcmd(":"+str(to))
current_line=to
if jump>3:
keyboard.write('zz') # centre scroll
if jump>15:
vimcmd(':syntax sync fromstart')
vimcmd(':')
time.sleep(min(0.3,jump*0.005))
for line in open(filename):
try:
(d,i,t)= ast.literal_eval(line)
except:
try:
(name,msg) = ast.literal_eval(line)
except:
continue;
if (msgwindow==0):
vimcmd(':set splitright')
vimcmd(":vnew")
keyboard.write('40')
keyboard.press_and_release('ctrl+w')
keyboard.write('|')
vimcmd(':set linebreak')
vimcmd(":set syntax=xml")
vimcmd(':file commit_messages')
msgwindow=1
else:
window('right')
keyboard.write('i<'+name+'>: '+msg)
keyboard.press_and_release('esc')
window('left')
stopearly=stopearly-1
if stopearly<=0: exit()
lines_added=0
lines_removed=0
continue;
if keyboard.is_pressed('esc'):
exit()
time.sleep(0.01)
if d==None: #insertion
navigate(i)
keyboard.write("O"+t, delay=0.001 )
keyboard.press_and_release('esc')
lines_added=1+lines_added
elif i==None:
navigate(d+lines_added-lines_removed)
keyboard.write("dd")
lines_removed=1+lines_removed