summaryrefslogtreecommitdiff
path: root/poezio/text_buffer.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2019-09-22 17:35:07 +0200
committermathieui <mathieui@mathieui.net>2020-05-09 19:46:17 +0200
commit41127e50abc3e126f953af5ad638f92d0848f9f1 (patch)
treeebc7c7a4557e1d005f2bf5a52b84f460342dca63 /poezio/text_buffer.py
parentd22b4b8c218cbbaee62002d751bd69bfe1d1deab (diff)
downloadpoezio-41127e50abc3e126f953af5ad638f92d0848f9f1.tar.gz
poezio-41127e50abc3e126f953af5ad638f92d0848f9f1.tar.bz2
poezio-41127e50abc3e126f953af5ad638f92d0848f9f1.tar.xz
poezio-41127e50abc3e126f953af5ad638f92d0848f9f1.zip
Move message rendering code to Message.render()
Also: - rename format_chars to FORMAT_CHARS because it’s static constant - move Line, Message, and a few funcs/consts to a new poezio.ui module
Diffstat (limited to 'poezio/text_buffer.py')
-rw-r--r--poezio/text_buffer.py86
1 files changed, 2 insertions, 84 deletions
diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py
index 2c0d192a..1667f0dc 100644
--- a/poezio/text_buffer.py
+++ b/poezio/text_buffer.py
@@ -14,90 +14,8 @@ log = logging.getLogger(__name__)
from typing import Dict, Union, Optional, List, Tuple
from datetime import datetime
from poezio.config import config
-from poezio.theming import get_theme, dump_tuple
-
-
-class Message:
- __slots__ = ('txt', 'nick_color', 'time', 'str_time', 'nickname', 'user',
- 'identifier', 'top', 'highlight', 'me', 'old_message', 'revisions',
- 'jid', 'ack')
-
- def __init__(self,
- txt: str,
- time: Optional[datetime],
- nickname: Optional[str],
- nick_color: Optional[Tuple],
- history: bool,
- user: Optional[str],
- identifier: Optional[str],
- top: Optional[bool] = False,
- str_time: Optional[str] = None,
- highlight: bool = False,
- old_message: Optional['Message'] = None,
- revisions: int = 0,
- jid: Optional[str] = None,
- ack: int = 0) -> None:
- """
- Create a new Message object with parameters, check for /me messages,
- and delayed messages
- """
- time = time if time is not None else datetime.now()
- if txt.startswith('/me '):
- me = True
- txt = '\x19%s}%s\x19o' % (dump_tuple(get_theme().COLOR_ME_MESSAGE),
- txt[4:])
- else:
- me = False
- str_time = time.strftime("%H:%M:%S")
- if history:
- txt = txt.replace(
- '\x19o',
- '\x19o\x19%s}' % dump_tuple(get_theme().COLOR_LOG_MSG))
- str_time = time.strftime("%Y-%m-%d %H:%M:%S")
-
- self.txt = txt.replace('\t', ' ') + '\x19o'
- self.nick_color = nick_color
- self.time = time
- self.str_time = str_time
- self.nickname = nickname
- self.user = user
- self.identifier = identifier
- self.top = top
- self.highlight = highlight
- self.me = me
- self.old_message = old_message
- self.revisions = revisions
- self.jid = jid
- self.ack = ack
-
- def _other_elems(self) -> str:
- "Helper for the repr_message function"
- acc = []
- fields = list(self.__slots__)
- fields.remove('old_message')
- for field in fields:
- acc.append('%s=%s' % (field, repr(getattr(self, field))))
- return 'Message(%s, %s' % (', '.join(acc), 'old_message=')
-
- def __repr__(self) -> str:
- """
- repr() for the Message class, for debug purposes, since the default
- repr() is recursive, so it can stack overflow given too many revisions
- of a message
- """
- init = self._other_elems()
- acc = [init]
- next_message = self.old_message
- rev = 1
- while next_message is not None:
- acc.append(next_message._other_elems())
- next_message = next_message.old_message
- rev += 1
- acc.append('None')
- while rev:
- acc.append(')')
- rev -= 1
- return ''.join(acc)
+from poezio.ui.types import Message
+
class CorrectionError(Exception):