-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption_formatting.py
65 lines (49 loc) · 1.73 KB
/
option_formatting.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
from typing import overload
from mods_base import JSON, BaseOption, BoolOption, KeybindOption, ValueOption
from .draw import draw, draw_description
from .screens import draw_stack_header
@overload
def get_option_value_str[J: JSON](option: ValueOption[J]) -> str: ...
@overload
def get_option_value_str(option: BaseOption) -> str | None: ...
def get_option_value_str(option: BaseOption) -> str | None:
"""
Gets the string to use for the option's value.
Args:
option: The option to get the value string of.
Returns:
The option's value string, or None if it doesn't have a value.
"""
match option:
case BoolOption():
return (option.false_text or "Off", option.true_text or "On")[option.value]
case KeybindOption():
key = str(option.value)
if option.value is None:
key = "Unbound"
if option.is_rebindable:
return key
return f"Locked: {key}"
case ValueOption():
# The generics mean the type of value is technically unknown here
return str(option.value) # type: ignore
case _:
return None
def draw_option_header(option: BaseOption) -> None:
"""
Draws the header for a particular option.
Args:
option: The option to draw the header for.
"""
draw_stack_header()
title = option.display_name
value_str = get_option_value_str(option)
if value_str is not None:
title += f" ({value_str})"
draw(title)
if option.description_title != option.display_name:
draw(option.description_title)
if len(option.description) > 0:
draw("=" * 32)
draw_description(option.description)
draw("")