-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.mojo
64 lines (54 loc) · 2.31 KB
/
style.mojo
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
from collections.dict import Dict, KeyElement, DictEntry
from external.mist import TerminalStyle, Profile, TRUE_COLOR
from .base import StringKey, FATAL, INFO, DEBUG, WARN, ERROR
alias Sections = Dict[StringKey, TerminalStyle]
# TODO: For now setting profile each time, it doesn't seem like os.getenv works at comp time?
@value
struct Styles:
var timestamp: TerminalStyle
var message: TerminalStyle
var key: TerminalStyle
var value: TerminalStyle
var separator: TerminalStyle
var levels: Dict[StringKey, TerminalStyle]
var keys: Dict[StringKey, TerminalStyle]
var values: Dict[StringKey, TerminalStyle]
fn __init__(
inout self,
*,
timestamp: TerminalStyle = TerminalStyle.new(Profile(TRUE_COLOR)),
message: TerminalStyle = TerminalStyle.new(Profile(TRUE_COLOR)),
key: TerminalStyle = TerminalStyle.new(Profile(TRUE_COLOR)),
value: TerminalStyle = TerminalStyle.new(Profile(TRUE_COLOR)),
separator: TerminalStyle = TerminalStyle.new(Profile(TRUE_COLOR)),
levels: Dict[StringKey, TerminalStyle] = Dict[StringKey, TerminalStyle](),
keys: Dict[StringKey, TerminalStyle] = Dict[StringKey, TerminalStyle](),
values: Dict[StringKey, TerminalStyle] = Dict[StringKey, TerminalStyle](),
):
self.timestamp = timestamp
self.message = message
self.key = key
self.value = value
self.separator = separator
self.levels = levels
self.keys = keys
self.values = values
fn get_default_styles() -> Styles:
# Log level styles, by default just set colors
var levels = Sections()
levels["FATAL"] = TerminalStyle.new().foreground("#d4317d")
levels["ERROR"] = TerminalStyle.new().foreground("#d48244")
levels["INFO"] = TerminalStyle.new().foreground("#13ed84")
levels["WARN"] = TerminalStyle.new().foreground("#decf2f")
levels["DEBUG"] = TerminalStyle.new().foreground("#bd37db")
return Styles(
timestamp=TerminalStyle.new(),
message=TerminalStyle.new(),
key=TerminalStyle.new().faint(),
value=TerminalStyle.new(),
separator=TerminalStyle.new().faint(),
levels=levels,
keys=Dict[StringKey, TerminalStyle](),
values=Dict[StringKey, TerminalStyle](),
)
alias DEFAULT_STYLES = get_default_styles()