mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
move some files around
This commit is contained in:
parent
c1b4d1bcd9
commit
15c0eea6fd
4 changed files with 107 additions and 95 deletions
11
jrnl/messages/Message.py
Normal file
11
jrnl/messages/Message.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from typing import NamedTuple
|
||||
from typing import Mapping
|
||||
|
||||
from .MsgText import MsgText
|
||||
from .MsgStyle import MsgStyle
|
||||
|
||||
|
||||
class Message(NamedTuple):
|
||||
text: MsgText
|
||||
style: MsgStyle = MsgStyle.NORMAL
|
||||
params: Mapping = {}
|
89
jrnl/messages/MsgStyle.py
Normal file
89
jrnl/messages/MsgStyle.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from enum import Enum
|
||||
from typing import NamedTuple
|
||||
from typing import Callable
|
||||
from rich.panel import Panel
|
||||
from rich import box
|
||||
|
||||
from .MsgText import MsgText
|
||||
|
||||
|
||||
class MsgStyle(Enum):
|
||||
class _Color(NamedTuple):
|
||||
"""
|
||||
String representing a standard color to display
|
||||
see: https://rich.readthedocs.io/en/stable/appendix/colors.html
|
||||
"""
|
||||
|
||||
color: str
|
||||
|
||||
class _Decoration(Enum):
|
||||
NONE = {
|
||||
"callback": lambda x, **_: x,
|
||||
"args": {},
|
||||
}
|
||||
BOX = {
|
||||
"callback": Panel,
|
||||
"args": {
|
||||
"expand": False,
|
||||
"padding": (0, 2),
|
||||
"title_align": "left",
|
||||
"box": box.HEAVY,
|
||||
},
|
||||
}
|
||||
|
||||
@property
|
||||
def callback(self) -> Callable:
|
||||
return self.value["callback"]
|
||||
|
||||
@property
|
||||
def args(self) -> dict:
|
||||
return self.value["args"]
|
||||
|
||||
PROMPT = {
|
||||
"decoration": _Decoration.NONE,
|
||||
"color": _Color("white"),
|
||||
"append_space": True,
|
||||
}
|
||||
TITLE = {
|
||||
"decoration": _Decoration.BOX,
|
||||
"color": _Color("cyan"),
|
||||
}
|
||||
NORMAL = {
|
||||
"decoration": _Decoration.BOX,
|
||||
"color": _Color("white"),
|
||||
}
|
||||
WARNING = {
|
||||
"decoration": _Decoration.BOX,
|
||||
"color": _Color("yellow"),
|
||||
}
|
||||
ERROR = {
|
||||
"decoration": _Decoration.BOX,
|
||||
"color": _Color("red"),
|
||||
"box_title": str(MsgText.Error),
|
||||
}
|
||||
ERROR_ON_NEW_LINE = {
|
||||
"decoration": _Decoration.BOX,
|
||||
"color": _Color("red"),
|
||||
"prepend_newline": True,
|
||||
"box_title": str(MsgText.Error),
|
||||
}
|
||||
|
||||
@property
|
||||
def decoration(self) -> _Decoration:
|
||||
return self.value["decoration"]
|
||||
|
||||
@property
|
||||
def color(self) -> _Color:
|
||||
return self.value["color"].color
|
||||
|
||||
@property
|
||||
def prepend_newline(self) -> bool:
|
||||
return self.value.get("prepend_newline", False)
|
||||
|
||||
@property
|
||||
def append_space(self) -> bool:
|
||||
return self.value.get("append_space", False)
|
||||
|
||||
@property
|
||||
def box_title(self) -> MsgText:
|
||||
return self.value.get("box_title", None)
|
|
@ -1,42 +1,4 @@
|
|||
from enum import Enum
|
||||
from typing import NamedTuple
|
||||
from typing import Mapping
|
||||
from typing import Callable
|
||||
from rich.panel import Panel
|
||||
from rich import box
|
||||
|
||||
|
||||
class _MsgColor(NamedTuple):
|
||||
"""
|
||||
String representing a standard color to display
|
||||
see: https://rich.readthedocs.io/en/stable/appendix/colors.html
|
||||
"""
|
||||
|
||||
color: str
|
||||
|
||||
|
||||
class MsgDecoration(Enum):
|
||||
NONE = {
|
||||
"callback": lambda x, **_: x,
|
||||
"args": {},
|
||||
}
|
||||
BOX = {
|
||||
"callback": Panel,
|
||||
"args": {
|
||||
"expand": False,
|
||||
"padding": (0, 2),
|
||||
"title_align": "left",
|
||||
"box": box.HEAVY,
|
||||
},
|
||||
}
|
||||
|
||||
@property
|
||||
def callback(self) -> Callable:
|
||||
return self.value["callback"]
|
||||
|
||||
@property
|
||||
def args(self) -> dict:
|
||||
return self.value["args"]
|
||||
|
||||
|
||||
class MsgText(Enum):
|
||||
|
@ -284,60 +246,3 @@ class MsgText(Enum):
|
|||
The command {old_cmd} is deprecated and will be removed from jrnl soon.
|
||||
Please use {new_cmd} instead.
|
||||
"""
|
||||
|
||||
|
||||
class MsgStyle(Enum):
|
||||
PROMPT = {
|
||||
"decoration": MsgDecoration.NONE,
|
||||
"color": _MsgColor("white"),
|
||||
"append_space": True,
|
||||
}
|
||||
TITLE = {
|
||||
"decoration": MsgDecoration.BOX,
|
||||
"color": _MsgColor("cyan"),
|
||||
}
|
||||
NORMAL = {
|
||||
"decoration": MsgDecoration.BOX,
|
||||
"color": _MsgColor("white"),
|
||||
}
|
||||
WARNING = {
|
||||
"decoration": MsgDecoration.BOX,
|
||||
"color": _MsgColor("yellow"),
|
||||
}
|
||||
ERROR = {
|
||||
"decoration": MsgDecoration.BOX,
|
||||
"color": _MsgColor("red"),
|
||||
"box_title": str(MsgText.Error),
|
||||
}
|
||||
ERROR_ON_NEW_LINE = {
|
||||
"decoration": MsgDecoration.BOX,
|
||||
"color": _MsgColor("red"),
|
||||
"prepend_newline": True,
|
||||
"box_title": str(MsgText.Error),
|
||||
}
|
||||
|
||||
@property
|
||||
def decoration(self) -> MsgDecoration:
|
||||
return self.value["decoration"]
|
||||
|
||||
@property
|
||||
def color(self) -> _MsgColor:
|
||||
return self.value["color"].color
|
||||
|
||||
@property
|
||||
def prepend_newline(self) -> bool:
|
||||
return self.value.get("prepend_newline", False)
|
||||
|
||||
@property
|
||||
def append_space(self) -> bool:
|
||||
return self.value.get("append_space", False)
|
||||
|
||||
@property
|
||||
def box_title(self) -> MsgText:
|
||||
return self.value.get("box_title", None)
|
||||
|
||||
|
||||
class Message(NamedTuple):
|
||||
text: MsgText
|
||||
style: MsgStyle = MsgStyle.NORMAL
|
||||
params: Mapping = {}
|
7
jrnl/messages/__init__.py
Normal file
7
jrnl/messages/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from .Message import Message
|
||||
from .MsgStyle import MsgStyle
|
||||
from .MsgText import MsgText
|
||||
|
||||
Message = Message
|
||||
MsgStyle = MsgStyle
|
||||
MsgText = MsgText
|
Loading…
Add table
Reference in a new issue