move date and time SHORT_FORMAT and LONG_FORMAT to the theme
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
96f3bd72ac
commit
03ef9c8d54
7 changed files with 23 additions and 26 deletions
|
@ -26,7 +26,7 @@ from poezio.plugin import BasePlugin
|
||||||
from poezio.common import shell_split
|
from poezio.common import shell_split
|
||||||
from poezio import tabs
|
from poezio import tabs
|
||||||
from poezio.ui.types import Message
|
from poezio.ui.types import Message
|
||||||
from poezio.ui.consts import SHORT_FORMAT
|
from poezio.theming import get_theme
|
||||||
|
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
|
@ -56,6 +56,7 @@ class Plugin(BasePlugin):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def command_display_corrections(self, args):
|
def command_display_corrections(self, args):
|
||||||
|
theme = get_theme()
|
||||||
args = shell_split(args)
|
args = shell_split(args)
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +69,7 @@ class Plugin(BasePlugin):
|
||||||
if message:
|
if message:
|
||||||
display = []
|
display = []
|
||||||
while message:
|
while message:
|
||||||
str_time = message.time.strftime(SHORT_FORMAT)
|
str_time = message.time.strftime(theme.SHORT_TIME_FORMAT)
|
||||||
display.append('%s %s%s%s %s' %
|
display.append('%s %s%s%s %s' %
|
||||||
(str_time, '* '
|
(str_time, '* '
|
||||||
if message.me else '', message.nickname, ''
|
if message.me else '', message.nickname, ''
|
||||||
|
|
|
@ -46,7 +46,6 @@ from poezio.logger import logger
|
||||||
from poezio.text_buffer import TextBuffer
|
from poezio.text_buffer import TextBuffer
|
||||||
from poezio.theming import get_theme, dump_tuple
|
from poezio.theming import get_theme, dump_tuple
|
||||||
from poezio.ui.funcs import truncate_nick
|
from poezio.ui.funcs import truncate_nick
|
||||||
from poezio.ui.consts import LONG_FORMAT_LENGTH
|
|
||||||
from poezio.ui.types import BaseMessage, InfoMessage, Message
|
from poezio.ui.types import BaseMessage, InfoMessage, Message
|
||||||
|
|
||||||
from slixmpp import JID, InvalidJID, Message as SMessage
|
from slixmpp import JID, InvalidJID, Message as SMessage
|
||||||
|
@ -802,6 +801,7 @@ class ChatTab(Tab):
|
||||||
message_count = 0
|
message_count = 0
|
||||||
timestamp = config.get('show_timestamps')
|
timestamp = config.get('show_timestamps')
|
||||||
nick_size = config.get('max_nick_length')
|
nick_size = config.get('max_nick_length')
|
||||||
|
theme = get_theme()
|
||||||
for message in text_buffer.messages:
|
for message in text_buffer.messages:
|
||||||
# Build lines of a message
|
# Build lines of a message
|
||||||
txt = message.txt
|
txt = message.txt
|
||||||
|
@ -821,7 +821,7 @@ class ChatTab(Tab):
|
||||||
offset += 1
|
offset += 1
|
||||||
if timestamp:
|
if timestamp:
|
||||||
if message.history:
|
if message.history:
|
||||||
offset += 1 + LONG_FORMAT_LENGTH
|
offset += 1 + theme.LONG_TIME_FORMAT_LENGTH
|
||||||
lines = poopt.cut_text(txt, self.text_win.width - offset - 1)
|
lines = poopt.cut_text(txt, self.text_win.width - offset - 1)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
built_lines.append(line)
|
built_lines.append(line)
|
||||||
|
|
|
@ -78,6 +78,7 @@ from typing import Dict, List, Union, Tuple, Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os import path
|
from os import path
|
||||||
from poezio import colors, xdg
|
from poezio import colors, xdg
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from importlib import machinery
|
from importlib import machinery
|
||||||
finder = machinery.PathFinder()
|
finder = machinery.PathFinder()
|
||||||
|
@ -143,6 +144,14 @@ class Theme:
|
||||||
return sub_mapping[sub] if sub == keep else ''
|
return sub_mapping[sub] if sub == keep else ''
|
||||||
return sub_mapping.get(sub, '')
|
return sub_mapping.get(sub, '')
|
||||||
|
|
||||||
|
# Short date format (only show time)
|
||||||
|
SHORT_TIME_FORMAT = '%H:%M:%S'
|
||||||
|
SHORT_TIME_FORMAT_LENGTH = len(datetime.now().strftime(SHORT_TIME_FORMAT))
|
||||||
|
|
||||||
|
# Long date format (show date and time)
|
||||||
|
LONG_TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
||||||
|
LONG_TIME_FORMAT_LENGTH = len(datetime.now().strftime(LONG_TIME_FORMAT))
|
||||||
|
|
||||||
# Message text color
|
# Message text color
|
||||||
COLOR_NORMAL_TEXT = (-1, -1)
|
COLOR_NORMAL_TEXT = (-1, -1)
|
||||||
COLOR_INFORMATION_TEXT = (5, -1) # TODO
|
COLOR_INFORMATION_TEXT = (5, -1) # TODO
|
||||||
|
|
|
@ -4,11 +4,3 @@ FORMAT_CHAR = '\x19'
|
||||||
# These are non-printable chars, so they should never appear in the input,
|
# 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.
|
# 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'
|
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))
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ from poezio.theming import (
|
||||||
)
|
)
|
||||||
from poezio.ui.consts import (
|
from poezio.ui.consts import (
|
||||||
FORMAT_CHAR,
|
FORMAT_CHAR,
|
||||||
LONG_FORMAT,
|
|
||||||
SHORT_FORMAT,
|
|
||||||
)
|
)
|
||||||
from poezio.ui.funcs import (
|
from poezio.ui.funcs import (
|
||||||
truncate_nick,
|
truncate_nick,
|
||||||
|
@ -237,11 +235,12 @@ class PreMessageHelpers:
|
||||||
"""
|
"""
|
||||||
Write the date on the yth line of the window
|
Write the date on the yth line of the window
|
||||||
"""
|
"""
|
||||||
|
theme = get_theme()
|
||||||
if time:
|
if time:
|
||||||
if history and time.date() != date.today():
|
if history and time.date() != date.today():
|
||||||
format = LONG_FORMAT
|
format = theme.LONG_TIME_FORMAT
|
||||||
else:
|
else:
|
||||||
format = SHORT_FORMAT
|
format = theme.SHORT_TIME_FORMAT
|
||||||
time_str = time.strftime(format)
|
time_str = time.strftime(format)
|
||||||
color = get_theme().COLOR_TIME_STRING
|
color = get_theme().COLOR_TIME_STRING
|
||||||
with buffer.colored_text(color=color):
|
with buffer.colored_text(color=color):
|
||||||
|
|
|
@ -6,11 +6,6 @@ from poezio.ui.funcs import truncate_nick
|
||||||
from poezio import poopt
|
from poezio import poopt
|
||||||
from poezio.user import User
|
from poezio.user import User
|
||||||
from poezio.theming import dump_tuple, get_theme
|
from poezio.theming import dump_tuple, get_theme
|
||||||
from poezio.ui.consts import (
|
|
||||||
SHORT_FORMAT_LENGTH,
|
|
||||||
LONG_FORMAT_LENGTH,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseMessage:
|
class BaseMessage:
|
||||||
|
@ -25,7 +20,8 @@ class BaseMessage:
|
||||||
self.time = datetime.now()
|
self.time = datetime.now()
|
||||||
|
|
||||||
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
|
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):
|
class EndOfArchive(BaseMessage):
|
||||||
|
@ -68,7 +64,7 @@ class XMLLog(BaseMessage):
|
||||||
offset = 0
|
offset = 0
|
||||||
theme = get_theme()
|
theme = get_theme()
|
||||||
if with_timestamps:
|
if with_timestamps:
|
||||||
offset += 1 + SHORT_FORMAT_LENGTH
|
offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH
|
||||||
if self.incoming:
|
if self.incoming:
|
||||||
nick = theme.CHAR_XML_IN
|
nick = theme.CHAR_XML_IN
|
||||||
else:
|
else:
|
||||||
|
@ -178,11 +174,12 @@ class Message(BaseMessage):
|
||||||
|
|
||||||
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
|
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
|
||||||
offset = 0
|
offset = 0
|
||||||
|
theme = get_theme()
|
||||||
if with_timestamps:
|
if with_timestamps:
|
||||||
if self.history:
|
if self.history:
|
||||||
offset += 1 + LONG_FORMAT_LENGTH
|
offset += 1 + theme.LONG_TIME_FORMAT_LENGTH
|
||||||
else:
|
else:
|
||||||
offset += 1 + SHORT_FORMAT_LENGTH
|
offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH
|
||||||
|
|
||||||
if not self.nickname: # not a message, nothing to do afterwards
|
if not self.nickname: # not a message, nothing to do afterwards
|
||||||
return offset
|
return offset
|
||||||
|
|
|
@ -3,7 +3,6 @@ from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from poezio.theming import get_theme
|
from poezio.theming import get_theme
|
||||||
from poezio.ui.render import build_lines, Line, write_pre
|
from poezio.ui.render import build_lines, Line, write_pre
|
||||||
from poezio.ui.consts import SHORT_FORMAT
|
|
||||||
from poezio.ui.types import BaseMessage, Message, StatusMessage, XMLLog
|
from poezio.ui.types import BaseMessage, Message, StatusMessage, XMLLog
|
||||||
|
|
||||||
def test_simple_build_basemsg():
|
def test_simple_build_basemsg():
|
||||||
|
|
Loading…
Reference in a new issue