Background worker that processes queued alerts and dynamic prompt updates.
(self)
| 3592 | return self._read_raw_input(prompt, temp_session, is_password=True) |
| 3593 | |
| 3594 | def _process_alerts(self) -> None: |
| 3595 | """Background worker that processes queued alerts and dynamic prompt updates.""" |
| 3596 | while True: |
| 3597 | with self._alert_condition: |
| 3598 | # Wait until we have alerts and are allowed to display them, or shutdown is signaled. |
| 3599 | self._alert_condition.wait_for( |
| 3600 | lambda: (len(self._alert_queue) > 0 and self._alert_allowed) or self._alert_shutdown |
| 3601 | ) |
| 3602 | |
| 3603 | # Shutdown immediately even if we have alerts. |
| 3604 | if self._alert_shutdown: |
| 3605 | break |
| 3606 | |
| 3607 | # Hold the condition lock while printing to block command execution. This |
| 3608 | # prevents async alerts from printing once a command starts. |
| 3609 | |
| 3610 | # Print all alerts at once to reduce flicker. |
| 3611 | alert_text = "\n".join(alert.msg for alert in self._alert_queue if alert.msg) |
| 3612 | |
| 3613 | # Find the latest prompt update among all pending alerts. |
| 3614 | latest_prompt = None |
| 3615 | for alert in reversed(self._alert_queue): |
| 3616 | if ( |
| 3617 | alert.prompt is not None |
| 3618 | and alert.prompt != self.prompt |
| 3619 | and alert.timestamp > self._alert_prompt_timestamp |
| 3620 | ): |
| 3621 | latest_prompt = alert.prompt |
| 3622 | self._alert_prompt_timestamp = alert.timestamp |
| 3623 | break |
| 3624 | |
| 3625 | # Clear the alerts |
| 3626 | self._alert_queue.clear() |
| 3627 | |
| 3628 | if latest_prompt is not None: |
| 3629 | # Update prompt so patch_stdout() or get_app().invalidate() can redraw it. |
| 3630 | self.prompt = latest_prompt |
| 3631 | |
| 3632 | if alert_text: |
| 3633 | # Print the alert messages above the prompt. |
| 3634 | with patch_stdout(): |
| 3635 | print_formatted_text(pt_filter_style(alert_text)) |
| 3636 | |
| 3637 | elif latest_prompt is not None: |
| 3638 | # Refresh UI immediately to show the new prompt |
| 3639 | get_app().invalidate() |
| 3640 | |
| 3641 | def _read_command_line(self, prompt: str) -> str: |
| 3642 | """Read the next command line from the input stream. |
nothing calls this directly
no test coverage detected