Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions marimo/_cli/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

from marimo._config.settings import GLOBAL_SETTINGS

_BOLD_PREFIX = "\033[1m"

_MUTED_PREFIX = "\033[37;2m"

_RESET = "\033[0m"


# Check if we're on Windows and if ANSI colors are supported
def _supports_color() -> bool:
Expand Down Expand Up @@ -40,7 +46,9 @@ def _supports_color() -> bool:


def bold(text: str) -> str:
return "\033[1m" + text + "\033[0m" if _USE_COLOR else text
if _USE_COLOR:
return f"{_BOLD_PREFIX}{text}{_RESET}"
return text


def green(text: str, bold: bool = False) -> str:
Expand Down Expand Up @@ -87,7 +95,9 @@ def light_blue(text: str, bold: bool = False) -> str:

def muted(text: str) -> str:
# Use dark gray (37 is white, 2 is dim) which is more widely supported than 90
return "\033[37;2m" + text + "\033[0m" if _USE_COLOR else text
if _USE_COLOR:
return f"{_MUTED_PREFIX}{text}{_RESET}"
return text


def _echo_or_print(*args: Any, **kwargs: Any) -> None:
Expand Down
21 changes: 9 additions & 12 deletions marimo/_server/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
from typing import Optional
from urllib.parse import urlparse

from marimo._cli.print import bold, green, muted
from marimo._config.config import MarimoConfig, MCPConfig
Expand Down Expand Up @@ -100,26 +101,22 @@ def _get_network_url(url: str) -> str:


def _colorized_url(url_string: str) -> str:
from urllib.parse import urlparse

url = urlparse(url_string)
if url.query:
query = muted(f"?{url.query}")
else:
query = ""
query = muted(f"?{url.query}") if url.query else ""
result = f"{url.scheme}://{url.hostname}"

url_string = f"{url.scheme}://{url.hostname}"
# raw https and http urls do not have a port to parse
# Try to append port if present and valid
# raw https and http urls do not have a port to parse
try:
if url.port:
url_string += f":{url.port}"
port = url.port
if port:
result += f":{port}"
except Exception:
# If the port is not a number, don't include it
pass

return bold(
f"{url_string}{url.path}{query}",
)
return bold(f"{result}{url.path}{query}")


def _utf8(msg: str) -> str:
Expand Down