Get a single keypress in a cross-platform way using readchar.
()
| 125 | |
| 126 | |
| 127 | def get_key(): |
| 128 | """Get a single keypress in a cross-platform way using readchar.""" |
| 129 | key = readchar.readkey() |
| 130 | |
| 131 | if key == readchar.key.UP or key == readchar.key.CTRL_P: |
| 132 | return 'up' |
| 133 | if key == readchar.key.DOWN or key == readchar.key.CTRL_N: |
| 134 | return 'down' |
| 135 | |
| 136 | if key == readchar.key.ENTER: |
| 137 | return 'enter' |
| 138 | |
| 139 | if key == readchar.key.ESC: |
| 140 | return 'escape' |
| 141 | |
| 142 | if key == readchar.key.CTRL_C: |
| 143 | raise KeyboardInterrupt |
| 144 | |
| 145 | return key |
| 146 | |
| 147 | def select_with_arrows( |
| 148 | options: dict[str, str], |
no outgoing calls
no test coverage detected