summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2019-09-29 12:20:00 +0200
committermathieui <mathieui@mathieui.net>2020-05-09 19:46:17 +0200
commit5bc510eafa5d3e9c735687f0b8c9d446159fffca (patch)
treee00c4b890c0c7e09c32a227b14ae90c0869c6a38
parent32beeca48018422499b9c0af55a5c5b1eaa67d75 (diff)
downloadpoezio-5bc510eafa5d3e9c735687f0b8c9d446159fffca.tar.gz
poezio-5bc510eafa5d3e9c735687f0b8c9d446159fffca.tar.bz2
poezio-5bc510eafa5d3e9c735687f0b8c9d446159fffca.tar.xz
poezio-5bc510eafa5d3e9c735687f0b8c9d446159fffca.zip
Fix an issue in xmllog rendering due to wrong offset
and improve tests to catch that
-rw-r--r--poezio/ui/render.py4
-rw-r--r--poezio/ui/types.py5
-rw-r--r--test/test_ui/test_render.py38
3 files changed, 28 insertions, 19 deletions
diff --git a/poezio/ui/render.py b/poezio/ui/render.py
index 64b480a9..b695e8f3 100644
--- a/poezio/ui/render.py
+++ b/poezio/ui/render.py
@@ -100,7 +100,7 @@ def build_xmllog(msg: XMLLog, width: int, timestamp: bool, nick_size: int = 10)
def write_pre(msg: BaseMessage, win, with_timestamps: bool, nick_size: int) -> int:
"""Write the part before text (only the timestamp)"""
if with_timestamps:
- return 1 + PreMessageHelpers.write_time(win, False, msg.time)
+ return PreMessageHelpers.write_time(win, False, msg.time)
return 0
@@ -153,7 +153,7 @@ def write_pre_xmllog(msg: XMLLog, win, with_timestamps: bool, nick_size: int) ->
"""Write the part before the stanza (timestamp + IN/OUT)"""
offset = 0
if with_timestamps:
- offset += PreMessageHelpers.write_time(win, False, msg.time)
+ offset += 1 + PreMessageHelpers.write_time(win, False, msg.time)
theme = get_theme()
if msg.incoming:
char = theme.CHAR_XML_IN
diff --git a/poezio/ui/types.py b/poezio/ui/types.py
index 18e51427..6c744ac3 100644
--- a/poezio/ui/types.py
+++ b/poezio/ui/types.py
@@ -48,13 +48,12 @@ class XMLLog(BaseMessage):
def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
offset = 0
theme = get_theme()
- IN, OUT = theme.CHAR_XML_IN, theme.CHAR_XML_OUT
if with_timestamps:
offset += 1 + SHORT_FORMAT_LENGTH
if self.incoming:
- nick = IN
+ nick = theme.CHAR_XML_IN
else:
- nick = OUT
+ nick = theme.CHAR_XML_OUT
nick = truncate_nick(nick, nick_size) or ''
offset += 1 + len(nick)
return offset
diff --git a/test/test_ui/test_render.py b/test/test_ui/test_render.py
index ae32059e..d13751d1 100644
--- a/test/test_ui/test_render.py
+++ b/test/test_ui/test_render.py
@@ -51,74 +51,84 @@ def test_write_pre_basemsg(buffer):
str_time = '10:11:12'
time = datetime.strptime(str_time, '%H:%M:%S')
msg = BaseMessage(txt='coucou', time=time)
-
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 '
+ assert size == len(buffer.text)
def test_write_pre_message_simple(buffer, time):
msg = Message(txt='coucou', nickname='toto', time=time)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 toto> '
+ assert size == len(buffer.text)
def test_write_pre_message_simple_history(buffer, time):
msg = Message(txt='coucou', nickname='toto', time=time, history=True)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '2019-09-27 10:11:12 toto> '
+ assert size == len(buffer.text)
def test_write_pre_message_highlight(buffer, time):
msg = Message(txt='coucou', nickname='toto', time=time, highlight=True)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 toto> '
+ assert size == len(buffer.text)
def test_write_pre_message_no_timestamp(buffer):
msg = Message(txt='coucou', nickname='toto')
- write_pre(msg, buffer, False, 10)
+ size = write_pre(msg, buffer, False, 10)
assert buffer.text == 'toto> '
+ assert size == len(buffer.text)
def test_write_pre_message_me(buffer, time):
msg = Message(txt='/me coucou', nickname='toto', time=time)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 * toto '
+ assert size == len(buffer.text)
def test_write_pre_message_revisions(buffer, time):
msg = Message(txt='coucou', nickname='toto', time=time, revisions=5)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 toto5> '
-
+ assert size == len(buffer.text)
def test_write_pre_message_revisions_me(buffer, time):
msg = Message(txt='/me coucou', nickname='toto', time=time, revisions=5)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '10:11:12 * toto5 '
+ assert size == len(buffer.text)
def test_write_pre_message_ack(buffer, time):
ack = get_theme().CHAR_ACK_RECEIVED
expected = '10:11:12 %s toto> ' % ack
msg = Message(txt='coucou', nickname='toto', time=time, ack=1)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == expected
+ assert size == len(buffer.text)
def test_write_pre_message_nack(buffer, time):
nack = get_theme().CHAR_NACK
expected = '10:11:12 %s toto> ' % nack
msg = Message(txt='coucou', nickname='toto', time=time, ack=-1)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == expected
+ assert size == len(buffer.text)
def test_write_pre_xmllog_in(buffer):
msg = XMLLog(txt="coucou", incoming=True)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '%s IN ' % msg.time.strftime('%H:%M:%S')
+ assert size == len(buffer.text)
def test_write_pre_xmllog_out(buffer):
msg = XMLLog(txt="coucou", incoming=False)
- write_pre(msg, buffer, True, 10)
+ size = write_pre(msg, buffer, True, 10)
assert buffer.text == '%s OUT ' % msg.time.strftime('%H:%M:%S')
+ assert size == len(buffer.text)