MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / _add_alerts_func

Method _add_alerts_func

examples/async_printing.py:149–171  ·  view source on GitHub ↗

Prints alerts and updates the prompt any time the prompt is showing.

(self)

Source from the content-addressed store, hash-verified

147 return stylize(self.visible_prompt, style=status_color)
148
149 def _add_alerts_func(self) -> None:
150 """Prints alerts and updates the prompt any time the prompt is showing."""
151 self._alert_count = 0
152 self._next_alert_time = 0
153
154 while not self._stop_event.is_set():
155 # Get any alerts that need to be printed
156 alert_str = self._build_alert_str()
157
158 # Build a new prompt
159 new_prompt = self._build_colored_prompt()
160
161 # Check if we have alerts to print
162 if alert_str:
163 self.add_alert(msg=alert_str, prompt=new_prompt)
164 new_title = f"Alerts Printed: {self._alert_count}"
165 self.set_window_title(new_title)
166
167 # Otherwise check if the prompt needs to be updated or refreshed
168 elif self.prompt != new_prompt:
169 self.add_alert(prompt=new_prompt)
170
171 self._stop_event.wait(0.5)
172
173
174if __name__ == "__main__":

Callers

nothing calls this directly

Calls 5

_build_alert_strMethod · 0.95
_build_colored_promptMethod · 0.95
add_alertMethod · 0.80
set_window_titleMethod · 0.80
waitMethod · 0.80

Tested by

no test coverage detected