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/tabs/basetabs.py | 3 +-- poezio/text_buffer.py | 32 +++++++++++--------------------- poezio/windows/text_win.py | 31 +++++++++---------------------- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index f7812060..e7a49073 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -16,8 +16,7 @@ revolving around chats. import logging import string import time -import asyncio -from datetime import datetime, timedelta +from datetime import datetime from xml.etree import cElementTree as ET from typing import Any, Callable, Dict, List, Optional, Union diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py index 3d1f8266..eeb83be4 100644 --- a/poezio/text_buffer.py +++ b/poezio/text_buffer.py @@ -169,27 +169,17 @@ class TextBuffer: nick_size = config.get('max_nick_length') for window in self._windows: # make the associated windows # build the lines from the new message - if top: - nb = window.build_message_at_the_top( - msg, - history=history, - timestamp=show_timestamps, - nick_size=nick_size) - if ret_val == 0: - ret_val = nb - if window.pos != 0: - window.scroll_up(nb) - else: - nb = window.build_new_message( - msg, - history=history, - highlight=highlight, - timestamp=show_timestamps, - nick_size=nick_size) - if ret_val == 0: - ret_val = nb - if window.pos != 0: - window.scroll_up(nb) + 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 + if window.pos != 0: + window.scroll_up(nb) return min(ret_val, 1) 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