-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35ca6ef
commit 2c1dbe9
Showing
1 changed file
with
29 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
from typing import Any | ||
from typing import Dict | ||
from typing import List | ||
from typing import Optional | ||
|
||
from rich.prompt import Prompt | ||
from rich.status import Status | ||
from rich.console import Console | ||
|
||
from .misc import shallow_copy_dict | ||
|
||
|
||
_console = Console() | ||
|
||
|
||
def deprecate(msg: str) -> None: | ||
_console.print(f"[yellow]DeprecationWarning: {msg}[/yellow]") | ||
def log(msg: str, *args: Any, **kwargs: Any) -> None: | ||
_console.log(msg, *args, **kwargs) | ||
|
||
|
||
def debug(msg: str, *args: Any, prefix: str = "", **kwargs: Any) -> None: | ||
log(f"[grey42]{prefix}{msg}[/grey42]", *args, **kwargs) | ||
|
||
|
||
def warn(msg: str, *args: Any, prefix: str = "Warning: ", **kwargs: Any) -> None: | ||
log(f"[yellow]{prefix}{msg}[/yellow]", *args, **kwargs) | ||
|
||
|
||
def deprecated(msg: str, *args: Any, **kwargs: Any) -> None: | ||
warn(msg, *args, prefix="DeprecationWarning: ", **kwargs) | ||
|
||
|
||
def log(msg: str) -> None: | ||
_console.log(msg) | ||
def error(msg: str, *args: Any, prefix: str = "Error: ", **kwargs: Any) -> None: | ||
log(f"[red]{prefix}{msg}[/red]", *args, **kwargs) | ||
|
||
|
||
def print(msg: str) -> None: | ||
_console.print(msg) | ||
def print(msg: str, *args: Any, **kwargs: Any) -> None: | ||
_console.print(msg, *args, **kwargs) | ||
|
||
|
||
def rule(title: str) -> None: | ||
_console.rule(title) | ||
def rule(title: str, **kwargs: Any) -> None: | ||
_console.rule(title, **kwargs) | ||
|
||
|
||
def ask( | ||
question: str, | ||
choices: Optional[List[str]] = None, | ||
*, | ||
default: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> str: | ||
kw: Dict[str, Any] = dict(choices=choices) | ||
kwargs = shallow_copy_dict(kwargs) | ||
kwargs["choices"] = choices | ||
if default is not None: | ||
kw["default"] = default | ||
return Prompt.ask(question, **kw) # type: ignore | ||
kwargs["default"] = default | ||
return Prompt.ask(question, **kwargs) | ||
|
||
|
||
def status(msg: str) -> Status: | ||
return _console.status(msg) | ||
def status(msg: str, **kwargs: Any) -> Status: | ||
return _console.status(msg, **kwargs) |