File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -191,11 +191,11 @@ what exit code is sent to the shell when your application exits from
191191``cmdloop() ``.
192192
193193
194- Asynchronous printing
194+ Asynchronous Feedback
195195=====================
196196``cmd2 `` provides two functions to provide asynchronous feedback to the user without interfering with
197197the command line. This means the feedback is provided to the user when they are still entering text at
198- the prompt. To use this functionality, the application must be running in any terminal that supports
198+ the prompt. To use this functionality, the application must be running in a terminal that supports
199199VT100 control characters and readline. Linux, Mac, and Windows 10 and greater all support these.
200200
201201async_alert()
@@ -208,6 +208,13 @@ async_update_prompt()
208208 changes dynamically in between commands. For instance you could alter the color of the prompt to indicate
209209 a system status or increase a counter to report an event.
210210
211+ ``cmd2 `` also provides a function to change the title of the terminal window. This feature requires the
212+ application be running in a terminal that support VT100 control characters. Linux, Mac, and Windows 10 and
213+ greater all support these.
214+
215+ set_window_title()
216+ Sets the terminal window title
217+
211218
212219The easiest way to understand these function is to see the AsyncPrinting _ example for a demonstration.
213220
Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22# coding=utf-8
3- """A simple example demonstrating an application that asynchronously prints alerts and updates the prompt"""
3+ """
4+ A simple example demonstrating an application that asynchronously prints alerts, updates the prompt
5+ and changes the window title
6+ """
47
58import random
69import threading
1821 "Keep typing..." ,
1922 "Move that cursor..." ,
2023 "Pretty seamless, eh?" ,
24+ "Feedback can also be given in the window title. Notice the arg count up there?" ,
2125 "You can stop and start the alerts by typing stop_alerts and start_alerts" ,
2226 "This demo will now continue to print alerts at random intervals"
2327 ]
@@ -105,8 +109,8 @@ def _get_alerts(self) -> List[str]:
105109 return []
106110
107111 for i in range (0 , rand_num ):
108- alerts .append ("Alert {}" .format (self ._alert_count ))
109112 self ._alert_count += 1
113+ alerts .append ("Alert {}" .format (self ._alert_count ))
110114
111115 self ._next_alert_time = 0
112116
@@ -180,6 +184,8 @@ def _alerter_thread_func(self) -> None:
180184 if alert_str :
181185 # new_prompt is an optional parameter to async_alert()
182186 self .async_alert (alert_str , new_prompt )
187+ new_title = "Alerts Printed: {}" .format (self ._alert_count )
188+ self .set_window_title (new_title )
183189
184190 # No alerts needed to be printed, check if the prompt changed
185191 elif new_prompt != self .prompt :
You can’t perform that action at this time.
0 commit comments