Selaa lähdekoodia

Enable customization of the welcome message

nghia-vo 1 vuosi sitten
vanhempi
säilyke
9e3790dae2
2 muutettua tiedostoa jossa 5 lisäystä ja 3 poistoa
  1. 3 1
      nicegui/ui_run.py
  2. 2 2
      nicegui/welcome.py

+ 3 - 1
nicegui/ui_run.py

@@ -45,6 +45,7 @@ def run(*,
         prod_js: bool = True,
         endpoint_documentation: Literal['none', 'internal', 'page', 'all'] = 'none',
         storage_secret: Optional[str] = None,
+        welcome_message: Optional[str] = 'NiceGUI ready to go ',
         **kwargs: Any,
         ) -> None:
     """ui.run
@@ -76,6 +77,7 @@ def run(*,
     :param prod_js: whether to use the production version of Vue and Quasar dependencies (default: `True`)
     :param endpoint_documentation: control what endpoints appear in the autogenerated OpenAPI docs (default: 'none', options: 'none', 'internal', 'page', 'all')
     :param storage_secret: secret key for browser-based storage (default: `None`, a value is required to enable ui.storage.individual and ui.storage.browser)
+    :param welcome_message: display a welcome message with URLs to access the NiceGUI app (default: `NiceGUI ready to go `)
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`    
     """
     core.app.config.add_run_config(
@@ -103,7 +105,7 @@ def run(*,
     if on_air:
         air.instance = air.Air('' if on_air is True else on_air)
 
-    core.app.on_startup(welcome.print_message)
+    core.app.on_startup(welcome.print_message(welcome_message))
 
     if multiprocessing.current_process().name != 'MainProcess':
         return

+ 2 - 2
nicegui/welcome.py

@@ -13,9 +13,9 @@ def _get_all_ips() -> List[str]:
     return ips
 
 
-async def print_message() -> None:
+async def print_message(welcome_message) -> None:
     """Print a welcome message with URLs to access the NiceGUI app."""
-    print('NiceGUI ready to go ', end='', flush=True)
+    print(welcome_message, end='', flush=True)
     host = os.environ['NICEGUI_HOST']
     port = os.environ['NICEGUI_PORT']
     ips = set((await run.io_bound(_get_all_ips)) if host == '0.0.0.0' else [])