Esempio n. 1
0
def test_cut_text():

    text = '12345678901234567890'
    assert cut_text(text, 5) == [(0, 5), (5, 10), (10, 15), (15, 20)]

    text = 'a\nb\nc\nd'
    assert cut_text(text, 10) == [(0, 2), (2, 4), (4, 6), (6, 7)]

    text = 'vivent les réfrigérateurs'
    assert cut_text(text, 6) == [(0, 6), (6, 10), (11, 17), (17, 23), (23, 25)]
Esempio n. 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
Esempio n. 3
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
Esempio n. 4
0
def build_lines(msg: BaseMessage,
                width: int,
                timestamp: bool,
                nick_size: int = 10) -> List[Line]:
    offset = msg.compute_offset(timestamp, nick_size)
    lines = poopt.cut_text(msg.txt, width - offset - 1)
    return generate_lines(lines, msg, default_color='')
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
def build_message(msg: Message,
                  width: int,
                  timestamp: bool,
                  nick_size: int = 10) -> List[Line]:
    """
    Build a list of lines from this message.
    """
    txt = msg.txt
    if not txt:
        return []
    offset = msg.compute_offset(timestamp, nick_size)
    lines = poopt.cut_text(txt, width - offset - 1)
    generated_lines = generate_lines(lines, msg, default_color='')
    return generated_lines
Esempio n. 8
0
 def goto_build_lines(self, new_date):
     text_buffer = self._text_buffer
     built_lines = []
     message_count = 0
     timestamp = config.get('show_timestamps')
     nick_size = config.get('max_nick_length')
     for message in text_buffer.messages:
         # Build lines of a message
         txt = message.txt
         nick = truncate_nick(message.nickname, nick_size)
         offset = 0
         theme = get_theme()
         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
         if message.revisions > 0:
             offset += ceil(log10(message.revisions + 1))
         if message.me:
             offset += 1
         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.text_win.width - offset - 1)
         for line in lines:
             built_lines.append(line)
         # Find the message with timestamp less than or equal to the queried
         # timestamp and goto that location in the tab.
         if message.time <= new_date:
             message_count += 1
             if len(self.text_win.built_lines
                    ) - self.text_win.height >= len(built_lines):
                 self.text_win.pos = len(
                     self.text_win.built_lines
                 ) - self.text_win.height - len(built_lines) + 1
             else:
                 self.text_win.pos = 0
     if message_count == 0:
         self.text_win.scroll_up(len(self.text_win.built_lines))
     self.core.refresh_window()
Esempio n. 9
0
def test_cut_text():

    text = '12345678901234567890'
    assert cut_text(text, 5) == [(0, 5), (5, 10), (10, 15), (15, 20)]