Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"uvicorn[standard] >= 0.17.6",
"rignore >= 0.5.1",
"httpx >= 0.27.0",
"rich-toolkit>=0.20.3",
"rich-toolkit>=0.20.5",
"pydantic[email] >= 2.7.4; python_version < '3.13'",
"pydantic[email] >= 2.8.0; python_version == '3.13'",
"pydantic[email] >= 2.12.0; python_version >= '3.14'",
Expand Down
6 changes: 5 additions & 1 deletion src/fastapi_cloud_cli/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ def _get_bullet_prefix(self, emoji: str) -> Text:
prefix = Text(" " * self.content_padding)

if emoji:
prefix.append_text(Text.from_markup(emoji))
bullet = Text.from_markup(emoji)
bullet.plain = self.symbol(
bullet.plain, fallback=" x" if emoji == ERROR_BULLET else "*"
)
prefix.append_text(bullet)

prefix.pad_right(
self.content_padding + self.emoji_column_width - prefix.cell_len
Expand Down
60 changes: 60 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import subprocess
import sys
Expand Down Expand Up @@ -266,6 +267,65 @@ def test_fastapi_style_progress_status_emoji_states() -> None:
assert render_plain(style.render_element(progress)) == " ✗ Working\n"


@pytest.mark.parametrize("encoding", ["ascii", "cp1252", "gbk", "utf-8"])
@pytest.mark.parametrize("emoji", ["📁", "⚡", ERROR_BULLET, "✅", "🟡", "🐤"])
def test_bullets_can_be_written_to_encoded_streams(encoding: str, emoji: str) -> None:
style = FastAPIStyle()
with io.TextIOWrapper(
io.BytesIO(), encoding=encoding, errors="strict", newline="\n"
) as stream:
style.console.file = stream
style.console.print(style.render_element("Working\nSecond line", emoji=emoji))
stream.flush()

expected_bullet = Text.from_markup(emoji).plain
if encoding != "utf-8":
expected_bullet = " x" if emoji == ERROR_BULLET else "*"
padding = " " * (3 - Text(expected_bullet).cell_len)
assert stream.buffer.getvalue().decode(encoding) == (
f" {expected_bullet}{padding}Working\n Second line\n"
)


@pytest.mark.parametrize("encoding", ["cp1252", "gbk"])
def test_bullet_fallback_preserves_supported_text_and_layout(encoding: str) -> None:
style = FastAPIStyle()
with io.TextIOWrapper(
io.BytesIO(), encoding=encoding, errors="strict", newline="\n"
) as stream:
style.console.file = stream
text = "café" if encoding == "cp1252" else "项目"
style.console.print(style.render_element(text, emoji="*"))
style.console.print(style.render_element("alpha\nbeta", bullet=False))
style.console.print(
style.render_element(get_details_table([("Name", text)]), bullet=False)
)
stream.flush()

assert stream.buffer.getvalue().decode(encoding) == (
f" * {text}\n alpha\n beta\n Name {text}\n"
)
assert (
style.get_cursor_offset_for_element(
Input(label="Project name", style=style, emoji="📁")
).left
== 4
)


@pytest.mark.parametrize("encoding", ["cp1252", "gbk"])
def test_error_bullet_fallback_keeps_error_style(encoding: str) -> None:
style = FastAPIStyle()
with io.TextIOWrapper(io.BytesIO(), encoding=encoding) as stream:
style.console.file = stream
prefix = style._get_bullet_prefix(ERROR_BULLET)

assert prefix.plain == " x "
error_style = prefix.get_style_at_offset(style.console, 2)
assert error_style.bold
assert error_style.color == style.console.get_style("error").color


def test_fastapi_style_gets_cursor_offset_with_and_without_bullet_column() -> None:
style = FastAPIStyle()

Expand Down
Loading