def test_strings(): """Test string functions.""" check(weechat.charset_set('iso-8859-15') == 1) check(weechat.charset_set('') == 1) check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc') check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd') check(weechat.gettext('abcdef') == 'abcdef') check(weechat.ngettext('file', 'files', 1) == 'file') check(weechat.ngettext('file', 'files', 2) == 'files') check(weechat.strlen_screen('abcd') == 4) check(weechat.string_match('abcdef', 'abc*', 0) == 1) check(weechat.string_match('abcdef', 'abc*', 1) == 1) check(weechat.string_match('ABCDEF', 'abc*', 1) == 0) check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0) check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1) check(weechat.string_match_list('def', '*,!abc*', 0) == 1) check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123') check(weechat.string_mask_to_regex('test*mask') == 'test.*mask') check(weechat.string_has_highlight('my test string', 'test,word2') == 1) check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1) check(weechat.string_format_size(0) == '0 bytes') check(weechat.string_format_size(1) == '1 byte') check(weechat.string_format_size(2097152) == '2.10 MB') check(weechat.string_format_size(420000000) == '420.00 MB') check(weechat.string_remove_color('test', '?') == 'test') check(weechat.string_is_command_char('/test') == 1) check(weechat.string_is_command_char('test') == 0) check(weechat.string_input_for_buffer('test') == 'test') check(weechat.string_input_for_buffer('/test') == '') check(weechat.string_input_for_buffer('//test') == '/test') check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
def test_strings(): """Test string functions.""" check(weechat.charset_set('iso-8859-15') == 1) check(weechat.charset_set('') == 1) check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc') check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd') check(weechat.gettext('abcdef') == 'abcdef') check(weechat.ngettext('file', 'files', 1) == 'file') check(weechat.ngettext('file', 'files', 2) == 'files') check(weechat.strlen_screen('abcd') == 4) check(weechat.string_match('abcdef', 'abc*', 0) == 1) check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123') check(weechat.string_mask_to_regex('test*mask') == 'test.*mask') check(weechat.string_has_highlight('my test string', 'test,word2') == 1) check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1) check(weechat.string_remove_color('test', '?') == 'test') check(weechat.string_is_command_char('/test') == 1) check(weechat.string_is_command_char('test') == 0) check(weechat.string_input_for_buffer('test') == 'test') check(weechat.string_input_for_buffer('/test') == '') check(weechat.string_input_for_buffer('//test') == '/test') check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
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 plugin = weechat.buffer_get_pointer(weechat.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' color_delimiters = cmdhelp_settings['color_delimiters'] return '%s %s%s%s%s%s' % ( string, weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def ap_input_return_cb(data, buf, command): """Callback called when Return key is pressed in a buffer.""" try: max_rejects = int(ap_settings['max_rejects']) except ValueError: max_rejects = 3 input_text = weechat.buffer_get_string(buf, 'input') if not weechat.string_input_for_buffer(input_text): # commands are ignored ap_reject['input'] = '' ap_reject['count'] = 0 return weechat.WEECHAT_RC_OK if ap_input_is_password(input_text): if ap_reject['input'] == input_text: if ap_reject['count'] >= max_rejects > 0: # it looks like a password but send anyway after N rejects ap_reject['input'] = '' ap_reject['count'] = 0 return weechat.WEECHAT_RC_OK ap_reject['count'] += 1 else: ap_reject['input'] = input_text ap_reject['count'] = 1 # password detected, do NOT send it to the buffer! return weechat.WEECHAT_RC_OK_EAT # not a password ap_reject['input'] = '' ap_reject['count'] = 0 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 shell_input_buffer(data, buffer, input): """Input callback on shell buffer.""" global cmd_send_to_buffer if input in ('q', 'Q'): weechat.buffer_close(buffer) return weechat.WEECHAT_RC_OK cmd_send_to_buffer = 'new' weechat.prnt(buffer, '') command = weechat.string_input_for_buffer(input) shell_exec(buffer, command) 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 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 plugin = weechat.buffer_get_pointer(weechat.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' color_delimiters = cmdhelp_settings['color_delimiters'] return '%s %s%s%s%s%s' % (string, weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])