def draw(self, current: int, chats: List[Dict[str, Any]], title: str = "Chats") -> None: self.win.erase() line = curses.ACS_VLINE # type: ignore width = self.w - 1 self.win.vline(0, width, line, self.h) self.win.addstr(0, 0, title.center(width)[:width], get_color(cyan, -1) | bold) for i, chat in enumerate(chats, 1): is_selected = i == current + 1 date = get_date(chat) title = chat["title"] offset = 0 last_msg_sender, last_msg = self._get_last_msg_data(chat) sender_label = f" {last_msg_sender}" if last_msg_sender else "" flags = self._get_flags(chat) flags_len = string_len_dwc(flags) if flags: self.win.addstr( i, max(0, width - flags_len), truncate_to_len(flags, width)[-width:], # flags[-width:], self._unread_color(is_selected), ) for attr, elem in zip( self._chat_attributes(is_selected, title, last_msg_sender), [f"{date} ", title, sender_label, f" {last_msg}"], ): if not elem: continue item = truncate_to_len(elem, max(0, width - offset - flags_len)) if len(item) > 1: self.win.addstr(i, offset, item, attr) offset += string_len_dwc(elem) self._refresh()
def draw(self, current: int, chats: List[Dict[str, Any]]) -> None: self.win.erase() line = curses.ACS_VLINE # type: ignore self.win.vline(0, self.w - 1, line, self.h) for i, chat in enumerate(chats): is_selected = i == current unread_count = chat["unread_count"] if chat["is_marked_as_unread"]: unread_count = "unread" date = get_date(chat) title = chat["title"] is_pinned = chat["is_pinned"] last_msg = get_last_msg(chat) offset = 0 for attr, elem in zip( self._chat_attributes(is_selected), [f"{date} ", title] ): self.win.addstr( i, offset, truncate_to_len(elem, max(0, self.w - offset - 1)), attr, ) offset += len(elem) + sum( map(len, emoji_pattern.findall(elem)) ) last_msg = " " + last_msg.replace("\n", " ") last_msg = truncate_to_len(last_msg, max(0, self.w - offset)) if last_msg.strip(): self.win.addstr( i, offset, last_msg, self._msg_color(is_selected) ) if flags := self._get_flags(unread_count, is_pinned, chat): flags_len = len(flags) + sum( map(len, emoji_pattern.findall(flags)) ) self.win.addstr( i, self.w - flags_len - 1, flags, self._unread_color(is_selected), )