Create palette from config and add default config
This commit is contained in:
parent
5cfdb8f8e2
commit
bc203aaff1
3 changed files with 58 additions and 13 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from .palette import *
|
|
||||||
from .single_room_application import *
|
from .single_room_application import *
|
||||||
|
from .util import *
|
||||||
|
|
||||||
__all__: List[str] = []
|
__all__: List[str] = []
|
||||||
__all__ += palette.__all__
|
|
||||||
__all__ += single_room_application.__all__
|
__all__ += single_room_application.__all__
|
||||||
|
__all__ += util.__all__
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import enum
|
|
||||||
|
|
||||||
__all__ = ["Style", "PALETTE"]
|
|
||||||
|
|
||||||
@enum.unique
|
|
||||||
class Style(enum.Enum):
|
|
||||||
ROOM = "room"
|
|
||||||
|
|
||||||
PALETTE = [
|
|
||||||
(Style.ROOM, "light blue,bold", ""),
|
|
||||||
]
|
|
||||||
56
cheuph/euphoria/util.py
Normal file
56
cheuph/euphoria/util.py
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
|
from ..config import Config
|
||||||
|
|
||||||
|
__all__ = ["UtilException","Palette", "palette_from_config", "DEFAULT_CONFIG"]
|
||||||
|
|
||||||
|
class UtilException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
Palette = List[Union[Tuple[str, str], Tuple[str, str, str],
|
||||||
|
Tuple[str, str, str, str]]]
|
||||||
|
|
||||||
|
def palette_from_config(conf: Config) -> Palette:
|
||||||
|
palette: Palette = []
|
||||||
|
|
||||||
|
styles = conf.tree["style"]
|
||||||
|
for style, info in styles.items():
|
||||||
|
# First, do the alias stuff
|
||||||
|
alias = info.get("alias")
|
||||||
|
if isinstance(alias, str):
|
||||||
|
if alias in styles:
|
||||||
|
palette.append((style, alias))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise UtilException((f"style.{style}.alias must be the name of"
|
||||||
|
" another style"))
|
||||||
|
elif alias is not None:
|
||||||
|
raise UtilException(f"style.{style}.alias must be a string")
|
||||||
|
|
||||||
|
# Foreground/background
|
||||||
|
fg = info.get("fg")
|
||||||
|
bg = info.get("bg")
|
||||||
|
|
||||||
|
if not isinstance(fg, str) and fg is not None:
|
||||||
|
raise TypeError(f"style.{style}.fg must be a string")
|
||||||
|
|
||||||
|
if not isinstance(bg, str) and bg is not None:
|
||||||
|
raise TypeError(f"style.{style}.bg must be a string")
|
||||||
|
|
||||||
|
fg = fg or ""
|
||||||
|
bg = bg or ""
|
||||||
|
|
||||||
|
palette.append((style, fg, bg))
|
||||||
|
|
||||||
|
return palette
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = {
|
||||||
|
"element": {
|
||||||
|
"room": "room",
|
||||||
|
},
|
||||||
|
"style": {
|
||||||
|
"room": {
|
||||||
|
"fg": "light blue, bold",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue