Removed repetitive code.
This commit is contained in:
parent
aae00af281
commit
254b8953c4
3 changed files with 21 additions and 45 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue