Skip to content

Commit 6f786eb

Browse files
committed
Update file-header command and change background thread to run 4 times a second instead of 10
1 parent 663eb03 commit 6f786eb

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

examples/getting_started.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
"""A simple example cmd2 application demonstrating many common features.
2+
"""An example cmd2 application demonstrating many common features.
33
44
Features demonstrated include all of the following:
55
1) Colorizing/stylizing output
@@ -15,6 +15,8 @@
1515
11) Shortcuts for commands
1616
12) Persistent bottom toolbar with realtime status updates
1717
13) Right prompt which displays contextual information
18+
14) Using a background thread to update the bottom toolbar in an efficient manner
19+
15) Using preloop() and postloop() hooks to start and stop a background thread
1820
"""
1921

2022
import datetime
@@ -109,8 +111,8 @@ def _update_toolbar_state(self) -> None:
109111
with self._toolbar_lock:
110112
self._toolbar_state["now"] = now
111113

112-
# Sleep to yield CPU, polling 10 times a second
113-
self._stop_thread_event.wait(0.1)
114+
# Sleep to yield CPU, polling 4 times a second
115+
self._stop_thread_event.wait(0.25)
114116

115117
def preloop(self) -> None:
116118
"""Hook method executed once when the cmdloop() method is called."""
@@ -136,7 +138,7 @@ def get_bottom_toolbar(self) -> AnyFormattedText:
136138
# If called outside a running app loop (e.g., in unit tests), get_app()
137139
# safely returns a dummy app with an 80-column fallback.
138140
cols = get_app().output.get_size().columns
139-
padding_size = cols - len(left_text) - len(now) - 1
141+
padding_size = cols - len(left_text) - len(now)
140142
if padding_size < 1:
141143
padding_size = 1
142144
padding = " " * padding_size

0 commit comments

Comments
 (0)