xC: split Command.BUFFER_INPUT on newlines
This commit is contained in:
		
							parent
							
								
									36529a46fd
								
							
						
					
					
						commit
						e7d0f2380e
					
				
							
								
								
									
										43
									
								
								xC.c
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								xC.c
									
									
									
									
									
								
							| @ -8180,7 +8180,7 @@ irc_try_parse_welcome_for_userhost (struct server *s, const char *m) | |||||||
| 	strv_free (&v); | 	strv_free (&v); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static bool process_input_utf8 | static bool process_input_line | ||||||
| 	(struct app_context *, struct buffer *, const char *, int); | 	(struct app_context *, struct buffer *, const char *, int); | ||||||
| static void on_autoaway_timer (struct app_context *ctx); | static void on_autoaway_timer (struct app_context *ctx); | ||||||
| 
 | 
 | ||||||
| @ -8209,7 +8209,7 @@ irc_on_registered (struct server *s, const char *nickname) | |||||||
| 	if (command) | 	if (command) | ||||||
| 	{ | 	{ | ||||||
| 		log_server_debug (s, "Executing \"#s\"", command); | 		log_server_debug (s, "Executing \"#s\"", command); | ||||||
| 		(void) process_input_utf8 (s->ctx, s->buffer, command, 0); | 		(void) process_input_line (s->ctx, s->buffer, command, 0); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	int64_t command_delay = get_config_integer (s->config, "command_delay"); | 	int64_t command_delay = get_config_integer (s->config, "command_delay"); | ||||||
| @ -9840,7 +9840,7 @@ lua_buffer_execute (lua_State *L) | |||||||
| 	struct lua_weak *wrapper = lua_weak_deref (L, &lua_buffer_info); | 	struct lua_weak *wrapper = lua_weak_deref (L, &lua_buffer_info); | ||||||
| 	struct buffer *buffer = wrapper->object; | 	struct buffer *buffer = wrapper->object; | ||||||
| 	const char *line = lua_plugin_check_utf8 (L, 2); | 	const char *line = lua_plugin_check_utf8 (L, 2); | ||||||
| 	(void) process_input_utf8 (wrapper->plugin->ctx, buffer, line, 0); | 	(void) process_input_line (wrapper->plugin->ctx, buffer, line, 0); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -13270,13 +13270,13 @@ process_alias (struct app_context *ctx, struct buffer *buffer, | |||||||
| 		log_global_debug (ctx, "Alias expanded to: ###d: \"#s\"", | 		log_global_debug (ctx, "Alias expanded to: ###d: \"#s\"", | ||||||
| 			(int) i, commands->vector[i]); | 			(int) i, commands->vector[i]); | ||||||
| 	for (size_t i = 0; i < commands->len; i++) | 	for (size_t i = 0; i < commands->len; i++) | ||||||
| 		if (!process_input_utf8 (ctx, buffer, commands->vector[i], ++level)) | 		if (!process_input_line (ctx, buffer, commands->vector[i], ++level)) | ||||||
| 			return false; | 			return false; | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static bool | static bool | ||||||
| process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer, | process_input_line_posthook (struct app_context *ctx, struct buffer *buffer, | ||||||
| 	char *input, int alias_level) | 	char *input, int alias_level) | ||||||
| { | { | ||||||
| 	if (*input != '/' || *++input == '/') | 	if (*input != '/' || *++input == '/') | ||||||
| @ -13325,36 +13325,28 @@ process_input_hooks (struct app_context *ctx, struct buffer *buffer, | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static bool | static bool | ||||||
| process_input_utf8 (struct app_context *ctx, struct buffer *buffer, | process_input_line (struct app_context *ctx, struct buffer *buffer, | ||||||
| 	const char *input, int alias_level) | 	const char *input, int alias_level) | ||||||
| { | { | ||||||
| 	// Note that this also gets called on expanded aliases,
 | 	// Note that this also gets called on expanded aliases,
 | ||||||
| 	// which might or might not be desirable (we can forward "alias_level")
 | 	// which might or might not be desirable (we can forward "alias_level")
 | ||||||
| 	char *processed = process_input_hooks (ctx, buffer, xstrdup (input)); | 	char *processed = process_input_hooks (ctx, buffer, xstrdup (input)); | ||||||
| 	bool result = !processed | 	bool result = !processed | ||||||
| 		|| process_input_utf8_posthook (ctx, buffer, processed, alias_level); | 		|| process_input_line_posthook (ctx, buffer, processed, alias_level); | ||||||
| 	free (processed); | 	free (processed); | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
| process_input (struct app_context *ctx, char *user_input) | process_input (struct app_context *ctx, struct buffer *buffer, | ||||||
| { | 	const char *input) | ||||||
| 	char *input; |  | ||||||
| 	if (!(input = iconv_xstrdup (ctx->term_to_utf8, user_input, -1, NULL))) |  | ||||||
| 		print_error ("character conversion failed for: %s", "user input"); |  | ||||||
| 	else |  | ||||||
| { | { | ||||||
| 	struct strv lines = strv_make (); | 	struct strv lines = strv_make (); | ||||||
| 	cstr_split (input, "\r\n", false, &lines); | 	cstr_split (input, "\r\n", false, &lines); | ||||||
| 	for (size_t i = 0; i < lines.len; i++) | 	for (size_t i = 0; i < lines.len; i++) | ||||||
| 			(void) process_input_utf8 (ctx, | 		(void) process_input_line (ctx, buffer, lines.vector[i], 0); | ||||||
| 				ctx->current_buffer, lines.vector[i], 0); |  | ||||||
| 
 |  | ||||||
| 	strv_free (&lines); | 	strv_free (&lines); | ||||||
| } | } | ||||||
| 	free (input); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| // --- Word completion ---------------------------------------------------------
 | // --- Word completion ---------------------------------------------------------
 | ||||||
| 
 | 
 | ||||||
| @ -14589,7 +14581,7 @@ on_editline_return (EditLine *editline, int key) | |||||||
| 	} | 	} | ||||||
| 	free (line); | 	free (line); | ||||||
| 
 | 
 | ||||||
| 	// process_input() expects a multibyte string
 | 	// on_pending_input() expects a multibyte string
 | ||||||
| 	const LineInfo *info_mb = el_line (editline); | 	const LineInfo *info_mb = el_line (editline); | ||||||
| 	strv_append_owned (&ctx->pending_input, | 	strv_append_owned (&ctx->pending_input, | ||||||
| 		xstrndup (info_mb->buffer, info_mb->lastchar - info_mb->buffer)); | 		xstrndup (info_mb->buffer, info_mb->lastchar - info_mb->buffer)); | ||||||
| @ -15179,7 +15171,15 @@ on_pending_input (struct app_context *ctx) | |||||||
| { | { | ||||||
| 	poller_idle_reset (&ctx->input_event); | 	poller_idle_reset (&ctx->input_event); | ||||||
| 	for (size_t i = 0; i < ctx->pending_input.len; i++) | 	for (size_t i = 0; i < ctx->pending_input.len; i++) | ||||||
| 		process_input (ctx, ctx->pending_input.vector[i]); | 	{ | ||||||
|  | 		char *input = iconv_xstrdup | ||||||
|  | 			(ctx->term_to_utf8, ctx->pending_input.vector[i], -1, NULL); | ||||||
|  | 		if (input) | ||||||
|  | 			process_input (ctx, ctx->current_buffer, input); | ||||||
|  | 		else | ||||||
|  | 			print_error ("character conversion failed for: %s", "user input"); | ||||||
|  | 		free (input); | ||||||
|  | 	} | ||||||
| 	strv_reset (&ctx->pending_input); | 	strv_reset (&ctx->pending_input); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -15383,8 +15383,7 @@ client_process_message (struct client *c, | |||||||
| 			&m->data.buffer_complete); | 			&m->data.buffer_complete); | ||||||
| 		break; | 		break; | ||||||
| 	case RELAY_COMMAND_BUFFER_INPUT: | 	case RELAY_COMMAND_BUFFER_INPUT: | ||||||
| 		(void) process_input_utf8 (c->ctx, | 		process_input (c->ctx, buffer, m->data.buffer_input.text.str); | ||||||
| 			buffer, m->data.buffer_input.text.str, 0); |  | ||||||
| 		break; | 		break; | ||||||
| 	case RELAY_COMMAND_BUFFER_ACTIVATE: | 	case RELAY_COMMAND_BUFFER_ACTIVATE: | ||||||
| 		buffer_activate (c->ctx, buffer); | 		buffer_activate (c->ctx, buffer); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user