示例#1
0
def get_merged_buffers(ptr):
    """
	Get a list of buffers which are merged with "ptr".
	"""

    hdata = weechat.hdata_get("buffer")
    buffers = weechat.hdata_get_list(hdata, "gui_buffers")
    buffer = weechat.hdata_search(
        hdata, buffers,
        "${buffer.number} == %i" % weechat.hdata_integer(hdata, ptr, "number"),
        1)
    nbuffer = weechat.hdata_move(hdata, buffer, 1)

    ret = []
    while buffer:
        ret.append(weechat.hdata_string(hdata, buffer, "full_name"))

        if (weechat.hdata_integer(hdata, buffer,
                                  "number") == weechat.hdata_integer(
                                      hdata, nbuffer, "number")):
            buffer = nbuffer
            nbuffer = weechat.hdata_move(hdata, nbuffer, 1)
        else:
            buffer = None

    return ret
示例#2
0
def count_filtered_lines(ptr_buffer, lines_count, lines_after):
    filtered_before = 0
    filtered_after = 0
    filtered = 0

    lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), ptr_buffer,
                                  'own_lines')
    counter = 0
    current_position = lines_count - lines_after

    if lines:
        line = weechat.hdata_pointer(weechat.hdata_get('lines'), lines,
                                     'first_line')
        hdata_line = weechat.hdata_get('line')
        hdata_line_data = weechat.hdata_get('line_data')

        while line:
            data = weechat.hdata_pointer(hdata_line, line, 'data')
            if data:
                #                message = weechat.hdata_string(hdata_line_data, data, 'message')
                displayed = weechat.hdata_char(hdata_line_data, data,
                                               'displayed')
                if displayed == 0:
                    #                    weechat.prnt('','%d - %s - %s' % (counter, displayed, message))
                    if counter < current_position:
                        filtered_before += 1
                    else:
                        filtered_after += 1
            counter += 1
            line = weechat.hdata_move(hdata_line, line, 1)

    filtered = filtered_before + filtered_after
    return filtered, filtered_before, filtered_after
示例#3
0
文件: bufsize.py 项目: Shrews/scripts
def count_filtered_lines(ptr_buffer, lines_count, lines_after):
    filtered_before = 0
    filtered_after = 0
    filtered = 0

    lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), ptr_buffer, "own_lines")
    counter = 0
    current_position = lines_count - lines_after

    if lines:
        line = weechat.hdata_pointer(weechat.hdata_get("lines"), lines, "first_line")
        hdata_line = weechat.hdata_get("line")
        hdata_line_data = weechat.hdata_get("line_data")

        while line:
            data = weechat.hdata_pointer(hdata_line, line, "data")
            if data:
                #                message = weechat.hdata_string(hdata_line_data, data, 'message')
                displayed = weechat.hdata_char(hdata_line_data, data, "displayed")
                if displayed == 0:
                    #                    weechat.prnt('','%d - %s - %s' % (counter, displayed, message))
                    if counter < current_position:
                        filtered_before += 1
                    else:
                        filtered_after += 1
            counter += 1
            line = weechat.hdata_move(hdata_line, line, 1)

    filtered = filtered_before + filtered_after
    return filtered, filtered_before, filtered_after
示例#4
0
def hotlist_item_cb(data, item, window):
    priorities = {}
    titles = {}

    hdata_hotlist = w.hdata_get('hotlist')
    ptr_hotlist = w.hdata_get_list(hdata_hotlist, 'gui_hotlist')
    while ptr_hotlist:
        priority = w.hdata_integer(hdata_hotlist, ptr_hotlist, 'priority')
        buffer = w.hdata_pointer(hdata_hotlist, ptr_hotlist, 'buffer')
        count = w.hdata_integer(
            hdata_hotlist, ptr_hotlist, '%d|count' % GUI_HOTLIST_MESSAGE)
        number = w.buffer_get_integer(buffer, 'number')
        name = w.buffer_get_string(buffer, 'short_name')

        if priority != GUI_HOTLIST_LOW:
            priorities[number] = priority
            titles[number] = '%d:%s' % (number, name)
            if count:
                titles[number] += '(%d)' % count

        ptr_hotlist = w.hdata_move(hdata_hotlist, ptr_hotlist, 1)

    items = []
    for number, priority in sorted(priorities.items()):
        items.append('%s %s %s' % (
            w.color(COLORS[priority]),
            titles[number],
            w.color('reset')))
    return ' '.join(items)
示例#5
0
def layout_apply_cb(data, buffer, command):
    if weechat.config_string_to_boolean(
            weechat.config_get_plugin("layout_apply")):
        m = LAYOUT_APPLY_RE.match(command)
        if m:
            layout_name = m.group(1) or "default"
            hdata_layout = weechat.hdata_get("layout")
            layouts = weechat.hdata_get_list(hdata_layout, "gui_layouts")
            layout = weechat.hdata_search(hdata_layout, layouts,
                                          "${layout.name} == " + layout_name,
                                          1)
            if layout:
                hdata_layout_buffer = weechat.hdata_get("layout_buffer")
                layout_buffer = weechat.hdata_pointer(hdata_layout, layout,
                                                      "layout_buffers")
                while layout_buffer:
                    plugin_name = weechat.hdata_string(hdata_layout_buffer,
                                                       layout_buffer,
                                                       "plugin_name")
                    buffer_name = weechat.hdata_string(hdata_layout_buffer,
                                                       layout_buffer,
                                                       "buffer_name")
                    full_name = "{}.{}".format(plugin_name, buffer_name)

                    buffer = weechat.buffer_search("==", full_name)
                    if not buffer:
                        buffer_open_full_name(full_name, noswitch=True)

                    layout_buffer = weechat.hdata_move(hdata_layout_buffer,
                                                       layout_buffer, 1)
    return weechat.WEECHAT_RC_OK
示例#6
0
def bufsave_cmd(data, buffer, args):
    filename = weechat.buffer_get_string(
        buffer, 'localvar_server') + '.' + weechat.buffer_get_string(
            buffer,
            'localvar_channel')[1:] + '-' + time.strftime('%y_%m_%d') + '.log'
    filename = weechat.string_eval_path_home('%h/logs/' + filename, {}, {}, {})
    try:
        fp = open(filename, 'w')
    except:
        weechat.prnt('', 'Error writing to target file!')
        return weechat.WEECHAT_RC_OK
    own_lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), buffer,
                                      'own_lines')
    if own_lines:
        line = weechat.hdata_pointer(weechat.hdata_get('lines'), own_lines,
                                     'first_line')
        hdata_line = weechat.hdata_get('line')
        hdata_line_data = weechat.hdata_get('line_data')
        while line:
            data = weechat.hdata_pointer(hdata_line, line, 'data')
            if data:
                date = weechat.hdata_time(hdata_line_data, data, 'date')
                if not isinstance(date, str):
                    date = time.strftime('%F %T', time.localtime(int(date)))
                fp.write('{0} {1} {2}\n'.format(
                    date,
                    cstrip(
                        weechat.hdata_string(hdata_line_data, data, 'prefix')),
                    cstrip(
                        weechat.hdata_string(hdata_line_data, data,
                                             'message'))))
            line = weechat.hdata_move(hdata_line, line, 1)
    fp.close()
    return weechat.WEECHAT_RC_OK
示例#7
0
def bufsave_cmd(data, buffer, args):
    ''' Callback for /bufsave command '''

    filename_raw = args

    if not filename_raw:
        w.command('', '/help %s' % SCRIPT_COMMAND)
        return w.WEECHAT_RC_OK

    filename = w.string_eval_path_home(filename_raw, {}, {}, {})

    if exists(filename):
        w.prnt('', 'Error: target file already exists!')
        return w.WEECHAT_RC_OK

    try:
        fp = open(filename, 'w')
    except:
        w.prnt('', 'Error writing to target file!')
        return w.WEECHAT_RC_OK

    version = w.info_get('version_number', '') or 0
    if int(version) >= 0x00030600:
        # use hdata with WeeChat >= 0.3.6 (direct access to data, very fast)
        own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
        if own_lines:
            line = w.hdata_pointer(w.hdata_get('lines'), own_lines,
                                   'first_line')
            hdata_line = w.hdata_get('line')
            hdata_line_data = w.hdata_get('line_data')
            while line:
                data = w.hdata_pointer(hdata_line, line, 'data')
                if data:
                    date = w.hdata_time(hdata_line_data, data, 'date')
                    # since WeeChat 0.3.9, hdata_time returns long instead of string
                    if not isinstance(date, str):
                        date = time.strftime('%F %T',
                                             time.localtime(int(date)))
                    fp.write('%s %s %s\n' %(\
                            date,
                            cstrip(w.hdata_string(hdata_line_data, data, 'prefix')),
                            cstrip(w.hdata_string(hdata_line_data, data, 'message')),
                            ))
                line = w.hdata_move(hdata_line, line, 1)
    else:
        # use infolist with WeeChat <= 0.3.5 (full duplication of lines, slow and uses memory)
        infolist = w.infolist_get('buffer_lines', buffer, '')
        while w.infolist_next(infolist):
            fp.write('%s %s %s\n' %(\
                    w.infolist_time(infolist, 'date'),
                    cstrip(w.infolist_string(infolist, 'prefix')),
                    cstrip(w.infolist_string(infolist, 'message')),
                    ))
        w.infolist_free(infolist)

    fp.close()

    return w.WEECHAT_RC_OK
示例#8
0
def bufsave_cmd(data, buffer, args):
    ''' Callback for /bufsave command '''

    filename_raw = args

    if not filename_raw:
        w.command('', '/help %s' %SCRIPT_COMMAND)
        return w.WEECHAT_RC_OK
    
    filename = w.string_eval_path_home(filename_raw, {}, {}, {})

    if exists(filename):
        w.prnt('', 'Error: target file already exists!')
        return w.WEECHAT_RC_OK

    try:
        fp = open(filename, 'w')
    except:
        w.prnt('', 'Error writing to target file!')
        return w.WEECHAT_RC_OK

    version = w.info_get('version_number', '') or 0
    if int(version) >= 0x00030600:
        # use hdata with WeeChat >= 0.3.6 (direct access to data, very fast)
        own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
        if own_lines:
            line = w.hdata_pointer(w.hdata_get('lines'), own_lines, 'first_line')
            hdata_line = w.hdata_get('line')
            hdata_line_data = w.hdata_get('line_data')
            while line:
                data = w.hdata_pointer(hdata_line, line, 'data')
                if data:
                    date = w.hdata_time(hdata_line_data, data, 'date')
                    # since WeeChat 0.3.9, hdata_time returns long instead of string
                    if not isinstance(date, str):
                        date = time.strftime('%F %T', time.localtime(int(date)))
                    fp.write('%s %s %s\n' %(\
                            date,
                            cstrip(w.hdata_string(hdata_line_data, data, 'prefix')),
                            cstrip(w.hdata_string(hdata_line_data, data, 'message')),
                            ))
                line = w.hdata_move(hdata_line, line, 1)
    else:
        # use infolist with WeeChat <= 0.3.5 (full duplication of lines, slow and uses memory)
        infolist = w.infolist_get('buffer_lines', buffer, '')
        while w.infolist_next(infolist):
            fp.write('%s %s %s\n' %(\
                    w.infolist_time(infolist, 'date'),
                    cstrip(w.infolist_string(infolist, 'prefix')),
                    cstrip(w.infolist_string(infolist, 'message')),
                    ))
        w.infolist_free(infolist)

    fp.close()

    return w.WEECHAT_RC_OK
示例#9
0
def get_merged_buffers(ptr):
    """
    Get a list of buffers which are merged with "ptr".
    """

    weechat_version = int(weechat.info_get("version_number", "") or 0)

    hdata = weechat.hdata_get("buffer")
    buffers = weechat.hdata_get_list(hdata, "gui_buffers")
    if weechat_version >= 0x03040000:
        buffer = weechat.hdata_search(
            hdata,
            buffers,
            "${buffer.number} == ${value}",
            {},
            {"value": str(weechat.hdata_integer(hdata, ptr, "number"))},
            {},
            1,
        )
    else:
        buffer = weechat.hdata_search(
            hdata,
            buffers,
            "${buffer.number} == %i" %
            weechat.hdata_integer(hdata, ptr, "number"),
            1,
        )
    nbuffer = weechat.hdata_move(hdata, buffer, 1)

    ret = []
    while buffer:
        ret.append(weechat.hdata_string(hdata, buffer, "full_name"))

        if weechat.hdata_integer(hdata, buffer,
                                 "number") == weechat.hdata_integer(
                                     hdata, nbuffer, "number"):
            buffer = nbuffer
            nbuffer = weechat.hdata_move(hdata, nbuffer, 1)
        else:
            buffer = None

    return ret
示例#10
0
def get_merged_buffers(ptr):
	"""
	Get a list of buffers which are merged with "ptr".
	"""

	hdata = weechat.hdata_get("buffer")
	buffers = weechat.hdata_get_list(hdata, "gui_buffers")
	buffer = weechat.hdata_search(hdata, buffers, "${buffer.number} == %i" % weechat.hdata_integer(hdata, ptr, "number"), 1)
	nbuffer = weechat.hdata_move(hdata, buffer, 1)

	ret = []
	while buffer:
		ret.append(weechat.hdata_string(hdata, buffer, "full_name"))

		if (weechat.hdata_integer(hdata, buffer, "number") == weechat.hdata_integer(hdata, nbuffer, "number")):
			buffer = nbuffer
			nbuffer = weechat.hdata_move(hdata, nbuffer, 1)
		else:
			buffer = None

	return ret
示例#11
0
    def refresh_buffers(self):
        self.buffers.clear()
        hdata = weechat.hdata_get("buffer")
        buffer = weechat.hdata_get_list(hdata, "gui_buffers")

        if not hdata or not buffer:
            return weechat.WEECHAT_RC_OK
        while True:
            buffer = weechat.hdata_move(hdata, buffer, 1)
            if not buffer:
                break
            else:
                buf = self.buffers[full_name(buffer)] = Buffer(buffer, self.opts)
                logging.debug("Hideable: {}".format(buf.is_hideable()))
                self.try_hide(self.buffers[full_name(buffer)])
示例#12
0
def build_list(data, item, window):
    # Setup variables
    # First retrieve the `hdata`s, then get relevant lists
    buffer_hdata = weechat.hdata_get('buffer')
    server_hdata = weechat.hdata_get('irc_server')
    hotlist_hdata = weechat.hdata_get('hotlist')
    buffer_pointer = weechat.hdata_get_list(buffer_hdata, 'gui_buffers')
    server_pointer = weechat.hdata_get_list(server_hdata, 'irc_servers')
    bar_width = weechat.config_integer(
        weechat.config_get('weechat.bar.buffers.size'))
    buflist = ''

    # Start looping through the buffers
    while buffer_pointer:
        # Grab the hotlist and priority level for the current buffer
        hotlist_pointer = weechat.hdata_pointer(buffer_hdata, buffer_pointer,
                                                "hotlist")
        if hotlist_pointer:
            priority = weechat.hdata_integer(hotlist_hdata, hotlist_pointer,
                                             'priority')
        else:
            priority = 0

        # Setup the info variables for the current buffer
        nick = weechat.buffer_get_string(buffer_pointer, "localvar_nick")
        name = weechat.buffer_get_string(buffer_pointer, "short_name")
        full_name = weechat.buffer_get_string(buffer_pointer, "name")
        plugin = weechat.buffer_get_string(buffer_pointer, "plugin")
        buffer_type = weechat.buffer_get_string(buffer_pointer,
                                                "localvar_type")
        server = weechat.buffer_get_string(buffer_pointer, 'localvar_server')
        icon_color = weechat.buffer_get_string(buffer_pointer,
                                               "localvar_icon_color") or 0
        current_buffer = 1 if weechat.current_buffer() == buffer_pointer else 0

        # Setup info variables for next buffer
        next_pointer = weechat.hdata_move(buffer_hdata, buffer_pointer, 1)
        next_type = weechat.buffer_get_string(next_pointer, "plugin")

        # Start building!

        # Draw icons for non-IRC buffers - core, script, fset, etc
        # You can set an `icon_color` localvar to override the `color.icon` option for a particular buffer when it's active
        # This isn't exactly ideal. Another option would be to use a localvar for each buffer that gets an icon, and then do a check for that
        if plugin != 'irc':
            if current_buffer:
                if icon_color:
                    buflist += weechat.color(icon_color)
                else:
                    buflist += weechat.color(option_values['color.icon'])
            else:
                buflist += weechat.color(option_values['color.default_fg'])

            buflist += "●  "
            buflist += weechat.color(option_values['color.default_fg'])

            # Add a newline if the next buffer is the start of IRC buffers
            if next_type == 'irc':
                buflist += '\n'
        # Start adding other buffers
        else:
            # Add separator between servers
            if option_values[
                    'look.server_separator'] == '1' and buffer_type == 'server':
                buflist += '─' * bar_width + '\n'
            # Print the appropriate color for the current buffer, as well as an icon for the current buffer
            if current_buffer:
                buflist += weechat.color(option_values['color.current_fg'])
                buflist += "●"
            elif priority == 1:
                buflist += weechat.color(
                    option_values['color.hotlist_message'])
            elif priority == 2:
                buflist += weechat.color(
                    option_values['color.hotlist_private'])
            elif priority == 3:
                buflist += weechat.color(
                    option_values['color.hotlist_highlight'])
            else:
                buflist += weechat.color(option_values['color.default_fg'])

            # Spacing between icon and name
            if current_buffer:
                buflist += ' '
            else:
                buflist += '  '
            if buffer_type != 'server':
                buflist += '   '
            if buffer_type == 'private':
                buflist += '  '

            # Add the nick prefix (@, +, etc)
            nick_prefix = get_nick_prefix(buffer_pointer)
            buflist += nick_prefix

            # Add the buffer name
            buflist += name

            # Add nick modes next to server buffers, if any are set
            if buffer_type == 'server':
                # Search for and retrieve a pointer for the server
                pointer = weechat.hdata_search(
                    server_hdata, server_pointer,
                    '${irc_server.name} == ' + server, 1)

                # Then get the nick modes for that server
                nick_modes = weechat.hdata_string(server_hdata, pointer,
                                                  'nick_modes')

                if nick_modes:
                    buflist += ' (+{})'.format(nick_modes)

            # Add the newline after each buffer
            buflist += '\n'

        # Move to the next buffer
        buffer_pointer = weechat.hdata_move(buffer_hdata, buffer_pointer, 1)

    # All done. Return the list
    return buflist