Procházet zdrojové kódy

format stuff correctly

Khaleel Al-Adhami před 2 měsíci
rodič
revize
851f49e775

+ 8 - 6
reflex/model.py

@@ -92,9 +92,10 @@ def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine:
 
     if not environment.ALEMBIC_CONFIG.get().exists():
         console.warn(
-            "Database is not initialized, run "
-            + colored("reflex db init", attrs=("bold",))
-            + " first."
+            colored("Database is not initialized, run ", "warning")
+            + colored("reflex db init", "warning", attrs=("bold",))
+            + colored(" first.", "warning"),
+            color=None,
         )
     _ENGINE[url] = sqlmodel.create_engine(
         url,
@@ -136,9 +137,10 @@ def get_async_engine(url: str | None) -> sqlalchemy.ext.asyncio.AsyncEngine:
 
     if not environment.ALEMBIC_CONFIG.get().exists():
         console.warn(
-            "Database is not initialized, run "
-            + colored("reflex db init", attrs=("bold",))
-            + " first."
+            colored("Database is not initialized, run ", "warning")
+            + colored("reflex db init", "warning", attrs=("bold",))
+            + colored(" first.", "warning"),
+            color=None,
         )
     _ASYNC_ENGINE[url] = sqlalchemy.ext.asyncio.create_async_engine(
         url,

+ 10 - 8
reflex/reflex.py

@@ -458,11 +458,12 @@ def db_init():
     # Check the alembic config.
     if environment.ALEMBIC_CONFIG.get().exists():
         console.error(
-            "Database is already initialized. Use "
-            + colored("reflex db makemigrations", attrs=("bold",))
-            + " to create schema change scripts and "
-            + colored("reflex db migrate", attrs=("bold",))
-            + " to apply migrations to a new or existing database.",
+            colored("Database is already initialized. Use ", "error")
+            + colored("reflex db makemigrations", "error", attrs=("bold",))
+            + colored(" to create schema change scripts and ", "error")
+            + colored("reflex db migrate", "error", attrs=("bold",))
+            + colored(" to apply migrations to a new or existing database.", "error"),
+            color=None,
         )
         return
 
@@ -512,9 +513,10 @@ def makemigrations(
             if "Target database is not up to date." not in str(command_error):
                 raise
             console.error(
-                f"{command_error} Run "
-                + colored("reflex db migrate", attrs=("bold",))
-                + " to update database."
+                colored(f"{command_error} Run ", "error")
+                + colored("reflex db migrate", "error", attrs=("bold",))
+                + colored(" to update database.", "error"),
+                color=None,
             )
 
 

+ 21 - 12
reflex/utils/console.py

@@ -74,6 +74,7 @@ class Status:
 
     message: str = "Loading"
     _reprinter: Reprinter | None = dataclasses.field(default=None, init=False)
+    _parity: int = dataclasses.field(default=0, init=False)
 
     def __enter__(self):
         """Enter the context manager.
@@ -110,7 +111,17 @@ class Status:
             kwargs: Keyword arguments to pass to the print function.
         """
         if self._reprinter:
-            self._reprinter.reprint(f"O {msg}")
+            char = (
+                "◐"
+                if self._parity % 4 == 0
+                else (
+                    "◓"
+                    if self._parity % 4 == 1
+                    else ("◑" if self._parity % 4 == 2 else "◒")
+                )
+            )
+            self._parity += 1
+            self._reprinter.reprint(f"{char} {msg}")
 
 
 @dataclass
@@ -142,8 +153,8 @@ class Console:
         """
         terminal_width = _get_terminal_width()
         remaining_width = (
-            terminal_width - len(title) - 4
-        )  # 4 for the spaces and characters around the title
+            terminal_width - len(title) - 2
+        )  # 2 for the spaces around the title
         left_padding = remaining_width // 2
         right_padding = remaining_width - left_padding
 
@@ -153,13 +164,11 @@ class Console:
         title = colored(title, color, attrs=("bold",) if bold else ())
 
         rule_line = (
-            " "
-            + colored("─" * left_padding, rule_color)
+            colored("─" * left_padding, rule_color)
             + " "
             + title
             + " "
             + colored("─" * right_padding, rule_color)
-            + " "
         )
         self.print(rule_line, **kwargs)
 
@@ -310,7 +319,7 @@ def debug(msg: str, dedupe: bool = False, **kwargs):
                 return
             else:
                 _EMITTED_DEBUG.add(msg)
-        kwargs.setdefault("color", "magenta")
+        kwargs.setdefault("color", "debug")
         print(msg, **kwargs)
 
 
@@ -328,7 +337,7 @@ def info(msg: str, dedupe: bool = False, **kwargs):
                 return
             else:
                 _EMITTED_INFO.add(msg)
-        kwargs.setdefault("color", "cyan")
+        kwargs.setdefault("color", "info")
         print(f"Info: {msg}", **kwargs)
 
 
@@ -346,7 +355,7 @@ def success(msg: str, dedupe: bool = False, **kwargs):
                 return
             else:
                 _EMITTED_SUCCESS.add(msg)
-        kwargs.setdefault("color", "green")
+        kwargs.setdefault("color", "success")
         print(f"Success: {msg}", **kwargs)
 
 
@@ -391,7 +400,7 @@ def warn(msg: str, dedupe: bool = False, **kwargs):
                 return
             else:
                 _EMIITED_WARNINGS.add(msg)
-        kwargs.setdefault("color", "light_yellow")
+        kwargs.setdefault("color", "warning")
         print(f"Warning: {msg}", **kwargs)
 
 
@@ -458,7 +467,7 @@ def deprecate(
             f"removed in {removal_version}. ({loc})"
         )
         if _LOG_LEVEL <= LogLevel.WARNING:
-            kwargs.setdefault("color", "yellow")
+            kwargs.setdefault("color", "warning")
             print(f"DeprecationWarning: {msg}", **kwargs)
         if dedupe:
             _EMITTED_DEPRECATION_WARNINGS.add(dedupe_key)
@@ -478,7 +487,7 @@ def error(msg: str, dedupe: bool = False, **kwargs):
                 return
             else:
                 _EMITTED_ERRORS.add(msg)
-        kwargs.setdefault("color", "red")
+        kwargs.setdefault("color", "error")
         print(f"{msg}", **kwargs)
 
 

+ 26 - 16
reflex/utils/prerequisites.py

@@ -567,9 +567,10 @@ def validate_app_name(app_name: str | None = None) -> str:
     # Make sure the app is not named "reflex".
     if app_name.lower() == constants.Reflex.MODULE_NAME:
         console.error(
-            "The app directory cannot be named "
-            + colored(constants.Reflex.MODULE_NAME, attrs=("bold",))
-            + "."
+            colored("The app directory cannot be named ", "error")
+            + colored(constants.Reflex.MODULE_NAME, "error", attrs=("bold",))
+            + colored(".", "error"),
+            color=None,
         )
         raise typer.Exit(1)
 
@@ -661,7 +662,10 @@ def rename_app(new_app_name: str, loglevel: constants.LogLevel):
     rename_path_up_tree(Path(module_path.origin), config.app_name, new_app_name)
 
     console.success(
-        "App directory renamed to " + colored(new_app_name, attrs=("bold",)) + "."
+        colored("App directory renamed to ", "success")
+        + colored(new_app_name, "success", attrs=("bold",))
+        + colored(".", "success"),
+        color=None,
     )
 
 
@@ -1273,9 +1277,12 @@ def needs_reinit(frontend: bool = True) -> bool:
     if not constants.Config.FILE.exists():
         console.error(
             colored(constants.Config.FILE, "cyan")
-            + " not found. Move to the root folder of your project, or run "
-            + colored(constants.Reflex.MODULE_NAME + " init", attrs=("bold",))
-            + " to start a new project."
+            + colored(
+                " not found. Move to the root folder of your project, or run ", "error"
+            )
+            + colored(constants.Reflex.MODULE_NAME + " init", "error", attrs=("bold",))
+            + colored(" to start a new project.", "error"),
+            color=None,
         )
         raise typer.Exit(1)
 
@@ -1456,9 +1463,10 @@ def check_db_initialized() -> bool:
         and not environment.ALEMBIC_CONFIG.get().exists()
     ):
         console.error(
-            "Database is not initialized. Run "
-            + colored("reflex db init", attrs=("bold",))
-            + " first."
+            colored("Database is not initialized. Run ", "error")
+            + colored("reflex db init", "error", attrs=("bold",))
+            + colored(" first.", "error"),
+            color=None,
         )
         return False
     return True
@@ -1475,16 +1483,18 @@ def check_schema_up_to_date():
                 write_migration_scripts=False,
             ):
                 console.error(
-                    "Detected database schema changes. Run "
-                    + colored("reflex db makemigrations", attrs=("bold",))
-                    + " to generate migration scripts.",
+                    colored("Detected database schema changes. Run ", "error")
+                    + colored("reflex db makemigrations", "error", attrs=("bold",))
+                    + colored(" to generate migration scripts.", "error"),
+                    color=None,
                 )
         except CommandError as command_error:
             if "Target database is not up to date." in str(command_error):
                 console.error(
-                    f"{command_error} Run "
-                    + colored("reflex db migrate", attrs=("bold",))
-                    + " to update database."
+                    colored(f"{command_error} Run ", "error")
+                    + colored("reflex db migrate", "error", attrs=("bold",))
+                    + colored(" to update database.", "error"),
+                    color=None,
                 )
 
 

+ 8 - 6
reflex/utils/processes.py

@@ -117,9 +117,10 @@ def change_port(port: int, _type: str) -> int:
     if is_process_on_port(new_port):
         return change_port(new_port, _type)
     console.info(
-        f"The {_type} will run on port "
-        + colored(port, attrs=("bold", "underline"))
-        + "."
+        colored(f"The {_type} will run on port ", "info")
+        + colored(port, "info", attrs=("bold", "underline"))
+        + colored(".", "info"),
+        color=None,
     )
     return new_port
 
@@ -326,9 +327,10 @@ def stream_logs(
         if analytics_enabled:
             telemetry.send("error", context=message)
         console.error(
-            "Run with "
-            + colored("--loglevel debug", attrs=("bold",))
-            + " for the full log."
+            colored("Run with ", "error")
+            + colored("--loglevel debug", "error", attrs=("bold",))
+            + colored(" for the full log.", "error"),
+            color=None,
         )
         raise typer.Exit(1)
 

+ 10 - 0
reflex/utils/terminal.py

@@ -51,6 +51,11 @@ _Color = Literal[
     "light_magenta",
     "light_cyan",
     "white",
+    "error",
+    "warning",
+    "info",
+    "success",
+    "debug",
 ]
 
 
@@ -71,6 +76,11 @@ _COLORS: dict[_Color, int] = {
     "light_magenta": 95,
     "light_cyan": 96,
     "white": 97,
+    "error": 31,
+    "warning": 33,
+    "info": 36,
+    "success": 32,
+    "debug": 90,
 }
 
 _BackgroundColor = Literal[