with self._path_test.open('r', encoding='utf8') as f:
self._playbook = tuple(line[:-1] for line in f.readlines())
self._playbook_anchors: dict[str, int] = {}
- for idx, line in enumerate(self._playbook):
- if line[:1] == '|':
- self._playbook_anchors[line[1:]] = idx + 1
+ while True:
+ self._playbook_anchors.clear()
+ for idx, line in enumerate(self._playbook):
+ if line[:1] == '|':
+ self._playbook_anchors[line[1:]] = idx
+ found_repeat = False
+ for idx, line in enumerate(self._playbook):
+ if line[:1] in '#|' or not line.strip():
+ continue
+ context, msg = line.split(' ', maxsplit=1)
+ if context == 'repeat':
+ found_repeat = True
+ start_key, end_key = msg.split(' ')
+ start = self._playbook_anchors[start_key] + 1
+ end = self._playbook_anchors[end_key]
+ self._playbook = (self._playbook[:idx]
+ + self._playbook[int(start):int(end)]
+ + self._playbook[idx + 1:])
+ break
+ if found_repeat:
+ continue
+ break
self._playbook_idx = -1
self._play_till_next_log()
if line[:1] in '#|' or not line.strip():
continue
context, msg = line.split(' ', maxsplit=1)
- if context == 'repeat':
- start_key, end_key = msg.split(' ')
- start = self._playbook_anchors[start_key]
- end = self._playbook_anchors[end_key]
- self._playbook = (self._playbook[:self._playbook_idx + 1]
- + self._playbook[int(start):int(end)]
- + self._playbook[self._playbook_idx + 1:])
- continue
if context == '>':
for c in msg:
self._q_keypresses.put(c)