File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 2121
2222
2323class DevConsoleHeader :
24- def __init__ (self , verbose : bool = False ) -> None :
24+ """Renderable representing the header at the top of the console
25+
26+ Args:
27+ port: The port the devtools server is running on.
28+ verbose: Whether verbose logging is enabled
29+ """
30+
31+ def __init__ (self , port : int | None = None , verbose : bool = False ) -> None :
32+ self .port = port
2533 self .verbose = verbose
2634
2735 def __rich_console__ (
2836 self , console : Console , options : ConsoleOptions
2937 ) -> RenderResult :
3038 preamble = Text .from_markup (
3139 f"[bold]Textual Development Console [magenta]v{ version ('textual' )} \n "
32- "[magenta]Run a Textual app with [reverse]textual run --dev my_app.py [/] to connect.\n "
40+ f "[magenta]Run a Textual app with [reverse]{ self . _run_command () } [/] to connect.\n "
3341 "[magenta]Press [reverse]Ctrl+C[/] to quit."
3442 )
3543 if self .verbose :
@@ -45,6 +53,17 @@ def __rich_console__(
4553 yield from line
4654 yield new_line
4755
56+ def _run_command (self ) -> str :
57+ """Get help text for the user to connect to the console
58+
59+ Returns:
60+ The command a user can run to connect a Textual app to the dev server
61+ """
62+ if self .port :
63+ return f"textual run --port { self .port } --dev my_app.py"
64+ else :
65+ return "textual run --dev my_app.py"
66+
4867
4968class DevConsoleLog :
5069 """Renderable representing a single log message
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ async def _on_startup(app: Application) -> None:
4141def _run_devtools (
4242 verbose : bool , exclude : list [str ] | None = None , port : int | None = None
4343) -> None :
44- app = _make_devtools_aiohttp_app (verbose = verbose , exclude = exclude )
44+ app = _make_devtools_aiohttp_app (port = port , verbose = verbose , exclude = exclude )
4545
4646 def noop_print (_ : str ) -> None :
4747 pass
@@ -68,6 +68,7 @@ def noop_print(_: str) -> None:
6868
6969def _make_devtools_aiohttp_app (
7070 size_change_poll_delay_secs : float = DEFAULT_SIZE_CHANGE_POLL_DELAY_SECONDS ,
71+ port : int | None = None ,
7172 verbose : bool = False ,
7273 exclude : list [str ] | None = None ,
7374) -> Application :
@@ -78,7 +79,10 @@ def _make_devtools_aiohttp_app(
7879
7980 app ["verbose" ] = verbose
8081 app ["service" ] = DevtoolsService (
81- update_frequency = size_change_poll_delay_secs , verbose = verbose , exclude = exclude
82+ update_frequency = size_change_poll_delay_secs ,
83+ port = port ,
84+ verbose = verbose ,
85+ exclude = exclude ,
8286 )
8387
8488 app .add_routes (
Original file line number Diff line number Diff line change @@ -30,17 +30,20 @@ class DevtoolsService:
3030 def __init__ (
3131 self ,
3232 update_frequency : float ,
33+ port : int | None = None ,
3334 verbose : bool = False ,
3435 exclude : list [str ] | None = None ,
3536 ) -> None :
3637 """
3738 Args:
3839 update_frequency: The number of seconds to wait between
3940 sending updates of the console size to connected clients.
41+ port: The port the devtools server is running on.
4042 verbose: Enable verbose logging on client.
4143 exclude: List of log groups to exclude from output.
4244 """
4345 self .update_frequency = update_frequency
46+ self .port = port
4447 self .verbose = verbose
4548 self .exclude = {name .upper () for name in exclude } if exclude else set ()
4649 self .console = Console ()
@@ -50,7 +53,7 @@ def __init__(
5053 async def start (self ) -> None :
5154 """Starts devtools tasks"""
5255 self .size_poll_task = asyncio .create_task (self ._console_size_poller ())
53- self .console .print (DevConsoleHeader (verbose = self .verbose ))
56+ self .console .print (DevConsoleHeader (port = self . port , verbose = self .verbose ))
5457
5558 @property
5659 def clients_connected (self ) -> bool :
You can’t perform that action at this time.
0 commit comments