def maze_get_size(args: str = "") -> Tuple[int, int]: """Get maze size with args, defaulting to current maze or window size.""" global maze width: int = 0 height: int = 0 if args in ("d", "default"): args = "" elif maze: width, height = maze.width, maze.height if args: # size given by user try: items = args.split() if len(items) > 1: width, height = int(items[0]), int(items[1]) else: width, height = int(args), int(args) width = max(width, 2) height = max(height, 2) except ValueError: width, height = 0, 0 if not width or not height: # automatic size with size of window win_width: int = weechat.window_get_integer(weechat.current_window(), "win_chat_width") - 1 win_height: int = weechat.window_get_integer(weechat.current_window(), "win_chat_height") - 1 size: int = min(win_width, win_height) width, height = size, size return width, height
def count_lines(winpointer, bufpointer): hdata_buf = weechat.hdata_get('buffer') hdata_lines = weechat.hdata_get('lines') lines = weechat.hdata_pointer(hdata_buf, bufpointer, 'lines') # own_lines, mixed_lines lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count') hdata_window = weechat.hdata_get('window') hdata_winscroll = weechat.hdata_get('window_scroll') window_scroll = weechat.hdata_pointer(hdata_window, winpointer, 'scroll') lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, 'lines_after') window_height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') if lines_count > window_height: differential = lines_count - window_height percent = max( int(round(100. * (differential - lines_after) / differential)), 0) else: percent = 100 #weechat.prnt('', " : lines_count "+str(lines_count)+" window_height "+str(window_height)+" lines after "+str(lines_after)) current_line = lines_count - lines_after return lines_after, lines_count, percent, current_line
def buffer_switch_cb(data, signal, signal_data): global OPTIONS, version # when you /join a buffer and irc.look.buffer_switch_join is ON, the new buffer pointer is not useable at this time server = weechat.buffer_get_string(signal_data, 'localvar_server') # get internal servername buffer_ptr = weechat.buffer_search('irc', 'server.%s' % server) if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower() == 'off' or OPTIONS['activity'].lower() == '0': # hide all channel but use -exclude weechat.command('','/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude']) if server == 'irc_raw': # buffer is /server raw weechat.command('','/allchan /buffer unhide') weechat.command('','/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude']) elif server != '': # a buffer with server weechat.command(buffer_ptr,'/allchan -current /buffer unhide') # use buffer pointer from server exclude_server('') single_channel_exclude() else: if int(version) <= 0x02040000: # workaround weechat.command(signal_data,'/allchan -current /buffer hide') bufpointer = weechat.window_get_pointer(weechat.current_window(), 'buffer') # get current channel pointer weechat.command('','/allchan /buffer hide') weechat.command(bufpointer,'/buffer unhide') # unhide current channel exclude_hotlist() return weechat.WEECHAT_RC_OK
def buffer_switch_cb(data, buffer, command): if command == '': return weechat.WEECHAT_RC_OK args = command.strip().split(' ',)[1:] if len(args) != 1: return weechat.WEECHAT_RC_OK destination_buffer = get_destination_buffer_number(args[0]) if not destination_buffer: return weechat.WEECHAT_RC_OK if destination_buffer < 1: destination_buffer = 1 buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr(destination_buffer) if not ptr_buffer: return weechat.WEECHAT_RC_OK if ptr_buffer == weechat.window_get_pointer(weechat.current_window(), 'buffer'): return weechat.WEECHAT_RC_OK window_number = weechat.buffer_get_string(ptr_buffer, 'localvar_stick_buffer_to_window') if not window_number: window_number = get_default_stick_window_number() if window_number: weechat.command('', '/window %s' % window_number) return weechat.WEECHAT_RC_OK
def buffer_switch_cb(data, buffer, command): if command == '': return weechat.WEECHAT_RC_OK args = command.strip().split(' ', )[1:] if len(args) != 1: return weechat.WEECHAT_RC_OK destination_buffer = get_destination_buffer_number(args[0]) if not destination_buffer: return weechat.WEECHAT_RC_OK if destination_buffer < 1: destination_buffer = 1 buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr( destination_buffer) if not ptr_buffer: return weechat.WEECHAT_RC_OK if ptr_buffer == weechat.window_get_pointer(weechat.current_window(), 'buffer'): return weechat.WEECHAT_RC_OK window_number = weechat.buffer_get_string( ptr_buffer, 'localvar_stick_buffer_to_window') if not window_number: window_number = get_default_stick_window_number() if window_number: weechat.command('', '/window %s' % window_number) return weechat.WEECHAT_RC_OK
def buffer_switch_cb(data, signal, signal_data): global OPTIONS, version # when you /join a buffer and irc.look.buffer_switch_join is ON, the new buffer pointer is not useable at this time server = weechat.buffer_get_string( signal_data, 'localvar_server') # get internal servername buffer_ptr = weechat.buffer_search('irc', 'server.%s' % server) if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower( ) == 'off' or OPTIONS['activity'].lower() == '0': # hide all channel but use -exclude weechat.command( '', '/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude']) if server == 'irc_raw': # buffer is /server raw weechat.command('', '/allchan /buffer unhide') weechat.command( '', '/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude']) elif server != '': # a buffer with server weechat.command(buffer_ptr, '/allchan -current /buffer unhide' ) # use buffer pointer from server exclude_server() single_channel_exclude() else: if int(version) <= 0x02040000: # workaround weechat.command(signal_data, '/allchan -current /buffer hide') bufpointer = weechat.window_get_pointer( weechat.current_window(), 'buffer') # get current channel pointer weechat.command('', '/allchan /buffer hide') weechat.command(bufpointer, '/buffer unhide') # unhide current channel exclude_hotlist() return weechat.WEECHAT_RC_OK
def count_lines(ptr_window,ptr_buffer): global filter_status hdata_buf = weechat.hdata_get('buffer') hdata_lines = weechat.hdata_get('lines') lines = weechat.hdata_pointer(hdata_buf, ptr_buffer, 'lines') # own_lines, mixed_lines lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count') hdata_window = weechat.hdata_get('window') hdata_winscroll = weechat.hdata_get('window_scroll') window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, 'scroll') lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, 'lines_after') window_height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') filtered = 0 filtered_before = 0 filtered_after = 0 # if filter is disabled, don't count. if (OPTIONS['count_filtered_lines'].lower() == 'off') and filter_status == 1: filtered, filtered_before,filtered_after = count_filtered_lines(ptr_buffer,lines_count,lines_after) lines_count = lines_count - filtered # lines_after = lines_after - filtered_after if lines_count > window_height: differential = lines_count - window_height percent = max(int(round(100. * (differential - lines_after) / differential)), 0) else: percent = 100 # get current position current_line = lines_count - lines_after return lines_after,lines_count,percent,current_line, filtered, filtered_before, filtered_after
def count_lines(ptr_window, ptr_buffer): global filter_status hdata_buf = weechat.hdata_get("buffer") hdata_lines = weechat.hdata_get("lines") lines = weechat.hdata_pointer(hdata_buf, ptr_buffer, "lines") # own_lines, mixed_lines lines_count = weechat.hdata_integer(hdata_lines, lines, "lines_count") hdata_window = weechat.hdata_get("window") hdata_winscroll = weechat.hdata_get("window_scroll") window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, "scroll") lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, "lines_after") window_height = weechat.window_get_integer(weechat.current_window(), "win_chat_height") filtered = 0 filtered_before = 0 filtered_after = 0 # if filter is disabled, don't count. if (OPTIONS["count_filtered_lines"].lower() == "off") and filter_status == 1: filtered, filtered_before, filtered_after = count_filtered_lines(ptr_buffer, lines_count, lines_after) lines_count = lines_count - filtered # lines_after = lines_after - filtered_after if lines_count > window_height: differential = lines_count - window_height percent = max(int(round(100.0 * (differential - lines_after) / differential)), 0) else: percent = 100 # get current position current_line = lines_count - lines_after return lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after
def buffer_switch_cb(data, signal, signal_data): global look_server look_server = "" look_server = weechat.config_string( weechat.config_get("irc.look.server_buffer")) if look_server == "independent": # server buffer independent? return weechat.WEECHAT_RC_OK # better remove script, you don't need it. if weechat.buffer_get_string( signal_data, 'name') != 'weechat': # not weechat core buffer if (weechat.buffer_get_string(signal_data, 'localvar_type') == '') or (weechat.buffer_get_string( signal_data, 'localvar_type') == 'server'): return weechat.WEECHAT_RC_OK elif weechat.buffer_get_string(signal_data, 'name') == 'weechat': return weechat.WEECHAT_RC_OK # buffer is channel or private? if (weechat.buffer_get_string(signal_data, 'localvar_type') == 'channel') or (weechat.buffer_get_string( signal_data, 'localvar_type') == 'private'): bufpointer = weechat.window_get_pointer(weechat.current_window(), "buffer") servername_from_current_buffer = weechat.buffer_get_string( bufpointer, 'localvar_server') name = weechat.buffer_get_string(bufpointer, 'name') server_switch(signal_data, servername_from_current_buffer, name) return weechat.WEECHAT_RC_OK
def osc_notify_hook(udata, buf, date, tags, displayed, highlight, prefix, message): if displayed and (highlight or 'notify_private' in tags.split(',')): is_visible = weechat.window_search_with_buffer( buf) == weechat.current_window() send_osc('im-notify', int(is_visible), int(is_tmux_visible()), prefix) return weechat.WEECHAT_RC_OK
def buffer_switch_cb(data, signal, signal_data): global highlights if w.config_get_plugin('clear_visited_buffers') == 'on': buffer = w.window_get_pointer(w.current_window(), 'buffer') write(w.config_get_plugin('output_active_buffer'), bufname(buffer)) highlights = [ item for item in highlights if item['buffer'] != buffer ] write_file() return w.WEECHAT_RC_OK
def buffer_switch_cb(data, signal, signal_data): ptr_buffer = signal_data window = weechat.current_window() ptr_buffer = weechat.window_get_pointer(window,'buffer') if ptr_buffer == '': return '' get_file_information(ptr_buffer) return weechat.WEECHAT_RC_OK
def bar_item_cb (data, item, window): # check for root input bar! if not window: window = weechat.current_window() # get current buffer (for example for split windows!) ptr_buffer = weechat.window_get_pointer(window,"buffer") if ptr_buffer == '': return ''
def samegame_adjust_zoom(): """Choose zoom according to size of window.""" global samegame, samegame_settings samegame["zoom"] = -1 if samegame_settings["zoom"]: try: samegame["zoom"] = int(samegame_settings["zoom"]) except: samegame["zoom"] = -1 if samegame["zoom"] < 0: width = weechat.window_get_integer(weechat.current_window(), "win_chat_width") height = weechat.window_get_integer(weechat.current_window(), "win_chat_height") for i in range(10, -1, -1): if width >= samegame["size"][0] * ((i + 1) * 2) + 2 and height >= (samegame["size"][1] * (i + 1)) + 3: samegame["zoom"] = i break if samegame["zoom"] < 0: samegame["zoom"] = 0
def bar_item_cb(data, item, window): # check for root input bar! if not window: window = weechat.current_window() # get current buffer (for example for split windows!) ptr_buffer = weechat.window_get_pointer(window, 'buffer') if ptr_buffer == '': return ''
def scroll_stats(): if timer_ptr: stop_timer() window_size = weechat.window_get_integer(weechat.current_window(), 'win_width') string = '' for key in streams_dict.keys(): string += key.decode('utf-8').lstrip('/') + ' => ' for subkey, value in streams_dict[key].items(): string += '%s: %s, ' % (subkey.decode('utf-8'), value.decode('utf-8'))
def floodit_adjust_zoom(): """Choose zoom according to size of window.""" global floodit, floodit_settings floodit['zoom'] = -1 if floodit_settings['zoom']: try: floodit['zoom'] = int(floodit_settings['zoom']) except: floodit['zoom'] = -1 if floodit['zoom'] < 0: width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') for i in range(10, -1, -1): if width >= floodit['size'] * ((i + 1) * 2) and height >= (floodit['size'] * (i + 1)) + i + 2: floodit['zoom'] = i break if floodit['zoom'] < 0: floodit['zoom'] = 0
def minimal_bar_item(data, item, window): if not window: window = w.current_window() ptr_buffer = w.window_get_pointer(window, "buffer") if ptr_buffer == "" or ptr_buffer == w.current_buffer(): return "" length = w.window_get_integer(window, 'win_width') - w.buffer_get_integer( ptr_buffer, 'input_length') s = length * " " return s
def minesweeper_adjust_zoom(): """Choose zoom according to size of window.""" global minesweeper, minesweeper_settings minesweeper['zoom'] = -1 if minesweeper_settings['zoom']: try: minesweeper['zoom'] = int(minesweeper_settings['zoom']) except: minesweeper['zoom'] = -1 if minesweeper['zoom'] > 1: minesweeper['zoom'] = 1 if minesweeper['zoom'] < 0: width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') minesweeper['zoom'] = 0 if width >= minesweeper['size'] * 6 and height >= 1 + (minesweeper['size'] * 3) + 2: minesweeper['zoom'] = 1 if minesweeper['zoom'] < 0: minesweeper['zoom'] = 0
def refresh(): width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') string = option_values['marker'] marker = string + ' ' * (width - (len(string.decode('utf-8')) * 2)) + string config = weechat.config_get('weechat.look.read_marker_string') weechat.config_option_set(config, marker, 0)
def show_item(data, item, window): # check for root input bar! if not window: window = weechat.current_window() ptr_buffer = weechat.window_get_pointer(window, 'buffer') if ptr_buffer == '': return '' if weechat.buffer_get_string( ptr_buffer, 'name') != 'weechat': # not weechat core buffer if weechat.buffer_get_string( ptr_buffer, 'localvar_type') == '': # buffer with free content? return '' lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after = count_lines( window, ptr_buffer) lines_after_bak = lines_after if lines_count == 0: # buffer empty? return '' if filtered == 0: filtered = '' if lines_after == 0 and (OPTIONS['show_scroll'].lower() == 'off'): lines_after = '' tags = { '%C': str(current_line), '%A': str(lines_after), '%F': str(filtered), '%L': str(lines_count), '%P': str(percent) + '%' } bufsize_item = substitute_colors(OPTIONS['format']) # replace mandatory tags for tag in list(tags.keys()): # for tag in tags.keys(): bufsize_item = bufsize_item.replace(tag, tags[tag]) # replace optional tags # %{…} only if lines after (e.g. %A > 0) if lines_after_bak > 0: for regex_tag in regex_optional_tags.findall(bufsize_item): bufsize_item = bufsize_item.replace( regex_tag, regex_tag.lstrip('%{').rstrip('}')) else: bufsize_item = regex_optional_tags.sub('', bufsize_item) return bufsize_item
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string current_buffer = weechat.current_buffer() current_window = weechat.current_window() plugin = weechat.buffer_get_pointer(current_buffer, 'plugin') msg_help = (get_help_command(plugin, command[1:], arguments) or get_list_commands(plugin, command[1:], arguments)) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' if cmdhelp_settings['right_align'] == 'on': win_width = weechat.window_get_integer(current_window, 'win_width') input_length = weechat.buffer_get_integer(current_buffer, 'input_length') help_length = len(weechat.string_remove_color(msg_help, "")) min_space = int(cmdhelp_settings['space']) padding = int(cmdhelp_settings['right_padding']) space = win_width - input_length - help_length - padding if space < min_space: space = min_space else: space = int(cmdhelp_settings['space']) color_delimiters = cmdhelp_settings['color_delimiters'] return '%s%s%s%s%s%s%s' % (string, space * ' ', weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def floodit_adjust_zoom(): """Choose zoom according to size of window.""" global floodit, floodit_settings floodit['zoom'] = -1 if floodit_settings['zoom']: try: floodit['zoom'] = int(floodit_settings['zoom']) except: floodit['zoom'] = -1 if floodit['zoom'] < 0: width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') for i in range(10, -1, -1): if width >= floodit['size'] * ( (i + 1) * 2) and height >= (floodit['size'] * (i + 1)) + i + 2: floodit['zoom'] = i break if floodit['zoom'] < 0: floodit['zoom'] = 0
def scroll_topic_cb(data_ptr, buffer_ptr, args): # enciende el scroll window_size = weechat.window_get_integer(weechat.current_window(), 'win_width') texto = u'\x03c12' + 'Texto de prueba' display_vect = [' '] * window_size texto_vect = [] for character in texto: texto_vect += [character] global display_fin display_fin = display_vect + texto_vect timer_ptr = weechat.hook_timer(300, 0, len(display_fin), 'scroll_cb', '') return weechat.WEECHAT_RC_OK
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string current_buffer = weechat.current_buffer() current_window = weechat.current_window() plugin = weechat.buffer_get_pointer(current_buffer, 'plugin') msg_help = get_help_command(plugin, command[1:], arguments) or get_list_commands( plugin, command[1:], arguments) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' if cmdhelp_settings['right_align'] == 'on': win_width = weechat.window_get_integer(current_window, 'win_width') input_length = weechat.buffer_get_integer(current_buffer, 'input_length') help_length = len(weechat.string_remove_color(msg_help, "")) min_space = int(cmdhelp_settings['space']) padding = int(cmdhelp_settings['right_padding']) space = win_width - input_length - help_length - padding if space < min_space: space = min_space else: space = int(cmdhelp_settings['space']) color_delimiters = cmdhelp_settings['color_delimiters'] return '%s%s%s%s%s%s%s' % ( string, space * ' ', weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def unfocused_bar_item (data, item, window): '''Item constructor''' # window empty? root bar! if not window: window = w.current_window() ptr_buffer = w.window_get_pointer(window, "buffer") if ptr_buffer == "" or ptr_buffer == w.current_buffer(): return "" length = w.window_get_integer(window, 'win_width') - w.buffer_get_integer(ptr_buffer, 'input_length') s = length * inputtape_char return s
def minesweeper_adjust_zoom(): """Choose zoom according to size of window.""" global minesweeper, minesweeper_settings minesweeper['zoom'] = -1 if minesweeper_settings['zoom']: try: minesweeper['zoom'] = int(minesweeper_settings['zoom']) except: minesweeper['zoom'] = -1 if minesweeper['zoom'] > 1: minesweeper['zoom'] = 1 if minesweeper['zoom'] < 0: width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') minesweeper['zoom'] = 0 if width >= minesweeper['size'] * 6 and height >= 1 + ( minesweeper['size'] * 3) + 2: minesweeper['zoom'] = 1 if minesweeper['zoom'] < 0: minesweeper['zoom'] = 0
def samegame_adjust_zoom(): """Choose zoom according to size of window.""" global samegame, samegame_settings samegame['zoom'] = -1 if samegame_settings['zoom']: try: samegame['zoom'] = int(samegame_settings['zoom']) except: samegame['zoom'] = -1 if samegame['zoom'] < 0: width = weechat.window_get_integer(weechat.current_window(), 'win_chat_width') height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') for i in range(10, -1, -1): if width >= samegame['size'][0] * ( (i + 1) * 2) + 2 and height >= (samegame['size'][1] * (i + 1)) + 3: samegame['zoom'] = i break if samegame['zoom'] < 0: samegame['zoom'] = 0
def cb_exec_cmd(data, remaining_calls): """Translate and execute our custom commands to WeeChat command.""" # Process the entered command. data = list(data) del data[0] data = "".join(data) # s/foo/bar command. if data.startswith("s/"): cmd = data parsed_cmd = next(csv.reader(StringIO(cmd), delimiter="/", escapechar="\\")) pattern = re.escape(parsed_cmd[1]) repl = parsed_cmd[2] repl = re.sub(r"([^\\])&", r"\1" + pattern, repl) flag = None if len(parsed_cmd) == 4: flag = parsed_cmd[3] count = 1 if flag == "g": count = 0 buf = weechat.current_buffer() input_line = weechat.buffer_get_string(buf, "input") input_line = re.sub(pattern, repl, input_line, count) weechat.buffer_set(buf, "input", input_line) # Shell command. elif data.startswith("!"): weechat.command("", "/exec -buffer shell %s" % data[1:]) # Commands like `:22`. This should start cursor mode (``/cursor``) and take # us to the relevant line. # TODO: look into possible replacement key bindings for: ← ↑ → ↓ Q m q. elif data.isdigit(): line_number = int(data) hdata_window = weechat.hdata_get("window") window = weechat.current_window() x = weechat.hdata_integer(hdata_window, window, "win_chat_x") y = (weechat.hdata_integer(hdata_window, window, "win_chat_y") + (line_number - 1)) weechat.command("", "/cursor go {},{}".format(x, y)) # Check againt defined commands. else: data = data.split(" ", 1) cmd = data[0] args = "" if len(data) == 2: args = data[1] if cmd in VI_COMMANDS: weechat.command("", "%s %s" % (VI_COMMANDS[cmd], args)) # No vi commands defined, run the command as a WeeChat command. else: weechat.command("", "/{} {}".format(cmd, args)) return weechat.WEECHAT_RC_OK
def cb_exec_cmd(data, remaining_calls): """Translate and execute our custom commands to WeeChat command.""" # Process the entered command. data = list(data) del data[0] data = "".join(data) # s/foo/bar command. if data.startswith("s/"): cmd = data parsed_cmd = next( csv.reader(StringIO(cmd), delimiter="/", escapechar="\\")) pattern = re.escape(parsed_cmd[1]) repl = parsed_cmd[2] repl = re.sub(r"([^\\])&", r"\1" + pattern, repl) flag = None if len(parsed_cmd) == 4: flag = parsed_cmd[3] count = 1 if flag == "g": count = 0 buf = weechat.current_buffer() input_line = weechat.buffer_get_string(buf, "input") input_line = re.sub(pattern, repl, input_line, count) weechat.buffer_set(buf, "input", input_line) # Shell command. elif data.startswith("!"): weechat.command("", "/exec -buffer shell %s" % data[1:]) # Commands like `:22`. This should start cursor mode (``/cursor``) and take # us to the relevant line. # TODO: look into possible replacement key bindings for: ← ↑ → ↓ Q m q. elif data.isdigit(): line_number = int(data) hdata_window = weechat.hdata_get("window") window = weechat.current_window() x = weechat.hdata_integer(hdata_window, window, "win_chat_x") y = (weechat.hdata_integer(hdata_window, window, "win_chat_y") + (line_number - 1)) weechat.command("", "/cursor go {},{}".format(x, y)) # Check againt defined commands. else: data = data.split(" ", 1) cmd = data[0] args = "" if len(data) == 2: args = data[1] if cmd in VI_COMMANDS: weechat.command("", "%s %s" % (VI_COMMANDS[cmd], args)) # No vi commands defined, run the command as a WeeChat command. else: weechat.command("", "/{} {}".format(cmd, args)) return weechat.WEECHAT_RC_OK
def unfocused_bar_item(data, item, window): '''Item constructor''' # window empty? root bar! if not window: window = w.current_window() ptr_buffer = w.window_get_pointer(window, "buffer") if ptr_buffer == "" or ptr_buffer == w.current_buffer(): return "" length = w.window_get_integer(window, 'win_width') - w.buffer_get_integer( ptr_buffer, 'input_length') s = length * inputtape_char return s
def show_spell_correction_item_cb(data, item, window): # check for root input bar! if not window: window = weechat.current_window() # weechat.buffer_get_string(buffer,'localvar_spell_correction_suggest_item'): buffer = weechat.window_get_pointer(window, "buffer") if buffer == '': return '' tab_complete, position, aspell_suggest_item = get_position_and_suggest_item( buffer) if not position or not aspell_suggest_item: return '' # config_spell_suggest_item = weechat.config_get_plugin('suggest_item') # if config_spell_suggest_item: # show_item = config_spell_suggest_item.replace('%S',aspell_suggest_item) # show_item = substitute_colors(show_item) # return '%s' % (show_item) # else: # return aspell_suggest_item config_spell_suggest_item = weechat.config_get_plugin('suggest_item') dict_found = search_dict(buffer, position) if dict_found: if config_spell_suggest_item: show_item = config_spell_suggest_item.replace( '%S', aspell_suggest_item) show_item = show_item.replace('%D', dict_found) show_item = substitute_colors(show_item) return '%s' % (show_item) else: return aspell_suggest_item else: if config_spell_suggest_item: show_item = config_spell_suggest_item.replace( '%S', aspell_suggest_item) if weechat.config_get_plugin('hide_single_dict').lower() == 'off': show_item = show_item.replace('%D', get_aspell_dict_for(buffer)) else: show_item = show_item.replace('%D', '').rstrip() show_item = substitute_colors(show_item) return '%s' % (show_item) return aspell_suggest_item
def server_switch(signal_data, servername_from_current_buffer, name): global look_server SERVER = {} bufpointer = weechat.window_get_pointer(weechat.current_window(), "buffer") servername_current_buffer = servername_from_current_buffer if look_server == "merge_with_core": # merge_with_core SERVER["weechat"] = "core.weechat" # get ALL server buffers and save them infolist = weechat.infolist_get( "buffer", "", "*server.*") # we are only interest in server-buffers while weechat.infolist_next(infolist): bufpointer = weechat.infolist_pointer(infolist, "pointer") server = weechat.infolist_string( infolist, "name") # full servername (server.<servername>) servername = weechat.infolist_string( infolist, "short_name" ) # get servername from server (without prefix "server") active = weechat.infolist_integer(infolist, "active") SERVER[servername] = server if (active == 1) and (servername_current_buffer != servername ): # buffer active but not correct server buffer? weechat.command( bufpointer, "/input switch_active_buffer") # switch server buffer weechat.infolist_free(infolist) # do not forget to free infolist! # switch though all server and stop at server from current buffer i = 0 while i <= len(SERVER): for servername, full_name in list(SERVER.items()): bufpointer = weechat.buffer_search( "irc", "%s" % full_name) # search pointer from server buffer if bufpointer == "": # core buffer if weechat.buffer_get_integer(weechat.buffer_search_main(), 'active') == 1: weechat.command(weechat.buffer_search_main(), "/input switch_active_buffer") else: # server buffer! if (servername != servername_current_buffer) and ( weechat.buffer_get_integer(bufpointer, 'active') == 1): weechat.command(bufpointer, "/input switch_active_buffer") elif (servername == servername_current_buffer) and ( weechat.buffer_get_integer(bufpointer, 'active') == 1): i = len(SERVER) break i += 1
def my_print_cb(data, buffer, date, tags, displayed, highlight, prefix, message): global highlights if w.config_get_plugin('clear_visited_buffers') == 'on': if buffer == w.window_get_pointer(w.current_window(), 'buffer'): return w.WEECHAT_RC_OK if highlight == "1": infos = {'buffer' : buffer, 'date' : date, 'tags' : str.split(tags, ','), 'nick' : prefix, 'message' : message, } highlights.append(infos) write_file() return w.WEECHAT_RC_OK
def update_item (data, item, window): if not data: return "" # window empty? root bar! if not window: window = weechat.current_window() value = weechat.config_get_plugin(data) if not value: return "" value = check_buffer_type(window, data, value) return substitute_colors(value,window)
def update_item(data, item, window): if not data: return "" # window empty? root bar! if not window: window = weechat.current_window() value = weechat.config_get_plugin(data) if not value: return "" value = check_buffer_type(window, data, value) return substitute_colors(value, window)
def show_item(data, item, window): # check for root input bar! if not window: window = weechat.current_window() ptr_buffer = weechat.window_get_pointer(window, "buffer") if ptr_buffer == "": return "" if weechat.buffer_get_string(ptr_buffer, "name") != "weechat": # not weechat core buffer if weechat.buffer_get_string(ptr_buffer, "localvar_type") == "": # buffer with free content? return "" lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after = count_lines( window, ptr_buffer ) if lines_count == 0: # buffer empty? return "" if filtered == 0: filtered = "" tags = { "%C": str(current_line), "%A": str(lines_after), "%F": str(filtered), "%L": str(lines_count), "%P": str(percent) + "%", } bufsize_item = substitute_colors(OPTIONS["format"]) # replace mandatory tags for tag in list(tags.keys()): # for tag in tags.keys(): bufsize_item = bufsize_item.replace(tag, tags[tag]) # replace optional tags # %{…} only if lines after (e.g. %A > 0) if lines_after > 0: for regex_tag in regex_optional_tags.findall(bufsize_item): bufsize_item = bufsize_item.replace(regex_tag, regex_tag.lstrip("%{").rstrip("}")) else: bufsize_item = regex_optional_tags.sub("", bufsize_item) return bufsize_item
def show_item (data, item, window): # check for root input bar! if not window: window = weechat.current_window() ptr_buffer = weechat.window_get_pointer(window,'buffer') if ptr_buffer == '': return '' if weechat.buffer_get_string(ptr_buffer,'name') != 'weechat': # not weechat core buffer if weechat.buffer_get_string(ptr_buffer,'localvar_type') == '': # buffer with free content? return '' lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after = count_lines(window,ptr_buffer) lines_after_bak = lines_after if lines_count == 0: # buffer empty? return '' if filtered == 0: filtered = '' if lines_after == 0 and (OPTIONS['show_scroll'].lower() == 'off'): lines_after = '' tags = {'%C': str(current_line), '%A': str(lines_after), '%F': str(filtered), '%L': str(lines_count), '%P': str(percent)+'%'} bufsize_item = substitute_colors(OPTIONS['format']) # replace mandatory tags for tag in list(tags.keys()): # for tag in tags.keys(): bufsize_item = bufsize_item.replace(tag, tags[tag]) # replace optional tags # %{…} only if lines after (e.g. %A > 0) if lines_after_bak > 0: for regex_tag in regex_optional_tags.findall(bufsize_item): bufsize_item = bufsize_item.replace(regex_tag, regex_tag.lstrip('%{').rstrip('}')) else: bufsize_item = regex_optional_tags.sub('', bufsize_item) return bufsize_item
def show_spell_correction_item_cb(data, item, window): # check for root input bar! if not window: window = weechat.current_window() # weechat.buffer_get_string(buffer,'localvar_spell_correction_suggest_item'): buffer = weechat.window_get_pointer(window, "buffer") if buffer == "": return "" tab_complete, position, aspell_suggest_item = get_position_and_suggest_item(buffer) if not position or not aspell_suggest_item: return "" # config_spell_suggest_item = weechat.config_get_plugin('suggest_item') # if config_spell_suggest_item: # show_item = config_spell_suggest_item.replace('%S',aspell_suggest_item) # show_item = substitute_colors(show_item) # return '%s' % (show_item) # else: # return aspell_suggest_item config_spell_suggest_item = weechat.config_get_plugin("suggest_item") dict_found = search_dict(buffer, position) if dict_found: if config_spell_suggest_item: show_item = config_spell_suggest_item.replace("%S", aspell_suggest_item) show_item = show_item.replace("%D", dict_found) show_item = substitute_colors(show_item) return "%s" % (show_item) else: return aspell_suggest_item else: if config_spell_suggest_item: show_item = config_spell_suggest_item.replace("%S", aspell_suggest_item) if weechat.config_get_plugin("hide_single_dict").lower() == "off": show_item = show_item.replace("%D", get_aspell_dict_for(buffer)) else: show_item = show_item.replace("%D", "").rstrip() show_item = substitute_colors(show_item) return "%s" % (show_item) return aspell_suggest_item
def buffer_switch_cb(data, buffer, command): # weechat.prnt("","data: %s buffer: %s command: %s" % (data,buffer,command)) # command exist? if command == '': return weechat.WEECHAT_RC_OK # get command without leading command char! cmd = command[1:].strip().split(' ',)[0:1] # get number from command /buffer args = command.strip().split(' ',)[1:] ptr_buffer = '' if "input" in cmd and "jump_smart" in args: buffer_name, ptr_buffer, buffer_number = infolist_get_first_entry_from_hotlist() if "buffer" in cmd: if len(args) != 1: return weechat.WEECHAT_RC_OK # check if argument is a buffer "number" destination_buffer = get_destination_buffer_number(args[0]) if destination_buffer: if destination_buffer < 1: destination_buffer = 1 buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr_by_number(destination_buffer) else: # search for buffer name buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr_by_name(args[0]) if not ptr_buffer: return weechat.WEECHAT_RC_OK if ptr_buffer == weechat.window_get_pointer(weechat.current_window(), 'buffer'): return weechat.WEECHAT_RC_OK window_number = weechat.buffer_get_string(ptr_buffer, 'localvar_stick_buffer_to_window') if not window_number: window_number = get_default_stick_window_number() if window_number: weechat.command('', '/window %s' % window_number) weechat.command('', '/buffer %s' % buffer_name) return weechat.WEECHAT_RC_OK_EAT else: return weechat.WEECHAT_RC_OK
def timer_cb(data, remaining_calls): global indent current_time = int(time.time()) interval = int(weechat.config_get_plugin('modulo_interval')) * 60 if (current_time % interval) == 0: infolist = weechat.infolist_get("buffer", "", "") if infolist: # set static width, assumes balanced window widths if indent < 0: if weechat.config_get_plugin('center') == '0': indent = 0 else: # centering = (window width - prefix width - (vertical separator + date)) / 2 - rounding adjustment indent = (weechat.window_get_integer(weechat.current_window (), "win_width") - int(weechat.string_eval_expression("${weechat.look.prefix_align_min}", {}, {}, {})) - 14) / 2 - 1 while weechat.infolist_next(infolist): buffer = weechat.infolist_pointer(infolist, 'pointer') prnt_timestamp(buffer, current_time, indent) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def buffer_switch_cb(data, signal, signal_data): global look_server look_server = "" look_server = weechat.config_string(weechat.config_get("irc.look.server_buffer")) if look_server == "independent": # server buffer independent? return weechat.WEECHAT_RC_OK # better remove script, you don't need it. if weechat.buffer_get_string(signal_data,'name') != 'weechat': # not weechat core buffer if (weechat.buffer_get_string(signal_data,'localvar_type') == '') or (weechat.buffer_get_string(signal_data,'localvar_type') == 'server'): return weechat.WEECHAT_RC_OK elif weechat.buffer_get_string(signal_data,'name') == 'weechat': return weechat.WEECHAT_RC_OK # buffer is channel or private? if (weechat.buffer_get_string(signal_data,'localvar_type') == 'channel') or (weechat.buffer_get_string(signal_data,'localvar_type') == 'private'): bufpointer = weechat.window_get_pointer(weechat.current_window(),"buffer") servername_from_current_buffer = weechat.buffer_get_string(bufpointer, 'localvar_server') name = weechat.buffer_get_string(bufpointer, 'name') server_switch(signal_data,servername_from_current_buffer,name) return weechat.WEECHAT_RC_OK
def win_scroll_screen(data, buffer, args): screens = float(args) win = w.current_window() chat_height = w.window_get_integer(win, 'win_chat_height') if screens < 0: scrolling = w.window_get_integer(win, 'scrolling') if scrolling == 0: # no idea why but this is needed scroll = int(chat_height * screens) - (chat_height - 3) else: scroll = int(chat_height * screens) else: scroll = int(chat_height * screens) lines_after = w.window_get_integer(win, 'lines_after') if scroll >= lines_after: return w.command(buffer, "/window scroll_bottom") return w.command(buffer, "/window scroll {:+d}".format(scroll))
def update_item (data, item, window): if not data: return "" # window empty? root bar! if not window: window = weechat.current_window() value = weechat.config_get_plugin(data) if value: value = check_buffer_type(window,value) else: return "" if not value: return "" # substitute colors in output return re.sub(regex_color, lambda match: weechat.color(match.group(1)), value)
def buffer_switch_cb(signal, callback, callback_data): if callback_data == '': return weechat.WEECHAT_RC_OK argv = callback_data.strip().split(' ', )[1:] if len(argv) == 0 or len(argv) > 1: return weechat.WEECHAT_RC_OK # check out if string is a number str_buffer_number = get_buffer_number_as_string(argv[0]) if not str_buffer_number: return weechat.WEECHAT_RC_OK curren_buffer_number = get_current_buffer_number() if not curren_buffer_number: return weechat.WEECHAT_RC_OK if argv[0][0] == '-': switch_to_buffer = curren_buffer_number - int( argv[0][1:]) # [1:] don't use first sign if switch_to_buffer < 1: switch_to_buffer = 1 elif argv[0][0] == '+': switch_to_buffer = curren_buffer_number + int( argv[0][1:]) # [1:] don't use first sign else: switch_to_buffer = int(str_buffer_number[0]) buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr( switch_to_buffer) if not buffer_name or not ptr_buffer: return weechat.WEECHAT_RC_OK if ptr_buffer == weechat.window_get_pointer(weechat.current_window(), 'buffer'): return weechat.WEECHAT_RC_OK window_number = weechat.buffer_get_string( ptr_buffer, 'localvar_stick_buffer_to_window') if window_number: weechat.command('', '/window %s' % window_number) return weechat.WEECHAT_RC_OK
def count_lines(ptr_window, ptr_buffer): global filter_status hdata_buf = weechat.hdata_get('buffer') hdata_lines = weechat.hdata_get('lines') lines = weechat.hdata_pointer(hdata_buf, ptr_buffer, 'lines') # own_lines, mixed_lines lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count') hdata_window = weechat.hdata_get('window') hdata_winscroll = weechat.hdata_get('window_scroll') window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, 'scroll') lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, 'lines_after') window_height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height') filtered = 0 filtered_before = 0 filtered_after = 0 # if filter is disabled, don't count. if (OPTIONS['count_filtered_lines'].lower() == 'off') and filter_status == 1: filtered, filtered_before, filtered_after = count_filtered_lines( ptr_buffer, lines_count, lines_after) lines_count = lines_count - filtered # lines_after = lines_after - filtered_after if lines_count > window_height: differential = lines_count - window_height percent = max( int(round(100. * (differential - lines_after) / differential)), 0) else: percent = 100 # get current position current_line = lines_count - lines_after return lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after
def update_item(data, item, window): if not data: return "" # window empty? root bar! if not window: window = weechat.current_window() value = weechat.config_get_plugin(data) if value: value = check_buffer_type(window, value) else: return "" if not value: return "" # substitute colors in output return re.sub(regex_color, lambda match: weechat.color(match.group(1)), value)
def count_lines(winpointer, bufpointer): hdata_buf = weechat.hdata_get("buffer") hdata_lines = weechat.hdata_get("lines") lines = weechat.hdata_pointer(hdata_buf, bufpointer, "lines") # own_lines, mixed_lines lines_count = weechat.hdata_integer(hdata_lines, lines, "lines_count") hdata_window = weechat.hdata_get("window") hdata_winscroll = weechat.hdata_get("window_scroll") window_scroll = weechat.hdata_pointer(hdata_window, winpointer, "scroll") lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, "lines_after") window_height = weechat.window_get_integer(weechat.current_window(), "win_chat_height") if lines_count > window_height: differential = lines_count - window_height percent = max(int(round(100.0 * (differential - lines_after) / differential)), 0) else: percent = 100 # weechat.prnt('', " : lines_count "+str(lines_count)+" window_height "+str(window_height)+" lines after "+str(lines_after)) current_line = lines_count - lines_after return lines_after, lines_count, percent, current_line
def timer_cb(data, remaining_calls): global indent current_time = int(time.time()) interval = int(weechat.config_get_plugin('modulo_interval')) * 60 if (current_time % interval) == 0: infolist = weechat.infolist_get("buffer", "", "") if infolist: # set static width, assumes balanced window widths if indent < 0: if weechat.config_get_plugin('center') == '0': indent = 0 else: # centering = (window width - prefix width - (vertical separator + date)) / 2 - rounding adjustment indent = (weechat.window_get_integer( weechat.current_window(), "win_width") - int( weechat.string_eval_expression( "${weechat.look.prefix_align_min}", {}, {}, {})) - 14) / 2 - 1 while weechat.infolist_next(infolist): buffer = weechat.infolist_pointer(infolist, 'pointer') prnt_timestamp(buffer, current_time, indent) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def buffer_switch_cb(signal, callback, callback_data): if callback_data == '': return weechat.WEECHAT_RC_OK argv = callback_data.strip().split(' ',)[1:] if len(argv) == 0 or len(argv) > 1: return weechat.WEECHAT_RC_OK # check out if string is a number str_buffer_number = get_buffer_number_as_string(argv[0]) if not str_buffer_number: return weechat.WEECHAT_RC_OK curren_buffer_number = get_current_buffer_number() if not curren_buffer_number: return weechat.WEECHAT_RC_OK if argv[0][0] == '-': switch_to_buffer = curren_buffer_number - int(argv[0][1:]) # [1:] don't use first sign if switch_to_buffer < 1: switch_to_buffer = 1 elif argv[0][0] == '+': switch_to_buffer = curren_buffer_number + int(argv[0][1:]) # [1:] don't use first sign else: switch_to_buffer = int(str_buffer_number[0]) buffer_name, ptr_buffer = infolist_get_buffer_name_and_ptr(switch_to_buffer) if not buffer_name or not ptr_buffer: return weechat.WEECHAT_RC_OK if ptr_buffer == weechat.window_get_pointer(weechat.current_window(),'buffer'): return weechat.WEECHAT_RC_OK window_number = weechat.buffer_get_string(ptr_buffer,'localvar_stick_buffer_to_window') if window_number: weechat.command('','/window %s' % window_number) return weechat.WEECHAT_RC_OK
def server_switch(signal_data,servername_from_current_buffer,name): global look_server SERVER = {} bufpointer = weechat.window_get_pointer(weechat.current_window(),"buffer") servername_current_buffer = servername_from_current_buffer if look_server == "merge_with_core": # merge_with_core SERVER["weechat"] = "core.weechat" # get ALL server buffers and save them infolist = weechat.infolist_get("buffer","","*server.*") # we are only interest in server-buffers while weechat.infolist_next(infolist): bufpointer = weechat.infolist_pointer(infolist,"pointer") server = weechat.infolist_string(infolist, "name") # full servername (server.<servername>) servername = weechat.infolist_string(infolist, "short_name") # get servername from server (without prefix "server") active = weechat.infolist_integer(infolist,"active") SERVER[servername] = server if (active == 1) and (servername_current_buffer != servername): # buffer active but not correct server buffer? weechat.command(bufpointer,"/input switch_active_buffer") # switch server buffer weechat.infolist_free(infolist) # do not forget to free infolist! # switch though all server and stop at server from current buffer i = 0 while i <= len(SERVER): for servername,full_name in SERVER.items(): bufpointer = weechat.buffer_search("irc","%s" % full_name) # search pointer from server buffer if bufpointer == "": # core buffer if weechat.buffer_get_integer(weechat.buffer_search_main(),'active') == 1: weechat.command(weechat.buffer_search_main(),"/input switch_active_buffer") else: # server buffer! if (servername != servername_current_buffer) and (weechat.buffer_get_integer(bufpointer,'active') == 1): weechat.command(bufpointer,"/input switch_active_buffer") elif (servername == servername_current_buffer) and (weechat.buffer_get_integer(bufpointer,'active') == 1): i = len(SERVER) break i += 1
def get_current_buffer_number(): ptr_buffer = weechat.window_get_pointer(weechat.current_window(), 'buffer') return weechat.buffer_get_integer(ptr_buffer, 'number')
def show_spell_correction_item_cb(data, item, window): # check for root input bar! if not window: window = weechat.current_window() # weechat.buffer_get_string(buffer,'localvar_spell_correction_suggest_item'): buffer = weechat.window_get_pointer(window, "buffer") if buffer == "": return "" tab_complete, position, aspell_suggest_item = get_position_and_suggest_item(buffer) if not position or not aspell_suggest_item: return "" # config_spell_suggest_item = weechat.config_get_plugin('suggest_item') # if config_spell_suggest_item: # show_item = config_spell_suggest_item.replace('%S',aspell_suggest_item) # show_item = substitute_colors(show_item) # return '%s' % (show_item) # else: # return aspell_suggest_item # get spell dict localvar_aspell_suggest = get_localvar_aspell_suggest(buffer) dicts_found = localvar_aspell_suggest.count("/") config_spell_suggest_item = weechat.config_get_plugin("suggest_item") if dicts_found: # aspell.dict.full_name = en_GB,de_DE-neu # localvar_dict = en_GB,de_DE-neu dictionary = get_aspell_dict_for(buffer) if not dictionary: return aspell_suggest_item dictionary_list = dictionary.split(",") # more then one dict? if len(dictionary_list) > 1: undef, aspell_suggestions = localvar_aspell_suggest.split(":") dictionary = aspell_suggestions.split("/") words = 0 i = -1 for a in dictionary: i += 1 words += a.count(",") + 1 if words > int(position): break if config_spell_suggest_item: show_item = config_spell_suggest_item.replace("%S", aspell_suggest_item) show_item = show_item.replace("%D", dictionary_list[i]) show_item = substitute_colors(show_item) return "%s" % (show_item) else: return aspell_suggest_item else: if config_spell_suggest_item: show_item = config_spell_suggest_item.replace("%S", aspell_suggest_item) if weechat.config_get_plugin("hide_single_dict").lower() == "off": show_item = show_item.replace("%D", get_aspell_dict_for(buffer)) else: show_item = show_item.replace("%D", "").rstrip() show_item = substitute_colors(show_item) return "%s" % (show_item) return aspell_suggest_item
def tc_bar_item (data, item, window): '''Item constructor''' # window empty? root bar! if not window: window = w.current_window() global length, cursor_pos, tc_input_text, count_over,tc_options count_over = '0' sms = '' tweet = '' reverse_chars = 0 ptr_buffer = w.window_get_pointer(window,"buffer") if ptr_buffer == "": return "" length = w.buffer_get_integer(ptr_buffer,'input_length') start_pos = int(tc_options['start_cursor_pos_at_zero'].lower() == 'off') cursor_pos = w.buffer_get_integer(ptr_buffer,'input_pos') + start_pos plugin = w.buffer_get_string(ptr_buffer, 'plugin') host = '' if plugin == 'irc': servername = w.buffer_get_string(ptr_buffer, 'localvar_server') channelname = w.buffer_get_string(ptr_buffer, 'localvar_channel') channel_type = w.buffer_get_string(ptr_buffer, 'localvar_type') name = w.buffer_get_string(ptr_buffer, 'localvar_name') input_line = w.buffer_get_string(ptr_buffer, 'input') mynick = w.info_get('irc_nick', servername) nick_ptr = w.nicklist_search_nick(ptr_buffer, '', mynick) # check for a sms message if channel_type == 'private' and name in tc_options['sms_buffer'].split(","): # 160 chars for a sms # 'sms:name:text' get_sms_text = re.match(r'(s|sms):(.*?:)(.*)', input_line) if get_sms_text: # if get_sms_text.group(2): sms_len = len(get_sms_text.group(3)) # input_length = len(input_line) # sms_prefix = input_length - sms_len sms = 160-sms_len reverse_chars = sms else: get_sms_text = re.match(r'(r|reply):(.*)', input_line) if get_sms_text: sms_len = len(get_sms_text.group(2)) sms = 160-sms_len reverse_chars = sms # check for a tweet buffer elif name in tc_options['tweet_buffer'].split(","): # 140 chars for a tweet! prefix "post " = 5 chars # check out if length >= 5 and matches "post " if length >= 5 and re.match(r'post (.*)', input_line): tweet = 145 - length reverse_chars = tweet # get host and length from host elif servername != channelname: infolist = w.infolist_get('irc_nick', '', '%s,%s,%s' % (servername,channelname,mynick)) # w.prnt("","%s.%s.%s.%s" % (servername,channelname,mynick,nick_ptr)) while w.infolist_next(infolist): host = w.infolist_string(infolist, 'host') w.infolist_free(infolist) if host != '': host = ':%s!%s PRIVMSG %s :' % (mynick,host,channelname) host_length = len(host) # w.prnt("","%d" % host_length) reverse_chars = (475 - int(host_length) - length -1) # -1 = return else: reverse_chars = (int(tc_options['max_chars']) - length) else: reverse_chars = (int(tc_options['max_chars']) - length) else: # reverse check for max_chars reverse_chars = (int(tc_options['max_chars']) - length) if reverse_chars == 0: reverse_chars = "%s" % ("0") else: if reverse_chars < 0: count_over = "%s%s%s" % (w.color(tc_options['warn_colour']),str(reverse_chars*-1), w.color('default')) reverse_chars = "%s" % ("0") tc_action_cb() else: reverse_chars = str(reverse_chars) out_format = tc_options['format'] if tc_options['warn']: if length >= int(tc_options['warn']): length_warn = "%s%s%s" % (w.color(tc_options['warn_colour']), str(length), w.color('default')) out_format = out_format.replace('%L', length_warn) else: out_format = out_format.replace('%L', str(length)) else: out_format = out_format.replace('%L', str(length)) out_format = out_format.replace('%P', str(cursor_pos)) if sms: out_format = out_format.replace('%R', "s:" + reverse_chars) elif tweet: out_format = out_format.replace('%R', "t:" + reverse_chars) else: out_format = out_format.replace('%R', reverse_chars) out_format = out_format.replace('%C', count_over) # out_format = out_format.replace('%T', str(tweet)) # out_format = out_format.replace('%S', str(sms)) tc_input_text = out_format return substitute_colors(tc_input_text)