@@ -299,6 +299,7 @@ def __init__(
299299 allow_redirection : bool = True ,
300300 auto_load_commands : bool = False ,
301301 auto_suggest : bool = True ,
302+ bottom_toolbar : bool = False ,
302303 command_sets : Iterable [CommandSet ] | None = None ,
303304 complete_style : CompleteStyle = CompleteStyle .COLUMN ,
304305 include_ipy : bool = False ,
@@ -337,6 +338,7 @@ def __init__(
337338 must be manually installed with `register_command_set`.
338339 :param auto_suggest: If True, cmd2 will provide fish shell style auto-suggestions
339340 based on history. If False, these will not be provided.
341+ :param bottom_toolbar: if ``True``, then a bottom toolbar will be displayed.
340342 :param command_sets: Provide CommandSet instances to load during cmd2 initialization.
341343 This allows CommandSets with custom constructor parameters to be
342344 loaded. This also allows the a set of CommandSets to be provided
@@ -467,6 +469,7 @@ def _(event: Any) -> None: # pragma: no cover
467469 self .history_adapter = Cmd2History (self )
468470 self .completer = Cmd2Completer (self )
469471 self .lexer = Cmd2Lexer (self )
472+ self .bottom_toolbar = bottom_toolbar
470473
471474 self .auto_suggest = None
472475 if auto_suggest :
@@ -475,7 +478,7 @@ def _(event: Any) -> None: # pragma: no cover
475478 try :
476479 self .session : PromptSession [str ] = PromptSession (
477480 auto_suggest = self .auto_suggest ,
478- bottom_toolbar = self .get_bottom_toolbar ,
481+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
479482 complete_in_thread = True ,
480483 complete_style = complete_style ,
481484 complete_while_typing = False ,
@@ -490,7 +493,7 @@ def _(event: Any) -> None: # pragma: no cover
490493 # where isatty() is True but there is no real console.
491494 self .session = PromptSession (
492495 auto_suggest = self .auto_suggest ,
493- bottom_toolbar = self .get_bottom_toolbar ,
496+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
494497 complete_in_thread = True ,
495498 complete_style = complete_style ,
496499 complete_while_typing = False ,
@@ -1698,14 +1701,35 @@ def _reset_completion_defaults(self) -> None:
16981701 def get_bottom_toolbar (self ) -> list [str | tuple [str , str ]] | None :
16991702 """Get the bottom toolbar content.
17001703
1701- Override this if you want a bottom toolbar to be displayed .
1704+ If self.bottom_toolbar is False, returns None .
17021705
1703- :return: tokens for prompt-toolkit to populate in the bottom toolbar
1704- or None for no bottom toolbar.
1706+ Otherwise returns tokens for prompt-toolkit to populate in the bottom toolbar.
17051707
17061708 NOTE: This content can extend over multiple lines. However we would recommend
17071709 keeping it to a single line or two lines maximum.
17081710 """
1711+ if self .bottom_toolbar :
1712+ import datetime
1713+ import shutil
1714+
1715+ # Get the current time in ISO format with 0.01s precision
1716+ dt = datetime .datetime .now (datetime .timezone .utc ).astimezone ()
1717+ now = dt .strftime ('%Y-%m-%dT%H:%M:%S.%f' )[:- 4 ] + dt .strftime ('%z' )
1718+ left_text = sys .argv [0 ]
1719+
1720+ # Get terminal width to calculate padding for right-alignment
1721+ cols , _ = shutil .get_terminal_size ()
1722+ padding_size = cols - len (left_text ) - len (now ) - 1
1723+ if padding_size < 1 :
1724+ padding_size = 1
1725+ padding = ' ' * padding_size
1726+
1727+ # Return formatted text for prompt-toolkit
1728+ return [
1729+ ('ansigreen' , left_text ),
1730+ ('' , padding ),
1731+ ('ansicyan' , now ),
1732+ ]
17091733 return None
17101734
17111735 def get_rprompt (self ) -> str | FormattedText | None :
@@ -3408,7 +3432,7 @@ def get_prompt() -> ANSI | str:
34083432
34093433 return temp_session1 .prompt (
34103434 prompt_to_use ,
3411- bottom_toolbar = self .get_bottom_toolbar ,
3435+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
34123436 completer = completer_to_use ,
34133437 lexer = self .lexer ,
34143438 pre_run = self .pre_prompt ,
@@ -3418,7 +3442,7 @@ def get_prompt() -> ANSI | str:
34183442 # history is None
34193443 return self .session .prompt (
34203444 prompt_to_use ,
3421- bottom_toolbar = self .get_bottom_toolbar ,
3445+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
34223446 completer = completer_to_use ,
34233447 lexer = self .lexer ,
34243448 pre_run = self .pre_prompt ,
@@ -3437,7 +3461,7 @@ def get_prompt() -> ANSI | str:
34373461 )
34383462 line = temp_session2 .prompt (
34393463 prompt ,
3440- bottom_toolbar = self .get_bottom_toolbar ,
3464+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
34413465 pre_run = self .pre_prompt ,
34423466 rprompt = self .get_rprompt ,
34433467 )
@@ -3454,7 +3478,7 @@ def get_prompt() -> ANSI | str:
34543478 output = self .session .output ,
34553479 )
34563480 line = temp_session3 .prompt (
3457- bottom_toolbar = self .get_bottom_toolbar ,
3481+ bottom_toolbar = self .get_bottom_toolbar if self . bottom_toolbar else None ,
34583482 pre_run = self .pre_prompt ,
34593483 rprompt = self .get_rprompt ,
34603484 )
0 commit comments