summaryrefslogtreecommitdiff
path: root/poezio
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-08-21 17:06:54 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit254b8953c4a63416a7d49088990bbd2768ca4ec6 (patch)
tree29db899f7e7fb87f1216d4b9a0cd41f22a653ed9 /poezio
parentaae00af2811e5d1229de1727717745e0dc242eab (diff)
downloadpoezio-254b8953c4a63416a7d49088990bbd2768ca4ec6.tar.gz
poezio-254b8953c4a63416a7d49088990bbd2768ca4ec6.tar.bz2
poezio-254b8953c4a63416a7d49088990bbd2768ca4ec6.tar.xz
poezio-254b8953c4a63416a7d49088990bbd2768ca4ec6.zip
Removed repetitive code.
Diffstat (limited to 'poezio')
-rw-r--r--poezio/tabs/basetabs.py3
-rw-r--r--poezio/text_buffer.py32
-rw-r--r--poezio/windows/text_win.py31
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