From 254b8953c4a63416a7d49088990bbd2768ca4ec6 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Wed, 21 Aug 2019 17:06:54 +0530 Subject: Removed repetitive code. --- poezio/windows/text_win.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'poezio/windows') diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py index 44a70953..8a55338a 100644 --- a/poezio/windows/text_win.py +++ b/poezio/windows/text_win.py @@ -316,6 +316,7 @@ class TextWin(BaseTextWin): clean: bool = True, highlight: bool = False, timestamp: bool = False, + top: Optional[bool] = False, nick_size: int = 10) -> int: """ Take one message, build it and add it to the list @@ -324,10 +325,15 @@ class TextWin(BaseTextWin): """ lines = self.build_message( message, timestamp=timestamp, nick_size=nick_size) - if self.lock: - self.lock_buffer.extend(lines) + if top: + lines.reverse() + for line in lines: + self.built_lines.insert(0, line) else: - self.built_lines.extend(lines) + if self.lock: + self.lock_buffer.extend(lines) + else: + self.built_lines.extend(lines) if not lines or not lines[0]: return 0 if highlight: @@ -340,25 +346,6 @@ class TextWin(BaseTextWin): self.built_lines.pop(0) return len(lines) - def build_message_at_the_top(self, - message: Message, - history=None, - timestamp: bool = False, - nick_size: int = 10) -> int: - """ - Take one message, build it and add it to the top of the list. - Return the number of lines that are built for the given - message. - """ - lines = self.build_message( - message, timestamp=timestamp, nick_size=nick_size) - lines.reverse() - for line in lines: - self.built_lines.insert(0, line) - if not lines or not lines[0]: - return 0 - return len(lines) - def build_message(self, message: Optional[Message], timestamp: bool = False, nick_size: int = 10) -> List[Union[None, Line]]: """ Build a list of lines from a message, without adding it -- cgit v1.2.3