示例#1
0
 def build_message(self, message, timestamp=False, nick_size=10):
     txt = message.txt
     ret = []
     default_color = None
     nick = truncate_nick(message.nickname, nick_size)
     offset = 0
     if nick:
         offset += poopt.wcswidth(nick) + 1 # + nick + ' ' length
     if message.str_time:
         offset += 1 + len(message.str_time)
     if get_theme().CHAR_TIME_LEFT and message.str_time:
         offset += 1
     if get_theme().CHAR_TIME_RIGHT and message.str_time:
         offset += 1
     lines = poopt.cut_text(txt, self.width-offset-1)
     prepend = default_color if default_color else ''
     attrs = []
     for line in lines:
         saved = Line(msg=message, start_pos=line[0], end_pos=line[1], prepend=prepend)
         attrs = parse_attrs(message.txt[line[0]:line[1]], attrs)
         if attrs:
             prepend = FORMAT_CHAR + FORMAT_CHAR.join(attrs)
         else:
             if default_color:
                 prepend = default_color
             else:
                 prepend = ''
         ret.append(saved)
     return ret
示例#2
0
 def build_message(self, message, timestamp=False, nick_size=10):
     txt = message.txt
     ret = []
     default_color = None
     nick = truncate_nick(message.nickname, nick_size)
     offset = 0
     if nick:
         offset += poopt.wcswidth(nick) + 1  # + nick + ' ' length
     if message.str_time:
         offset += 1 + len(message.str_time)
     if get_theme().CHAR_TIME_LEFT and message.str_time:
         offset += 1
     if get_theme().CHAR_TIME_RIGHT and message.str_time:
         offset += 1
     lines = poopt.cut_text(txt, self.width - offset - 1)
     prepend = default_color if default_color else ''
     attrs = []
     for line in lines:
         saved = Line(msg=message,
                      start_pos=line[0],
                      end_pos=line[1],
                      prepend=prepend)
         attrs = parse_attrs(message.txt[line[0]:line[1]], attrs)
         if attrs:
             prepend = FORMAT_CHAR + FORMAT_CHAR.join(attrs)
         else:
             if default_color:
                 prepend = default_color
             else:
                 prepend = ''
         ret.append(saved)
     return ret
示例#3
0
 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
     to a list
     """
     if message is None:  # line separator
         return [None]
     txt = message.txt
     if not txt:
         return []
     theme = get_theme()
     if len(message.str_time) > 8:
         default_color = (FORMAT_CHAR + dump_tuple(theme.COLOR_LOG_MSG) +
                          '}')  # type: Optional[str]
     else:
         default_color = None
     ret = []  # type: List[Union[None, Line]]
     nick = truncate_nick(message.nickname, nick_size)
     offset = 0
     if message.ack:
         if message.ack > 0:
             offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1
         else:
             offset += poopt.wcswidth(theme.CHAR_NACK) + 1
     if nick:
         offset += poopt.wcswidth(nick) + 2  # + nick + '> ' length
     if message.revisions > 0:
         offset += ceil(log10(message.revisions + 1))
     if message.me:
         offset += 1  # '* ' before and ' ' after
     if timestamp:
         if message.str_time:
             offset += 1 + len(message.str_time)
         if theme.CHAR_TIME_LEFT and message.str_time:
             offset += 1
         if theme.CHAR_TIME_RIGHT and message.str_time:
             offset += 1
     lines = poopt.cut_text(txt, self.width - offset - 1)
     prepend = default_color if default_color else ''
     attrs = []  # type: List[str]
     for line in lines:
         saved = Line(msg=message,
                      start_pos=line[0],
                      end_pos=line[1],
                      prepend=prepend)
         attrs = parse_attrs(message.txt[line[0]:line[1]], attrs)
         if attrs:
             prepend = FORMAT_CHAR + FORMAT_CHAR.join(attrs)
         else:
             if default_color:
                 prepend = default_color
             else:
                 prepend = ''
         ret.append(saved)
     return ret
示例#4
0
 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
     to a list
     """
     if message is None:  # line separator
         return [None]
     txt = message.txt
     if not txt:
         return []
     theme = get_theme()
     if len(message.str_time) > 8:
         default_color = (
             FORMAT_CHAR + dump_tuple(theme.COLOR_LOG_MSG) + '}')  # type: Optional[str]
     else:
         default_color = None
     ret = []  # type: List[Union[None, Line]]
     nick = truncate_nick(message.nickname, nick_size)
     offset = 0
     if message.ack:
         if message.ack > 0:
             offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1
         else:
             offset += poopt.wcswidth(theme.CHAR_NACK) + 1
     if nick:
         offset += poopt.wcswidth(nick) + 2  # + nick + '> ' length
     if message.revisions > 0:
         offset += ceil(log10(message.revisions + 1))
     if message.me:
         offset += 1  # '* ' before and ' ' after
     if timestamp:
         if message.str_time:
             offset += 1 + len(message.str_time)
         if theme.CHAR_TIME_LEFT and message.str_time:
             offset += 1
         if theme.CHAR_TIME_RIGHT and message.str_time:
             offset += 1
     lines = poopt.cut_text(txt, self.width - offset - 1)
     prepend = default_color if default_color else ''
     attrs = []  # type: List[str]
     for line in lines:
         saved = Line(
             msg=message,
             start_pos=line[0],
             end_pos=line[1],
             prepend=prepend)
         attrs = parse_attrs(message.txt[line[0]:line[1]], attrs)
         if attrs:
             prepend = FORMAT_CHAR + FORMAT_CHAR.join(attrs)
         else:
             if default_color:
                 prepend = default_color
             else:
                 prepend = ''
         ret.append(saved)
     return ret