Handle yes/no key presses when the exit confirmation is shown.
(python_input: PythonInput)
| 278 | |
| 279 | |
| 280 | def load_confirm_exit_bindings(python_input: PythonInput) -> KeyBindings: |
| 281 | """ |
| 282 | Handle yes/no key presses when the exit confirmation is shown. |
| 283 | """ |
| 284 | bindings = KeyBindings() |
| 285 | |
| 286 | handle = bindings.add |
| 287 | confirmation_visible = Condition(lambda: python_input.show_exit_confirmation) |
| 288 | |
| 289 | @handle("y", filter=confirmation_visible) |
| 290 | @handle("Y", filter=confirmation_visible) |
| 291 | @handle("enter", filter=confirmation_visible) |
| 292 | @handle("c-d", filter=confirmation_visible) |
| 293 | def _(event: E) -> None: |
| 294 | """ |
| 295 | Really quit. |
| 296 | """ |
| 297 | event.app.exit(exception=EOFError, style="class:exiting") |
| 298 | |
| 299 | @handle(Keys.Any, filter=confirmation_visible) |
| 300 | def _(event: E) -> None: |
| 301 | """ |
| 302 | Cancel exit. |
| 303 | """ |
| 304 | python_input.show_exit_confirmation = False |
| 305 | python_input.app.layout.focus_previous() |
| 306 | |
| 307 | return bindings |
| 308 | |
| 309 | |
| 310 | def auto_newline(buffer: Buffer) -> None: |