This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathnotice.py
68 lines (57 loc) · 1.81 KB
/
notice.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
# -*- coding: utf-8 -*-
"""
Notices during runtime.
:copyright: 2015-22 Agile Scientific
:license: Apache 2.0
"""
class Notice(object):
"""
Helper class to make printout more readable.
"""
styles = {'HEADER': '\033[95m',
'INFO': '\033[94m', # blue
'OK': '\033[92m', # green
'WARNING': '\033[93m', # red
'FAIL': '\033[91m',
'BOLD': '\033[1m'
}
ENDC = '\033[0m'
def __init__(self, string, style, hold=False):
string = self.styles[style.upper()] + string + self.ENDC
end = '' if hold else '\n'
print(string, end=end)
@classmethod
def title(cls):
"""Makes a logo."""
logo = """
Welcome to
┌─┐┌─┐┬┌─┐┌─┐┬ ┌─┐┌┬┐
└─┐├┤ │└─┐├─┘│ │ │ │
└─┘└─┘┴└─┘┴ ┴─┘└─┘ ┴
Good luck"""
return cls(logo, 'FAIL')
@classmethod
def warning(cls, string, hold=False):
"""Yellow."""
return cls(string, 'WARNING', hold=hold)
@classmethod
def fail(cls, string, hold=False):
"""Red."""
return cls(string, 'FAIL', hold=hold)
@classmethod
def header(cls, string, hold=False):
"""Pink."""
return cls('\n'+string+'\n', 'HEADER', hold=hold)
@classmethod
def hr_header(cls, string, hold=False):
"""Pink."""
hr = "\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
return cls(hr+string.upper(), 'HEADER', hold=hold)
@classmethod
def info(cls, string, hold=False):
"""Blue."""
return cls(string, 'INFO', hold=hold)
@classmethod
def ok(cls, string, hold=False):
"""Green."""
return cls(string, 'OK', hold=hold)