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

Method _build_alert_str

examples/async_printing.py:106–126  ·  view source on GitHub ↗

Combines alerts into one string that can be printed to the terminal :return: the alert string.

(self)

Source from the content-addressed store, hash-verified

104 return alerts
105
106 def _build_alert_str(self) -> str:
107 """Combines alerts into one string that can be printed to the terminal
108 :return: the alert string.
109 """
110 alert_str = ""
111 alerts = self._get_alerts()
112
113 longest_alert = max(ALERTS, key=len)
114 num_asterisks = len(longest_alert) + 8
115
116 for i, cur_alert in enumerate(alerts):
117 # Use padding to center the alert
118 padding = " " * int((num_asterisks - len(cur_alert)) / 2)
119
120 if i > 0:
121 alert_str += "\n"
122 alert_str += "*" * num_asterisks + "\n"
123 alert_str += padding + cur_alert + padding + "\n"
124 alert_str += "*" * num_asterisks + "\n"
125
126 return alert_str
127
128 def _build_colored_prompt(self) -> str:
129 """Randomly builds a colored prompt

Callers 1

_add_alerts_funcMethod · 0.95

Calls 1

_get_alertsMethod · 0.95

Tested by

no test coverage detected