Skip to content

Fix special command newline issues #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions piduck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def eprint(*args, **kwargs):

def string(string):
for char in string:
pharse(char, [[], []], True)
pharse_p2(char, [[], []], True)
sleep(string_delay / 100)


def pharse(line, known, deltrue):
def pharse_p1(line):
global default_delay
global string_delay
global last_line
if line == "":
return
elif line == " ":
Expand All @@ -32,42 +33,54 @@ def pharse(line, known, deltrue):
elif command[0] == "REPEAT":
try:
for i in range(int(command[1])):
pharse(last_line.strip(), [[], []], False)
return # todo
pharse_p1(last_line)
except RecursionError:
eprint("You can not repeat the repeat")
eprint("RecursionError!")
exit(4)
return
elif command[0] == "DEFAULTCHARDELAY":
string_delay = int(command[1])
return
elif command[0] == "DEFAULTDELAY":
default_delay = int(command[1])
return
else:
if not deltrue:
sleep(default_delay / 100)
if command[0] == "STRING":
elif command[0] == "STRING":
sleep(default_delay / 100) # DEFAULT_DELAY
string(line[len(command[0] + " ") :])
last_line = line
return
else:
pharse_p2(line, [[], []], False)
last_line = line
return


def pharse_p2(line, known, deltrue):
if line == "":
return
elif command[0] in keymap.commap:
elif line == " ":
command = [" "]
else:
command = line.split()
if command[0] in keymap.commap:
known[0].append(keymap.commap[command[0]])
if len(command) > 1:
pharse(" ".join(command[1:]), known, True)
pharse_p2(" ".join(command[1:]), known, True)
else:
out(known)
return
elif command[0] in keymap.c1map:
known[1].append(keymap.c1map[command[0]])
if len(command) > 1:
pharse(" ".join(command[1:]), known, True)
pharse_p2(" ".join(command[1:]), known, True)
else:
out(known)
return
elif command[0] in keymap.c2map:
pharse(keymap.c2map[command[0]] + " " + " ".join(command[1:]), known, True)
pharse_p2(keymap.c2map[command[0]] + " " + " ".join(command[1:]), known, True)
return
elif command[0] in aliasmap:
pharse(aliasmap[command[0]] + " " + " ".join(command[1:]), known, True)
pharse_p2(aliasmap[command[0]] + " " + " ".join(command[1:]), known, True)
return
else:
eprint('Could not find "' + command[0] + '"')
Expand All @@ -91,15 +104,13 @@ def out(ccl):


def main():
global last_line
if piargs.input is not None:
file1 = open(piargs.input, "r")
while True:
line = file1.readline()
if not line:
break
pharse(line.strip(), [[], []], False)
last_line = line
parse_p1(line)
file1.close()
else:
while True:
Expand All @@ -109,8 +120,7 @@ def main():
break
if not line:
break
pharse(line.strip(), [[], []], False)
last_line = line
pharse_p1(line)


if __name__ == "__main__":
Expand Down