Skip to content

Commit 636520b

Browse files
authored
Merge pull request #12 from gitdev-bash/Fix-Special-Command-Newline-Issues
Fix special command newline issues
2 parents ef876c7 + be72dd0 commit 636520b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

piduck.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ def eprint(*args, **kwargs):
1111

1212
def string(string):
1313
for char in string:
14-
pharse(char, [[], []], True)
14+
pharse_p2(char, [[], []], True)
1515
sleep(string_delay / 100)
1616

1717

18-
def pharse(line, known, deltrue):
18+
def pharse_p1(line):
1919
global default_delay
2020
global string_delay
21+
global last_line
2122
if line == "":
2223
return
2324
elif line == " ":
@@ -32,42 +33,54 @@ def pharse(line, known, deltrue):
3233
elif command[0] == "REPEAT":
3334
try:
3435
for i in range(int(command[1])):
35-
pharse(last_line.strip(), [[], []], False)
36-
return # todo
36+
pharse_p1(last_line)
3737
except RecursionError:
38-
eprint("You can not repeat the repeat")
38+
eprint("RecursionError!")
3939
exit(4)
40+
return
4041
elif command[0] == "DEFAULTCHARDELAY":
4142
string_delay = int(command[1])
4243
return
4344
elif command[0] == "DEFAULTDELAY":
4445
default_delay = int(command[1])
4546
return
46-
else:
47-
if not deltrue:
48-
sleep(default_delay / 100)
49-
if command[0] == "STRING":
47+
elif command[0] == "STRING":
48+
sleep(default_delay / 100) # DEFAULT_DELAY
5049
string(line[len(command[0] + " ") :])
50+
last_line = line
51+
return
52+
else:
53+
pharse_p2(line, [[], []], False)
54+
last_line = line
55+
return
56+
57+
58+
def pharse_p2(line, known, deltrue):
59+
if line == "":
5160
return
52-
elif command[0] in keymap.commap:
61+
elif line == " ":
62+
command = [" "]
63+
else:
64+
command = line.split()
65+
if command[0] in keymap.commap:
5366
known[0].append(keymap.commap[command[0]])
5467
if len(command) > 1:
55-
pharse(" ".join(command[1:]), known, True)
68+
pharse_p2(" ".join(command[1:]), known, True)
5669
else:
5770
out(known)
5871
return
5972
elif command[0] in keymap.c1map:
6073
known[1].append(keymap.c1map[command[0]])
6174
if len(command) > 1:
62-
pharse(" ".join(command[1:]), known, True)
75+
pharse_p2(" ".join(command[1:]), known, True)
6376
else:
6477
out(known)
6578
return
6679
elif command[0] in keymap.c2map:
67-
pharse(keymap.c2map[command[0]] + " " + " ".join(command[1:]), known, True)
80+
pharse_p2(keymap.c2map[command[0]] + " " + " ".join(command[1:]), known, True)
6881
return
6982
elif command[0] in aliasmap:
70-
pharse(aliasmap[command[0]] + " " + " ".join(command[1:]), known, True)
83+
pharse_p2(aliasmap[command[0]] + " " + " ".join(command[1:]), known, True)
7184
return
7285
else:
7386
eprint('Could not find "' + command[0] + '"')
@@ -91,15 +104,13 @@ def out(ccl):
91104

92105

93106
def main():
94-
global last_line
95107
if piargs.input is not None:
96108
file1 = open(piargs.input, "r")
97109
while True:
98110
line = file1.readline()
99111
if not line:
100112
break
101-
pharse(line.strip(), [[], []], False)
102-
last_line = line
113+
parse_p1(line)
103114
file1.close()
104115
else:
105116
while True:
@@ -109,8 +120,7 @@ def main():
109120
break
110121
if not line:
111122
break
112-
pharse(line.strip(), [[], []], False)
113-
last_line = line
123+
pharse_p1(line)
114124

115125

116126
if __name__ == "__main__":

0 commit comments

Comments
 (0)