1from . import utils
2
3
4FIELD_BY_MODE = {
5    "pid": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
6    "database": {
7        "default": "black_bold",
8        "cursor": "cyan_reverse",
9        "yellow": "yellow_bold",
10    },
11    "application_name": {
12        "default": "black_bold",
13        "cursor": "cyan_reverse",
14        "yellow": "yellow_bold",
15    },
16    "user": {
17        "default": "black_bold",
18        "cursor": "cyan_reverse",
19        "yellow": "yellow_bold",
20    },
21    "client": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
22    "cpu": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
23    "mem": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
24    "read": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
25    "write": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
26    "time_red": {"default": "red", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
27    "time_yellow": {
28        "default": "yellow",
29        "cursor": "cyan_reverse",
30        "yellow": "yellow_bold",
31    },
32    "time_green": {
33        "default": "green",
34        "cursor": "cyan_reverse",
35        "yellow": "yellow_bold",
36    },
37    "wait_green": {
38        "default": "green_bold",
39        "cursor": "cyan_reverse",
40        "yellow": "yellow_bold",
41    },
42    "wait_red": {
43        "default": "red_bold",
44        "cursor": "cyan_reverse",
45        "yellow": "yellow_bold",
46    },
47    "state_default": {
48        "default": "normal",
49        "cursor": "cyan_reverse",
50        "yellow": "yellow_bold",
51    },
52    "state_yellow": {
53        "default": "yellow",
54        "cursor": "cyan_reverse",
55        "yellow": "yellow_bold",
56    },
57    "state_green": {
58        "default": "green",
59        "cursor": "cyan_reverse",
60        "yellow": "yellow_bold",
61    },
62    "state_red": {"default": "red", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
63    "query": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
64    "relation": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
65    "type": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
66    "mode_yellow": {
67        "default": "yellow_bold",
68        "cursor": "cyan_reverse",
69        "yellow": "yellow_bold",
70    },
71    "mode_red": {
72        "default": "red_bold",
73        "cursor": "cyan_reverse",
74        "yellow": "yellow_bold",
75    },
76}
77
78
79def short_state(state: str) -> str:
80    state = utils.short_state(state)
81    if state == "active":
82        return "state_green"
83    elif state == "idle in trans":
84        return "state_yellow"
85    elif state == "idle in trans (a)":
86        return "state_red"
87    else:
88        return "state_default"
89
90
91def lock_mode(mode: str) -> str:
92    if mode in (
93        "ExclusiveLock",
94        "RowExclusiveLock",
95        "AccessExclusiveLock",
96    ):
97        return "mode_red"
98    else:
99        return "mode_yellow"
100
101
102def wait(value: bool) -> str:
103    return "wait_red" if value else "wait_green"
104