2021-10-18 09:43:40 +00:00
|
|
|
import os
|
|
|
|
|
2019-01-22 20:25:04 +00:00
|
|
|
import click
|
|
|
|
|
2020-01-16 10:52:53 +00:00
|
|
|
STDOUT = None
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def title(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
indent = 8
|
|
|
|
separator = "=" * (len(text) + 2 * indent)
|
|
|
|
message = "{separator}\n{indent}{text}\n{separator}".format(
|
2019-05-05 09:45:24 +00:00
|
|
|
separator=separator, indent=" " * indent, text=text
|
2019-01-22 20:25:04 +00:00
|
|
|
)
|
|
|
|
return click.style(message, fg="green")
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def echo_info(text: str) -> None:
|
2019-05-11 22:10:14 +00:00
|
|
|
echo(info(text))
|
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def info(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
return click.style(text, fg="blue")
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def error(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
return click.style(text, fg="red")
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def echo_error(text: str) -> None:
|
2019-05-11 22:10:14 +00:00
|
|
|
echo(error(text), err=True)
|
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def command(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
return click.style(text, fg="magenta")
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def question(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
return click.style(text, fg="yellow")
|
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def echo_alert(text: str) -> None:
|
2021-02-05 14:42:46 +00:00
|
|
|
echo_error(alert(text))
|
2019-05-11 22:10:14 +00:00
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def alert(text: str) -> str:
|
2019-01-22 20:25:04 +00:00
|
|
|
return click.style("⚠️ " + text, fg="yellow", bold=True)
|
2019-05-11 22:10:14 +00:00
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def echo(text: str, err: bool = False) -> None:
|
2021-10-18 09:43:40 +00:00
|
|
|
if os.environ.get("_TUTOR_COMPLETE"):
|
|
|
|
if os.environ.get("COMP_WORDS") or os.environ.get("COMP_CWORD"):
|
|
|
|
# Don't even attempt to log stuff when we are actually auto-completing shell commands.
|
|
|
|
return
|
2020-01-16 10:52:53 +00:00
|
|
|
click.echo(text, file=STDOUT, err=err)
|