onaplogging: Docstrings, refactor, type hinting
[logging-analytics.git] / pylog / onaplogging / utils / styles.py
1 # Copyright (c) 2020 Deutsche Telekom.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
11 """These are ANSI shell coloring codes used to format strings.
12
13 [ begins the color definition. \033 starts the escape sequence.
14 [\0330m is the default color of the shell that closes the escape sequence.
15
16 `FMT_STR` takes the color as its first parameter (int). As the second
17 parameter its takes the text (str).
18
19 TL;DR
20     Examples on ANSI colors, attributes, backgrounds and foregrounds:
21     https://stackoverflow.com/a/28938235/7619961
22 """
23
24 COLOR_TAG = "color"
25 HIGHLIGHT_TAG = "highlight"
26 ATTRIBUTE_TAG = "attribute"
27
28 RESET = "\033[0m"
29 FMT_STR = "\033[%dm%s"
30
31 ATTRIBUTES = {
32
33     'normal': 0,
34     'bold': 1,
35     'underline': 4,
36     'blink': 5,
37     'invert': 7,
38     'hide': 8,
39
40 }
41
42 HIGHLIGHTS = {
43
44     'black': 40,
45     'red': 41,
46     'green': 42,
47     'yellow': 43,
48     'blue': 44,
49     'purple': 45,
50     'cyan': 46,
51     'white': 47,
52
53 }
54
55 COLORS = {
56
57     'black': 30,
58     'red': 31,
59     'green': 32,
60     'yellow': 33,
61     'blue': 34,
62     'purple': 35,
63     'cyan': 36,
64     'white': 37,
65
66 }
67
68 """
69 MDC and MARKER options are used only with Python starting 3.2 due to an update
70 in the logging module. This allows the use of %-formatting, :meth:`str.format`
71 (``{}``) formatting or :class:`string.Template` in the format string.
72 """
73
74 MARKER_OPTIONS = {
75     "%": "%(marker)s",
76     "{": "{marker}",
77     "$": "${marker}"
78 }
79
80 MDC_OPTIONS = {
81     "%": "%(mdc)s",
82     "{": "{mdc}",
83     "$": "${mdc}"
84 }