forked from bokeh/bokeh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
110 lines (76 loc) · 2.6 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -----------------------------------------------------------------------------
# Copyright (c) Anaconda, Inc., and Bokeh Contributors.
# All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# -----------------------------------------------------------------------------
"""
"""
from __future__ import annotations
# Standard library imports
import sys
from typing import Callable, Sequence
__all__ = (
"banner",
"failed",
"passed",
"shell",
"skipped",
)
ColorFunction = Callable[[str], str]
try:
import colorama # isort:skip
def bright(text: str) -> str:
return f"{colorama.Style.BRIGHT}{text}{colorama.Style.RESET_ALL}"
def dim(text: str) -> str:
return f"{colorama.Style.DIM}{text}{colorama.Style.RESET_ALL}"
def white(text: str) -> str:
return f"{colorama.Fore.WHITE}{text}{colorama.Style.RESET_ALL}"
def blue(text: str) -> str:
return f"{colorama.Fore.BLUE}{text}{colorama.Style.RESET_ALL}"
def red(text: str) -> str:
return f"{colorama.Fore.RED}{text}{colorama.Style.RESET_ALL}"
def green(text: str) -> str:
return f"{colorama.Fore.GREEN}{text}{colorama.Style.RESET_ALL}"
def yellow(text: str) -> str:
return f"{colorama.Fore.YELLOW}{text}{colorama.Style.RESET_ALL}"
if sys.platform == "win32":
colorama.init()
except ImportError:
def bright(text: str) -> str:
return text
def dim(text: str) -> str:
return text
def white(text: str) -> str:
return text
def blue(text: str) -> str:
return text
def red(text: str) -> str:
return text
def green(text: str) -> str:
return text
def yellow(text: str) -> str:
return text
def banner(color: ColorFunction, msg: str) -> str:
""""""
section = "=" * 80
header = f"{msg:^80}"
return f"\n{section}\n{header}\n{section}\n"
def _format_details(details: Sequence[str] | None = None) -> str:
if details:
return "\n" + "\n".join(f" {line}" for line in details)
return ""
def failed(msg: str, details: Sequence[str] | None = None) -> str:
""""""
return f"{red('[FAIL]')} {msg}" + _format_details(details)
def passed(msg: str, details: Sequence[str] | None = None) -> str:
""""""
return f"{dim(green('[PASS]'))} {msg}" + _format_details(details)
def shell(cmd: str) -> str:
return dim(white(f"+{cmd}"))
def skipped(msg: str, _details: Sequence[str] | None = None) -> str:
""""""
return f"{blue('[SKIP]')} {msg}"
def task(msg: str) -> str:
""""""
return f"\n------ {msg}"