Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
feat: Improve formatting of announcements (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Nov 26, 2021
1 parent 775700c commit fbc3c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/186.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve formatting of announcements using box-drawing characters and a Markdown formatter
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'multidict>=5.1.0',
'python-dateutil>=2.8.2',
'PyYAML~=5.4.1',
'rich~=10.5.0',
'rich~=10.14',
'tabulate>=0.8.9',
'tqdm>=4.61',
'yarl>=1.6.3',
Expand Down
21 changes: 14 additions & 7 deletions src/ai/backend/client/cli/announcement.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import hashlib
import json
from pathlib import Path
import sys

import appdirs

from rich import print as rprint
from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
from rich.style import Style

_printed_announcement = False

Expand All @@ -27,10 +28,16 @@ def announce(msg: str, only_once: bool = True) -> None:
msg_hash = hasher.hexdigest()

if not (last_state['hash'] == msg_hash and last_state['dismissed']):
rprint('[bold cyan]The server has an announcement![/]', file=sys.stderr)
rprint('[bold cyan]----------[/]', file=sys.stderr)
rprint(f'[bold]{msg}[/]', file=sys.stderr)
rprint('[bold cyan]----------[/]', file=sys.stderr)
console = Console(stderr=True)
doc = Markdown(msg)
console.print(
Panel(
doc,
title="Server Announcement",
border_style=Style(color='cyan', bold=True),
width=min(console.size.width, 82),
),
)
_printed_announcement = True

last_state['hash'] = msg_hash
Expand Down

0 comments on commit fbc3c87

Please sign in to comment.