示例#1
0
    def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
        offset = 0
        theme = get_theme()
        if with_timestamps:
            if self.history:
                offset += 1 + theme.LONG_TIME_FORMAT_LENGTH
            else:
                offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH

        if not self.nickname:  # not a message, nothing to do afterwards
            return offset

        nick = truncate_nick(self.nickname, nick_size) or ''
        offset += poopt.wcswidth(nick)
        if self.ack:
            theme = get_theme()
            if self.ack > 0:
                offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1
            else:
                offset += poopt.wcswidth(theme.CHAR_NACK) + 1
        if self.me:
            offset += 3
        else:
            offset += 2
        if self.revisions:
            offset += ceil(log10(self.revisions + 1))
        return offset
示例#2
0
 def write_own_nick(self, room):
     """
     Write our own nick in the info bar
     """
     nick = room.own_nick
     if not nick:
         return
     self.addstr(truncate_nick(nick, 13),
                 to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
示例#3
0
 def compute_offset(self, with_timestamps: bool, nick_size: int) -> int:
     offset = 0
     theme = get_theme()
     if with_timestamps:
         offset += 1 + theme.SHORT_TIME_FORMAT_LENGTH
     if self.incoming:
         nick = theme.CHAR_XML_IN
     else:
         nick = theme.CHAR_XML_OUT
     nick = truncate_nick(nick, nick_size) or ''
     offset += 1 + len(nick)
     return offset
示例#4
0
def write_pre_xmllog(msg: XMLLog, win: 'Win', with_timestamps: bool,
                     nick_size: int) -> int:
    """Write the part before the stanza (timestamp + IN/OUT)"""
    offset = 0
    if with_timestamps:
        offset += 1 + PreMessageHelpers.write_time(win, False, msg.time)
    theme = get_theme()
    if msg.incoming:
        char = theme.CHAR_XML_IN
        color = theme.COLOR_XML_IN
    else:
        char = theme.CHAR_XML_OUT
        color = theme.COLOR_XML_OUT
    nick = truncate_nick(char, nick_size)
    offset += poopt.wcswidth(nick)
    PreMessageHelpers.write_nickname(win, char, color)
    win.addstr(' ')
    return offset
示例#5
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')
     theme = get_theme()
     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.history:
                 offset += 1 + theme.LONG_TIME_FORMAT_LENGTH
         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()
示例#6
0
def write_pre_message(msg: Message, win: 'Win', with_timestamps: bool,
                      nick_size: int) -> int:
    """Write the part before the body:
        - timestamp (short or long)
        - ack/nack
        - nick (with a "* " for /me)
        - LMC number if present
    """
    offset = 0
    if with_timestamps:
        offset += PreMessageHelpers.write_time(win, msg.history, msg.time)

    if not msg.nickname:  # not a message, nothing to do afterwards
        return offset

    nick = truncate_nick(msg.nickname, nick_size)
    offset += poopt.wcswidth(nick)
    if msg.nick_color:
        color = msg.nick_color
    elif msg.user:
        color = msg.user.color
    else:
        color = None
    if msg.ack:
        if msg.ack > 0:
            offset += PreMessageHelpers.write_ack(win)
        else:
            offset += PreMessageHelpers.write_nack(win)
    if msg.me:
        with win.colored_text(color=get_theme().COLOR_ME_MESSAGE):
            win.addstr('* ')
        PreMessageHelpers.write_nickname(win, nick, color, msg.highlight)
        offset += PreMessageHelpers.write_revisions(win, msg)
        win.addstr(' ')
        offset += 3
    else:
        PreMessageHelpers.write_nickname(win, nick, color, msg.highlight)
        offset += PreMessageHelpers.write_revisions(win, msg)
        win.addstr('> ')
        offset += 2
    return offset
示例#7
0
def test_truncate_nick_no_nick():
    assert truncate_nick('') == ''
示例#8
0
def test_truncate_nick_too_long():
    nick = "012345678901234567"
    assert truncate_nick(nick) == nick[:10] + "…"
示例#9
0
def test_truncate_nick_wrong_size():
    assert truncate_nick("toto", -10) == "t…"
示例#10
0
def test_truncate_nick():
    assert truncate_nick("toto") == "toto"