summaryrefslogtreecommitdiff
path: root/poezio/ui
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2020-08-14 22:12:16 +0200
committerMaxime “pep” Buquet <pep@bouah.net>2020-08-14 22:12:26 +0200
commit03ef9c8d547872ae7aa87ecec4779bca49309225 (patch)
tree547dca2f342f7f102ec1f6e2d20776ce78bc1974 /poezio/ui
parent96f3bd72ac2704534388d993f644ec55abdf31b2 (diff)
downloadpoezio-03ef9c8d547872ae7aa87ecec4779bca49309225.tar.gz
poezio-03ef9c8d547872ae7aa87ecec4779bca49309225.tar.bz2
poezio-03ef9c8d547872ae7aa87ecec4779bca49309225.tar.xz
poezio-03ef9c8d547872ae7aa87ecec4779bca49309225.zip
move date and time SHORT_FORMAT and LONG_FORMAT to the theme
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'poezio/ui')
-rw-r--r--poezio/ui/consts.py8
-rw-r--r--poezio/ui/render.py7
-rw-r--r--poezio/ui/types.py15
3 files changed, 9 insertions, 21 deletions
diff --git a/poezio/ui/consts.py b/poezio/ui/consts.py
index 0838d953..51febf22 100644
--- a/poezio/ui/consts.py
+++ b/poezio/ui/consts.py
@@ -4,11 +4,3 @@ FORMAT_CHAR = '\x19'
# These are non-printable chars, so they should never appear in the input,
# I guess. But maybe we can find better chars that are even less risky.
FORMAT_CHARS = '\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x1A'
-
-# Short date format (only show time)
-SHORT_FORMAT = '%H:%M:%S'
-SHORT_FORMAT_LENGTH = len(datetime.now().strftime(SHORT_FORMAT))
-
-# Long date format (show date and time)
-LONG_FORMAT = '%Y-%m-%d %H:%M:%S'
-LONG_FORMAT_LENGTH = len(datetime.now().strftime(LONG_FORMAT))
diff --git a/poezio/ui/render.py b/poezio/ui/render.py
index 633ac2a0..f37ea39e 100644
--- a/poezio/ui/render.py
+++ b/poezio/ui/render.py
@@ -18,8 +18,6 @@ from poezio.theming import (
)
from poezio.ui.consts import (
FORMAT_CHAR,
- LONG_FORMAT,
- SHORT_FORMAT,
)
from poezio.ui.funcs import (
truncate_nick,
@@ -237,11 +235,12 @@ class PreMessageHelpers:
"""
Write the date on the yth line of the window
"""
+ theme = get_theme()
if time:
if history and time.date() != date.today():
- format = LONG_FORMAT
+ format = theme.LONG_TIME_FORMAT
else:
- format = SHORT_FORMAT
+ format = theme.SHORT_TIME_FORMAT
time_str = time.strftime(format)
color = get_theme().COLOR_TIME_STRING
with buffer.colored_text(color=color):
diff --git a/poezio/ui/types.py b/poezio/ui/types.py
index 15117275..e75f8eba 100644
--- a/poezio/ui/types.py
+++ b/poezio/ui/types.py
@@ -6,11 +6,6 @@ from poezio.ui.funcs import truncate_nick
from poezio import poopt
from poezio.user import User
from poezio.theming import dump_tuple, get_theme
-from poezio.ui.consts import (
- SHORT_FORMAT_LENGTH,
- LONG_FORMAT_LENGTH,
-)
-
class BaseMessage:
@@ -25,7 +20,8 @@ class BaseMessage:
self.time = datetime.now()
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
- return SHORT_FORMAT_LENGTH + 1
+ theme = get_theme()
+ return theme.SHORT_TIME_FORMAT_LENGTH + 1
class EndOfArchive(BaseMessage):
@@ -68,7 +64,7 @@ class XMLLog(BaseMessage):
offset = 0
theme = get_theme()
if with_timestamps:
- offset += 1 + SHORT_FORMAT_LENGTH
+ offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH
if self.incoming:
nick = theme.CHAR_XML_IN
else:
@@ -178,11 +174,12 @@ class Message(BaseMessage):
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
offset = 0
+ theme = get_theme()
if with_timestamps:
if self.history:
- offset += 1 + LONG_FORMAT_LENGTH
+ offset += 1 + theme.LONG_TIME_FORMAT_LENGTH
else:
- offset += 1 + SHORT_FORMAT_LENGTH
+ offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH
if not self.nickname: # not a message, nothing to do afterwards
return offset