summaryrefslogtreecommitdiff
path: root/poezio/text_buffer.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2019-09-29 18:12:48 +0200
committermathieui <mathieui@mathieui.net>2020-05-09 19:46:17 +0200
commita5e92800477f6195a6b2e8c6e64a56859117d5b8 (patch)
treef53550024091a12deeee88c0d9897d0aeba9f4bf /poezio/text_buffer.py
parentfefbb0b08887b761ad7a1cf95cf6b9f5f30013a6 (diff)
downloadpoezio-a5e92800477f6195a6b2e8c6e64a56859117d5b8.tar.gz
poezio-a5e92800477f6195a6b2e8c6e64a56859117d5b8.tar.bz2
poezio-a5e92800477f6195a6b2e8c6e64a56859117d5b8.tar.xz
poezio-a5e92800477f6195a6b2e8c6e64a56859117d5b8.zip
Pass a message to add_message instead of messed up kwargs everywhere
Changes LOTS of things
Diffstat (limited to 'poezio/text_buffer.py')
-rw-r--r--poezio/text_buffer.py35
1 files changed, 5 insertions, 30 deletions
diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py
index c03f84f5..3c8d78ba 100644
--- a/poezio/text_buffer.py
+++ b/poezio/text_buffer.py
@@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
from typing import Dict, Union, Optional, List, Tuple
from datetime import datetime
from poezio.config import config
-from poezio.ui.types import Message
+from poezio.ui.types import Message, BaseMessage
@@ -38,7 +38,7 @@ class TextBuffer:
messages_nb_limit = config.get('max_messages_in_memory')
self._messages_nb_limit = messages_nb_limit # type: int
# Message objects
- self.messages = [] # type: List[Message]
+ self.messages = [] # type: List[BaseMessage]
# COMPAT: Correction id -> Original message id.
self.correction_ids = {} # type: Dict[str, str]
# we keep track of one or more windows
@@ -53,33 +53,10 @@ class TextBuffer:
def last_message(self) -> Optional[Message]:
return self.messages[-1] if self.messages else None
- def add_message(self,
- txt: str,
- time: Optional[datetime] = None,
- nickname: Optional[str] = None,
- nick_color: Optional[Tuple] = None,
- history: bool = False,
- user: Optional[str] = None,
- highlight: bool = False,
- top: Optional[bool] = False,
- identifier: Optional[str] = None,
- jid: Optional[str] = None,
- ack: int = 0) -> int:
+ def add_message(self, msg: BaseMessage):
"""
Create a message and add it to the text buffer
"""
- msg = Message(
- txt,
- time=time,
- nickname=nickname,
- nick_color=nick_color,
- history=history,
- user=user,
- identifier=identifier,
- top=top,
- highlight=highlight,
- jid=jid,
- ack=ack)
self.messages.append(msg)
while len(self.messages) > self._messages_nb_limit:
@@ -92,13 +69,11 @@ class TextBuffer:
# build the lines from the new message
nb = window.build_new_message(
msg,
- history=history,
- highlight=highlight,
timestamp=show_timestamps,
- top=top,
nick_size=nick_size)
if ret_val == 0:
ret_val = nb
+ top = isinstance(msg, Message) and msg.top
if window.pos != 0 and top is False:
window.scroll_up(nb)
@@ -156,7 +131,7 @@ class TextBuffer:
highlight: bool = False,
time: Optional[datetime] = None,
user: Optional[str] = None,
- jid: Optional[str] = None):
+ jid: Optional[str] = None) -> Message:
"""
Correct a message in a text buffer.