| 184 | return lines |
| 185 | |
| 186 | def _read_key(self) -> str: |
| 187 | if os.name == "nt": |
| 188 | import msvcrt |
| 189 | |
| 190 | first = msvcrt.getch() |
| 191 | if first in {b"\x00", b"\xe0"}: |
| 192 | second = msvcrt.getch() |
| 193 | if second == b"H": |
| 194 | return "up" |
| 195 | if second == b"P": |
| 196 | return "down" |
| 197 | return "other" |
| 198 | if first in {b"\r", b"\n"}: |
| 199 | return "enter" |
| 200 | if first == b"\x03": |
| 201 | return "interrupt" |
| 202 | return "other" |
| 203 | |
| 204 | import termios |
| 205 | import tty |
| 206 | |
| 207 | fd = self.stdin.fileno() |
| 208 | old_settings = termios.tcgetattr(fd) |
| 209 | try: |
| 210 | tty.setraw(fd) |
| 211 | first = self.stdin.read(1) |
| 212 | if first == "\x1b": |
| 213 | second = self.stdin.read(1) |
| 214 | third = self.stdin.read(1) |
| 215 | if second == "[" and third == "A": |
| 216 | return "up" |
| 217 | if second == "[" and third == "B": |
| 218 | return "down" |
| 219 | return "other" |
| 220 | if first in {"\r", "\n"}: |
| 221 | return "enter" |
| 222 | if first == "\x03": |
| 223 | return "interrupt" |
| 224 | return "other" |
| 225 | finally: |
| 226 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
| 227 | |
| 228 | |
| 229 | def shell_quote(value: str) -> str: |