degesch: fix fancy-prompt.lua with libedit
Partly by unifying the interface for prompt hooks to match GNU Readline.
This commit is contained in:
		
							
								
								
									
										14
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								degesch.c
									
									
									
									
									
								
							@@ -6028,6 +6028,14 @@ make_prompt (struct app_context *ctx, struct str *output)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
input_maybe_set_prompt (struct input *self, char *new_prompt)
 | 
					input_maybe_set_prompt (struct input *self, char *new_prompt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						// Fix libedit's expectations to see a non-control character following
 | 
				
			||||||
 | 
						// the end mark (see prompt.c and literal.c) by cleaning this up
 | 
				
			||||||
 | 
						for (char *p = new_prompt; *p; )
 | 
				
			||||||
 | 
							if (p[0] == INPUT_END_IGNORE && p[1] == INPUT_START_IGNORE)
 | 
				
			||||||
 | 
								memmove (p, p + 2, strlen (p + 2) + 1);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								p++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Redisplay can be an expensive operation
 | 
						// Redisplay can be an expensive operation
 | 
				
			||||||
	const char *prompt = CALL (self, get_prompt);
 | 
						const char *prompt = CALL (self, get_prompt);
 | 
				
			||||||
	if (prompt && !strcmp (new_prompt, prompt))
 | 
						if (prompt && !strcmp (new_prompt, prompt))
 | 
				
			||||||
@@ -6055,6 +6063,12 @@ on_refresh_prompt (struct app_context *ctx)
 | 
				
			|||||||
		prompt.str[--prompt.len] = 0;
 | 
							prompt.str[--prompt.len] = 0;
 | 
				
			||||||
		attributed_suffix = " ";
 | 
							attributed_suffix = " ";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Also enable a uniform interface for prompt hooks by assuming it uses
 | 
				
			||||||
 | 
						// GNU Readline escapes: turn this into libedit's almost-flip-flop
 | 
				
			||||||
 | 
						for (size_t i = 0; i < prompt.len; i++)
 | 
				
			||||||
 | 
							if (prompt.str[i] == '\x01' || prompt.str[i] == '\x02')
 | 
				
			||||||
 | 
								prompt.str[i] = INPUT_START_IGNORE /* == INPUT_END_IGNORE */;
 | 
				
			||||||
#endif // HAVE_EDITLINE
 | 
					#endif // HAVE_EDITLINE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL);
 | 
						char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user