(self, e: events.Event | str)
| 121 | self.rl_char_sequences = edit_keys |
| 122 | |
| 123 | def process_event(self, e: events.Event | str) -> None: |
| 124 | assert self.has_focus |
| 125 | |
| 126 | logger.debug("fake input processing event %r", e) |
| 127 | if isinstance(e, events.Event): |
| 128 | if isinstance(e, events.PasteEvent): |
| 129 | for ee in e.events: |
| 130 | if ee not in self.rl_char_sequences: |
| 131 | self.add_input_character(ee) |
| 132 | elif isinstance(e, events.SigIntEvent): |
| 133 | self.coderunner.sigint_happened_in_main_context = True |
| 134 | self.has_focus = False |
| 135 | self.current_line = "" |
| 136 | self.cursor_offset = 0 |
| 137 | self.repl.run_code_and_maybe_finish() |
| 138 | elif e in self.rl_char_sequences: |
| 139 | self.cursor_offset, self.current_line = self.rl_char_sequences[e]( |
| 140 | self.cursor_offset, self.current_line |
| 141 | ) |
| 142 | elif e == "<Ctrl-d>": |
| 143 | if not len(self.current_line): |
| 144 | self.repl.send_to_stdin("\n") |
| 145 | self.has_focus = False |
| 146 | self.current_line = "" |
| 147 | self.cursor_offset = 0 |
| 148 | self.repl.run_code_and_maybe_finish(for_code="") |
| 149 | elif e in ("\n", "\r", "<Ctrl-j>", "<Ctrl-m>"): |
| 150 | line = f"{self.current_line}\n" |
| 151 | self.repl.send_to_stdin(line) |
| 152 | self.has_focus = False |
| 153 | self.current_line = "" |
| 154 | self.cursor_offset = 0 |
| 155 | self.repl.run_code_and_maybe_finish(for_code=line) |
| 156 | elif e != "<ESC>": # add normal character |
| 157 | self.add_input_character(e) |
| 158 | |
| 159 | if not self.current_line.endswith(("\n", "\r")): |
| 160 | self.repl.send_to_stdin(self.current_line) |
| 161 | |
| 162 | def add_input_character(self, e: str) -> None: |
| 163 | if e == "<SPACE>": |
nothing calls this directly
no test coverage detected